iphlpapi: Moved AllocateAndGetIpForwardTableFromStack implementation to ipstats.c.

This commit is contained in:
Alexandre Julliard 2009-03-02 12:52:45 +01:00
parent b406213c42
commit 44f30a645e
3 changed files with 43 additions and 70 deletions

View File

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

View File

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

View File

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