iphlpapi: Moved AllocateAndGetIpForwardTableFromStack implementation to ipstats.c.
This commit is contained in:
parent
b406213c42
commit
44f30a645e
|
@ -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.@)
|
* CreateIpForwardEntry (IPHLPAPI.@)
|
||||||
*
|
*
|
||||||
|
@ -535,7 +478,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
|
||||||
|
|
||||||
ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
|
ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
|
ret = AllocateAndGetIpForwardTableFromStack(&routeTable, FALSE, GetProcessHeap(), 0);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
table = getNonLoopbackInterfaceIndexTable();
|
table = getNonLoopbackInterfaceIndexTable();
|
||||||
if (table) {
|
if (table) {
|
||||||
|
@ -1101,7 +1044,7 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
|
||||||
|
|
||||||
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
if (!pdwSize) return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
ret = getRouteTable(&table, GetProcessHeap(), 0);
|
ret = AllocateAndGetIpForwardTableFromStack(&table, bOrder, GetProcessHeap(), 0);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
|
DWORD size = FIELD_OFFSET( MIB_IPFORWARDTABLE, table[table->dwNumEntries] );
|
||||||
if (!pIpForwardTable || *pdwSize < size) {
|
if (!pIpForwardTable || *pdwSize < size) {
|
||||||
|
@ -1111,9 +1054,6 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
|
||||||
else {
|
else {
|
||||||
*pdwSize = size;
|
*pdwSize = size;
|
||||||
memcpy(pIpForwardTable, table, size);
|
memcpy(pIpForwardTable, table, size);
|
||||||
if (bOrder)
|
|
||||||
qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries,
|
|
||||||
sizeof(MIB_IPFORWARDROW), IpForwardTableSorter);
|
|
||||||
}
|
}
|
||||||
HeapFree(GetProcessHeap(), 0, table);
|
HeapFree(GetProcessHeap(), 0, table);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1065,12 +1065,44 @@ static MIB_IPFORWARDTABLE *append_ipforward_row( HANDLE heap, DWORD flags, MIB_I
|
||||||
return table;
|
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_IPFORWARDTABLE *table;
|
||||||
MIB_IPFORWARDROW row;
|
MIB_IPFORWARDROW row;
|
||||||
DWORD ret = NO_ERROR, count = 16;
|
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 (!ppIpForwardTable) return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_IPFORWARDTABLE, table[count] ))))
|
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_IPFORWARDTABLE, table[count] ))))
|
||||||
|
@ -1225,8 +1257,14 @@ done:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!table) return ERROR_OUTOFMEMORY;
|
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 );
|
else HeapFree( heap, flags, table );
|
||||||
|
TRACE( "returning ret %u table %p\n", ret, table );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,6 @@ DWORD getUDPStats(MIB_UDPSTATS *stats);
|
||||||
/* Returns the number of entries in the route table. */
|
/* Returns the number of entries in the route table. */
|
||||||
DWORD getNumRoutes(void);
|
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. */
|
/* Returns the number of entries in the arp table. */
|
||||||
DWORD getNumArpEntries(void);
|
DWORD getNumArpEntries(void);
|
||||||
|
|
||||||
|
@ -73,5 +67,6 @@ DWORD getNumTcpEntries(void);
|
||||||
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags);
|
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 AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags);
|
||||||
DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable, 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_ */
|
#endif /* ndef WINE_IPSTATS_H_ */
|
||||||
|
|
Loading…
Reference in New Issue