Module: wine Branch: master Commit: bc08fb99d3a6ef662556e6eda5788016d7045ad4 URL: http://source.winehq.org/git/wine.git/?a=commit;h=bc08fb99d3a6ef662556e6eda5...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Mar 2 12:51:02 2009 +0100
iphlpapi: Moved AllocateAndGetTcpTableFromStack implementation to ipstats.c.
---
dlls/iphlpapi/iphlpapi_main.c | 66 +---------------------------------------- dlls/iphlpapi/ipstats.c | 44 ++++++++++++++++++++++++++- dlls/iphlpapi/ipstats.h | 6 +--- 3 files changed, 44 insertions(+), 72 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 735091b..1d2735f 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -291,67 +291,6 @@ DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable, }
-static int TcpTableSorter(const void *a, const void *b) -{ - int ret; - - if (a && b) { - const MIB_TCPROW* rowA = a; - const MIB_TCPROW* rowB = b; - - ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr); - if (ret == 0) { - ret = ntohs ((unsigned short)rowA->dwLocalPort) - - ntohs ((unsigned short)rowB->dwLocalPort); - if (ret == 0) { - ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr); - if (ret == 0) - ret = ntohs ((unsigned short)rowA->dwRemotePort) - - ntohs ((unsigned short)rowB->dwRemotePort); - } - } - } - else - ret = 0; - return ret; -} - - -/****************************************************************** - * AllocateAndGetTcpTableFromStack (IPHLPAPI.@) - * - * Get the TCP connection table. - * Like GetTcpTable(), but allocate the returned table from heap. - * - * PARAMS - * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is - * allocated and returned. - * bOrder [In] whether to sort the table - * heap [In] heap from which the table is allocated - * flags [In] flags to HeapAlloc - * - * RETURNS - * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable() - * returns otherwise. - */ -DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable, - BOOL bOrder, HANDLE heap, DWORD flags) -{ - DWORD ret; - - TRACE("ppTcpTable %p, bOrder %d, heap %p, flags 0x%08x\n", - ppTcpTable, bOrder, heap, flags); - - *ppTcpTable = NULL; - ret = getTcpTable(ppTcpTable, heap, flags); - if (!ret && bOrder) - qsort((*ppTcpTable)->table, (*ppTcpTable)->dwNumEntries, - sizeof(MIB_TCPROW), TcpTableSorter); - TRACE("returning %d\n", ret); - return ret; -} - - /****************************************************************** * CreateIpForwardEntry (IPHLPAPI.@) * @@ -1525,7 +1464,7 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
if (!pdwSize) return ERROR_INVALID_PARAMETER;
- ret = getTcpTable(&table, GetProcessHeap(), 0); + ret = AllocateAndGetTcpTableFromStack(&table, bOrder, GetProcessHeap(), 0); if (!ret) { DWORD size = FIELD_OFFSET( MIB_TCPTABLE, table[table->dwNumEntries] ); if (!pTcpTable || *pdwSize < size) { @@ -1535,9 +1474,6 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder) else { *pdwSize = size; memcpy(pTcpTable, table, size); - if (bOrder) - qsort(pTcpTable->table, pTcpTable->dwNumEntries, - sizeof(MIB_TCPROW), TcpTableSorter); } HeapFree(GetProcessHeap(), 0, table); } diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c index 2277b80..1a3086f 100644 --- a/dlls/iphlpapi/ipstats.c +++ b/dlls/iphlpapi/ipstats.c @@ -1591,12 +1591,46 @@ static DWORD TCPStateToMIBState (int state) }
-DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, HANDLE heap, DWORD flags) +static int compare_tcp_rows(const void *a, const void *b) +{ + const MIB_TCPROW *rowA = a; + const MIB_TCPROW *rowB = b; + int ret; + + if ((ret = ntohl (rowA->dwLocalAddr) - ntohl (rowB->dwLocalAddr)) != 0) return ret; + if ((ret = ntohs ((unsigned short)rowA->dwLocalPort) - + ntohs ((unsigned short)rowB->dwLocalPort)) != 0) return ret; + if ((ret = ntohl (rowA->dwRemoteAddr) - ntohl (rowB->dwRemoteAddr)) != 0) return ret; + return ntohs ((unsigned short)rowA->dwRemotePort) - ntohs ((unsigned short)rowB->dwRemotePort); +} + + +/****************************************************************** + * AllocateAndGetTcpTableFromStack (IPHLPAPI.@) + * + * Get the TCP connection table. + * Like GetTcpTable(), but allocate the returned table from heap. + * + * PARAMS + * ppTcpTable [Out] pointer into which the MIB_TCPTABLE is + * allocated and returned. + * bOrder [In] whether to sort the table + * heap [In] heap from which the table is allocated + * flags [In] flags to HeapAlloc + * + * RETURNS + * ERROR_INVALID_PARAMETER if ppTcpTable is NULL, whatever GetTcpTable() + * returns otherwise. + */ +DWORD WINAPI AllocateAndGetTcpTableFromStack( PMIB_TCPTABLE *ppTcpTable, BOOL bOrder, + HANDLE heap, DWORD flags) { MIB_TCPTABLE *table; MIB_TCPROW row; DWORD ret = NO_ERROR, count = 16;
+ TRACE("table %p, bOrder %d, heap %p, flags 0x%08x\n", ppTcpTable, bOrder, heap, flags); + if (!ppTcpTable) return ERROR_INVALID_PARAMETER;
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_TCPTABLE, table[count] )))) @@ -1713,7 +1747,13 @@ DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, HANDLE heap, DWORD flags) #endif
if (!table) return ERROR_OUTOFMEMORY; - if (!ret) *ppTcpTable = table; + if (!ret) + { + if (bOrder && table->dwNumEntries) + qsort( table->table, table->dwNumEntries, sizeof(row), compare_tcp_rows ); + *ppTcpTable = table; + } else HeapFree( heap, flags, table ); + TRACE( "returning ret %u table %p\n", ret, table ); return ret; } diff --git a/dlls/iphlpapi/ipstats.h b/dlls/iphlpapi/ipstats.h index 431b414..bc2fe7b 100644 --- a/dlls/iphlpapi/ipstats.h +++ b/dlls/iphlpapi/ipstats.h @@ -75,11 +75,7 @@ DWORD getNumUdpEntries(void); /* Returns the number of entries in the TCP state table. */ 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, HANDLE heap, DWORD flags); - DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags); +DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags);
#endif /* ndef WINE_IPSTATS_H_ */