Alexandre Julliard : iphlpapi: Moved AllocateAndGetIpForwardTableFromStack implementation to ipstats.c.
Alexandre Julliard
julliard at winehq.org
Mon Mar 2 09:01:54 CST 2009
Module: wine
Branch: master
Commit: 44f30a645e65db6385bc9b33d26de2c3264d8e84
URL: http://source.winehq.org/git/wine.git/?a=commit;h=44f30a645e65db6385bc9b33d26de2c3264d8e84
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Mar 2 12:52:45 2009 +0100
iphlpapi: Moved AllocateAndGetIpForwardTableFromStack implementation to ipstats.c.
---
dlls/iphlpapi/iphlpapi_main.c | 64 +---------------------------------------
dlls/iphlpapi/ipstats.c | 42 +++++++++++++++++++++++++-
dlls/iphlpapi/ipstats.h | 7 +----
3 files changed, 43 insertions(+), 70 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index f0ca8ad..3481f86 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -189,63 +189,6 @@ DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable,
}
-static int IpForwardTableSorter(const void *a, const void *b)
-{
- int ret;
-
- if (a && b) {
- const MIB_IPFORWARDROW* rowA = (const MIB_IPFORWARDROW*)a;
- const MIB_IPFORWARDROW* rowB = (const MIB_IPFORWARDROW*)b;
-
- ret = rowA->dwForwardDest - rowB->dwForwardDest;
- if (ret == 0) {
- ret = rowA->dwForwardProto - rowB->dwForwardProto;
- if (ret == 0) {
- ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy;
- if (ret == 0)
- ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop;
- }
- }
- }
- else
- ret = 0;
- return ret;
-}
-
-
-/******************************************************************
- * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
- *
- * Get the route table.
- * Like GetIpForwardTable(), but allocate the returned table from heap.
- *
- * PARAMS
- * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE 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 ppIfTable is NULL, other error codes
- * on failure, NO_ERROR on success.
- */
-DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
- ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags)
-{
- DWORD ret;
-
- TRACE("ppIpForwardTable %p, bOrder %d, heap %p, flags 0x%08x\n",
- ppIpForwardTable, bOrder, heap, flags);
- ret = getRouteTable(ppIpForwardTable, heap, flags);
- if (!ret && bOrder)
- qsort((*ppIpForwardTable)->table, (*ppIpForwardTable)->dwNumEntries,
- sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
- TRACE("returning %d\n", ret);
- return ret;
-}
-
-
/******************************************************************
* CreateIpForwardEntry (IPHLPAPI.@)
*
@@ -535,7 +478,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
if (!ret)
- ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
+ ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
if (!ret)
table = getNonLoopbackInterfaceIndexTable();
if (table) {
@@ -1101,7 +1044,7 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
if (!pdwSize) return ERROR_INVALID_PARAMETER;
- ret = getRouteTable(&table, GetProcessHeap(), 0);
+ ret = AllocateAndGetIpForwardTableFromStack(&table, bOrder, GetProcessHeap(), 0);
if (!ret) {
DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
if (!pIpForwardTable || *pdwSize < size) {
@@ -1111,9 +1054,6 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
else {
*pdwSize = size;
memcpy(pIpForwardTable, table, size);
- if (bOrder)
- qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
- sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
}
HeapFree(GetProcessHeap(), 0, table);
}
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 58ec76f..d01bf22 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -1065,12 +1065,44 @@ static MIB_IPFORWARDTABLE *append_ipforward_row( HANDLE heap, DWORD flags, MIB_I
return table;
}
-DWORD getRouteTable(PMIB_IPFORWARDTABLE *ppIpForwardTable, HANDLE heap, DWORD flags)
+static int compare_ipforward_rows(const void *a, const void *b)
+{
+ const MIB_IPFORWARDROW *rowA = a;
+ const MIB_IPFORWARDROW *rowB = b;
+ int ret;
+
+ if ((ret = rowA->dwForwardDest - rowB->dwForwardDest) != 0) return ret;
+ if ((ret = rowA->dwForwardProto - rowB->dwForwardProto) != 0) return ret;
+ if ((ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy) != 0) return ret;
+ return rowA->dwForwardNextHop - rowB->dwForwardNextHop;
+}
+
+/******************************************************************
+ * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@)
+ *
+ * Get the route table.
+ * Like GetIpForwardTable(), but allocate the returned table from heap.
+ *
+ * PARAMS
+ * ppIpForwardTable [Out] pointer into which the MIB_IPFORWARDTABLE 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 ppIfTable is NULL, other error codes
+ * on failure, NO_ERROR on success.
+ */
+DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForwardTable, BOOL bOrder,
+ HANDLE heap, DWORD flags)
{
MIB_IPFORWARDTABLE *table;
MIB_IPFORWARDROW row;
DWORD ret = NO_ERROR, count = 16;
+ TRACE("table %p, bOrder %d, heap %p, flags 0x%08x\n", ppIpForwardTable, bOrder, heap, flags);
+
if (!ppIpForwardTable) return ERROR_INVALID_PARAMETER;
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_IPFORWARDTABLE, table[count] ))))
@@ -1225,8 +1257,14 @@ done:
#endif
if (!table) return ERROR_OUTOFMEMORY;
- if (!ret) *ppIpForwardTable = table;
+ if (!ret)
+ {
+ if (bOrder && table->dwNumEntries)
+ qsort( table->table, table->dwNumEntries, sizeof(row), compare_ipforward_rows );
+ *ppIpForwardTable = 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 30b78b2..3e05d56 100644
--- a/dlls/iphlpapi/ipstats.h
+++ b/dlls/iphlpapi/ipstats.h
@@ -55,12 +55,6 @@ DWORD getUDPStats(MIB_UDPSTATS *stats);
/* Returns the number of entries in the route table. */
DWORD getNumRoutes(void);
-/* Allocates the route table from heap and returns it to you in
- * *ppIpForwardTable. Returns NO_ERROR on success, something else on failure.
- */
-DWORD getRouteTable(PMIB_IPFORWARDTABLE *ppIpForwardTable, HANDLE heap,
- DWORD flags);
-
/* Returns the number of entries in the arp table. */
DWORD getNumArpEntries(void);
@@ -73,5 +67,6 @@ DWORD getNumTcpEntries(void);
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags);
DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags);
DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable, BOOL bOrder, HANDLE heap, DWORD flags);
+DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags);
#endif /* ndef WINE_IPSTATS_H_ */
More information about the wine-cvs
mailing list