Alexandre Julliard : iphlpapi: Moved AllocateAndGetUdpTableFromStack implementation to ipstats.c.
Alexandre Julliard
julliard at winehq.org
Mon Mar 2 09:01:54 CST 2009
Module: wine
Branch: master
Commit: 95827a8237fea9ef3fa0558a99009ff5c9c7cd9d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=95827a8237fea9ef3fa0558a99009ff5c9c7cd9d
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Mar 2 12:50:30 2009 +0100
iphlpapi: Moved AllocateAndGetUdpTableFromStack implementation to ipstats.c.
---
dlls/iphlpapi/iphlpapi_main.c | 56 +----------------------------------------
dlls/iphlpapi/ipstats.c | 41 ++++++++++++++++++++++++++++-
dlls/iphlpapi/ipstats.h | 7 +---
3 files changed, 42 insertions(+), 62 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 0c5f209..735091b 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -352,57 +352,6 @@ DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
}
-static int UdpTableSorter(const void *a, const void *b)
-{
- int ret;
-
- if (a && b) {
- const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
- const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
-
- ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
- if (ret == 0)
- ret = rowA->dwLocalPort - rowB->dwLocalPort;
- }
- else
- ret = 0;
- return ret;
-}
-
-
-/******************************************************************
- * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
- *
- * Get the UDP listener table.
- * Like GetUdpTable(), but allocate the returned table from heap.
- *
- * PARAMS
- * ppUdpTable [Out] pointer into which the MIB_UDPTABLE 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 ppUdpTable is NULL, whatever GetUdpTable()
- * returns otherwise.
- */
-DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
- BOOL bOrder, HANDLE heap, DWORD flags)
-{
- DWORD ret;
-
- TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
- ppUdpTable, bOrder, heap, flags);
- ret = getUdpTable(ppUdpTable, heap, flags);
- if (!ret && bOrder)
- qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
- sizeof(MIB_UDPROW), UdpTableSorter);
- TRACE("returning %d\n", ret);
- return ret;
-}
-
-
/******************************************************************
* CreateIpForwardEntry (IPHLPAPI.@)
*
@@ -1650,7 +1599,7 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
if (!pdwSize) return ERROR_INVALID_PARAMETER;
- ret = getUdpTable(&table, GetProcessHeap(), 0);
+ ret = AllocateAndGetUdpTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
if (!ret) {
DWORD size = FIELD_OFFSET( MIB_UDPTABLE, table[table->dwNumEntries] );
if (!pUdpTable || *pdwSize < size) {
@@ -1660,9 +1609,6 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
else {
*pdwSize = size;
memcpy(pUdpTable, table, size);
- if (bOrder)
- qsort(pUdpTable->table, pUdpTable->dwNumEntries,
- sizeof(MIB_UDPROW), UdpTableSorter);
}
HeapFree(GetProcessHeap(), 0, table);
}
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 9cfaa21..2277b80 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -1454,12 +1454,43 @@ static MIB_UDPTABLE *append_udp_row( HANDLE heap, DWORD flags, MIB_UDPTABLE *tab
return table;
}
-DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
+static int compare_udp_rows(const void *a, const void *b)
+{
+ const MIB_UDPROW *rowA = a;
+ const MIB_UDPROW *rowB = b;
+ int ret;
+
+ if ((ret = rowA->dwLocalAddr - rowB->dwLocalAddr) != 0) return ret;
+ return rowA->dwLocalPort - rowB->dwLocalPort;
+}
+
+
+/******************************************************************
+ * AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
+ *
+ * Get the UDP listener table.
+ * Like GetUdpTable(), but allocate the returned table from heap.
+ *
+ * PARAMS
+ * ppUdpTable [Out] pointer into which the MIB_UDPTABLE 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 ppUdpTable is NULL, whatever GetUdpTable()
+ * returns otherwise.
+ */
+DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder,
+ HANDLE heap, DWORD flags)
{
MIB_UDPTABLE *table;
MIB_UDPROW row;
DWORD ret = NO_ERROR, count = 16;
+ TRACE("table %p, bOrder %d, heap %p, flags 0x%08x\n", ppUdpTable, bOrder, heap, flags);
+
if (!ppUdpTable) return ERROR_INVALID_PARAMETER;
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_UDPTABLE, table[count] ))))
@@ -1496,8 +1527,14 @@ DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
#endif
if (!table) return ERROR_OUTOFMEMORY;
- if (!ret) *ppUdpTable = table;
+ if (!ret)
+ {
+ if (bOrder && table->dwNumEntries)
+ qsort( table->table, table->dwNumEntries, sizeof(row), compare_udp_rows );
+ *ppUdpTable = 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 147276e..431b414 100644
--- a/dlls/iphlpapi/ipstats.h
+++ b/dlls/iphlpapi/ipstats.h
@@ -72,11 +72,6 @@ DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags);
/* Returns the number of entries in the UDP state table. */
DWORD getNumUdpEntries(void);
-/* Allocates the UDP state table from heap and returns it to you in *ppUdpTable.
- * Returns NO_ERROR on success, something else on failure.
- */
-DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags);
-
/* Returns the number of entries in the TCP state table. */
DWORD getNumTcpEntries(void);
@@ -85,4 +80,6 @@ DWORD getNumTcpEntries(void);
*/
DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, HANDLE heap, DWORD flags);
+DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags);
+
#endif /* ndef WINE_IPSTATS_H_ */
More information about the wine-cvs
mailing list