Commit b406213c authored by Alexandre Julliard's avatar Alexandre Julliard

iphlpapi: Moved AllocateAndGetIpNetTableFromStack implementation to ipstats.c.

parent bc08fb99
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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_ */
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