Alexandre Julliard : iphlpapi: Moved AllocateAndGetIpNetTableFromStack implementation to ipstats.c.

Alexandre Julliard julliard at winehq.org
Mon Mar 2 09:01:54 CST 2009


Module: wine
Branch: master
Commit: b406213c42793cc166b90ab2f7d4fc70445b0103
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b406213c42793cc166b90ab2f7d4fc70445b0103

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Mar  2 12:51:48 2009 +0100

iphlpapi: Moved AllocateAndGetIpNetTableFromStack implementation to ipstats.c.

---

 dlls/iphlpapi/iphlpapi_main.c |   50 +----------------------------------------
 dlls/iphlpapi/ipstats.c       |   39 ++++++++++++++++++++++++++++++-
 dlls/iphlpapi/ipstats.h       |    6 +----
 3 files changed, 39 insertions(+), 56 deletions(-)

diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 1d2735f..f0ca8ad 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -246,51 +246,6 @@ DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE *
 }
 
 
-static int IpNetTableSorter(const void *a, const void *b)
-{
-  int ret;
-
-  if (a && b)
-    ret = ((const MIB_IPNETROW*)a)->dwAddr - ((const MIB_IPNETROW*)b)->dwAddr;
-  else
-    ret = 0;
-  return ret;
-}
-
-
-/******************************************************************
- *    AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
- *
- * Get the IP-to-physical address mapping table.
- * Like GetIpNetTable(), but allocate the returned table from heap.
- *
- * PARAMS
- *  ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE 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 ppIpNetTable is NULL, other error codes
- *  on failure, NO_ERROR on success.
- */
-DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable,
- BOOL bOrder, HANDLE heap, DWORD flags)
-{
-  DWORD ret;
-
-  TRACE("ppIpNetTable %p, bOrder %d, heap %p, flags 0x%08x\n",
-   ppIpNetTable, bOrder, heap, flags);
-  ret = getArpTable(ppIpNetTable, heap, flags);
-  if (!ret && bOrder)
-    qsort((*ppIpNetTable)->table, (*ppIpNetTable)->dwNumEntries,
-     sizeof(MIB_IPADDRROW), IpNetTableSorter);
-  TRACE("returning %d\n", ret);
-  return ret;
-}
-
-
 /******************************************************************
  *    CreateIpForwardEntry (IPHLPAPI.@)
  *
@@ -1196,7 +1151,7 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
 
     if (!pdwSize) return ERROR_INVALID_PARAMETER;
 
-    ret = getArpTable(&table, GetProcessHeap(), 0);
+    ret = AllocateAndGetIpNetTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
     if (!ret) {
         DWORD size = FIELD_OFFSET( MIB_IPNETTABLE, table[table->dwNumEntries] );
         if (!pIpNetTable || *pdwSize < size) {
@@ -1206,9 +1161,6 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
         else {
           *pdwSize = size;
           memcpy(pIpNetTable, table, size);
-          if (bOrder)
-            qsort(pIpNetTable->table, pIpNetTable->dwNumEntries,
-             sizeof(MIB_IPNETROW), IpNetTableSorter);
         }
         HeapFree(GetProcessHeap(), 0, table);
     }
diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c
index 1a3086f..58ec76f 100644
--- a/dlls/iphlpapi/ipstats.c
+++ b/dlls/iphlpapi/ipstats.c
@@ -1296,12 +1296,41 @@ static MIB_IPNETTABLE *append_ipnet_row( HANDLE heap, DWORD flags, MIB_IPNETTABL
     return table;
 }
 
-DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags)
+static int compare_ipnet_rows(const void *a, const void *b)
+{
+    const MIB_IPNETROW *rowA = a;
+    const MIB_IPNETROW *rowB = b;
+
+    return ntohl(rowA->dwAddr) - ntohl(rowB->dwAddr);
+}
+
+
+/******************************************************************
+ *    AllocateAndGetIpNetTableFromStack (IPHLPAPI.@)
+ *
+ * Get the IP-to-physical address mapping table.
+ * Like GetIpNetTable(), but allocate the returned table from heap.
+ *
+ * PARAMS
+ *  ppIpNetTable [Out] pointer into which the MIB_IPNETTABLE 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 ppIpNetTable is NULL, other error codes
+ *  on failure, NO_ERROR on success.
+ */
+DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable, BOOL bOrder,
+                                               HANDLE heap, DWORD flags)
 {
     MIB_IPNETTABLE *table;
     MIB_IPNETROW row;
     DWORD ret = NO_ERROR, count = 16;
 
+    TRACE("table %p, bOrder %d, heap %p, flags 0x%08x\n", ppIpNetTable, bOrder, heap, flags);
+
     if (!ppIpNetTable) return ERROR_INVALID_PARAMETER;
 
     if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_IPNETTABLE, table[count] ))))
@@ -1420,8 +1449,14 @@ done:
 #endif
 
     if (!table) return ERROR_OUTOFMEMORY;
-    if (!ret) *ppIpNetTable = table;
+    if (!ret)
+    {
+        if (bOrder && table->dwNumEntries)
+            qsort( table->table, table->dwNumEntries, sizeof(row), compare_ipnet_rows );
+        *ppIpNetTable = 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 bc2fe7b..30b78b2 100644
--- a/dlls/iphlpapi/ipstats.h
+++ b/dlls/iphlpapi/ipstats.h
@@ -64,11 +64,6 @@ DWORD getRouteTable(PMIB_IPFORWARDTABLE *ppIpForwardTable, HANDLE heap,
 /* Returns the number of entries in the arp table. */
 DWORD getNumArpEntries(void);
 
-/* Allocates the arp table from heap and returns it to you in *ppIpNetTable.
- * Returns NO_ERROR on success, something else on failure.
- */
-DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags);
-
 /* Returns the number of entries in the UDP state table. */
 DWORD getNumUdpEntries(void);
 
@@ -77,5 +72,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);
 
 #endif /* ndef WINE_IPSTATS_H_ */




More information about the wine-cvs mailing list