iphlpapi: Moved AllocateAndGetIpNetTableFromStack implementation to ipstats.c.

This commit is contained in:
Alexandre Julliard 2009-03-02 12:51:48 +01:00
parent bc08fb99d3
commit b406213c42
3 changed files with 39 additions and 56 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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_ */