Commit 53d522bc authored by Alexandre Julliard's avatar Alexandre Julliard

iphlpapi: Reimplement GetTcpTable to avoid parsing the same information three times.

parent d069e498
......@@ -343,7 +343,7 @@ DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
ppTcpTable, bOrder, heap, flags);
*ppTcpTable = NULL;
ret = getTcpTable(ppTcpTable, 0, heap, flags);
ret = getTcpTable(ppTcpTable, heap, flags);
if (!ret && bOrder)
qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries,
sizeof(MIB_TCPROW), TcpTableSorter);
......@@ -1603,39 +1603,31 @@ DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats)
*/
DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
{
DWORD ret;
DWORD ret;
PMIB_TCPTABLE table;
TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
(DWORD)bOrder);
if (!pdwSize)
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numEntries = getNumTcpEntries();
DWORD size = sizeof(MIB_TCPTABLE);
TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize, bOrder);
if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_TCPROW);
if (!pTcpTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
}
else {
ret = getTcpTable(&pTcpTable, numEntries, 0, 0);
if (!ret) {
size = sizeof(MIB_TCPTABLE);
if (pTcpTable->dwNumEntries > 1)
size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
*pdwSize = size;
if (!pdwSize) return ERROR_INVALID_PARAMETER;
if (bOrder)
qsort(pTcpTable->table, pTcpTable->dwNumEntries,
sizeof(MIB_TCPROW), TcpTableSorter);
ret = NO_ERROR;
}
ret = getTcpTable(&table, GetProcessHeap(), 0);
if (!ret) {
DWORD size = FIELD_OFFSET( MIB_TCPTABLE, table[table->dwNumEntries] );
if (!pTcpTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
}
else {
*pdwSize = size;
memcpy(pTcpTable, table, size);
if (bOrder)
qsort(pTcpTable->table, pTcpTable->dwNumEntries,
sizeof(MIB_TCPROW), TcpTableSorter);
}
HeapFree(GetProcessHeap(), 0, table);
}
}
TRACE("returning %d\n", ret);
return ret;
TRACE("returning %d\n", ret);
return ret;
}
......
......@@ -83,7 +83,6 @@ DWORD getNumTcpEntries(void);
/* Allocates the TCP state table from heap and returns it to you in *ppTcpTable.
* Returns NO_ERROR on success, something else on failure.
*/
DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, DWORD maxEntries, HANDLE heap,
DWORD flags);
DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, HANDLE heap, DWORD flags);
#endif /* ndef WINE_IPSTATS_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment