iphlpapi: Moved AllocateAndGetUdpTableFromStack implementation to ipstats.c.

This commit is contained in:
Alexandre Julliard 2009-03-02 12:50:30 +01:00
parent 3ce9eb0f85
commit 95827a8237
3 changed files with 42 additions and 62 deletions

View File

@ -352,57 +352,6 @@ DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable,
}
static int UdpTableSorter(const void *a, const void *b)
{
int ret;
if (a && b) {
const MIB_UDPROW* rowA = (const MIB_UDPROW*)a;
const MIB_UDPROW* rowB = (const MIB_UDPROW*)b;
ret = rowA->dwLocalAddr - rowB->dwLocalAddr;
if (ret == 0)
ret = rowA->dwLocalPort - rowB->dwLocalPort;
}
else
ret = 0;
return ret;
}
/******************************************************************
* AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
*
* Get the UDP listener table.
* Like GetUdpTable(), but allocate the returned table from heap.
*
* PARAMS
* ppUdpTable [Out] pointer into which the MIB_UDPTABLE 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 ppUdpTable is NULL, whatever GetUdpTable()
* returns otherwise.
*/
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable,
BOOL bOrder, HANDLE heap, DWORD flags)
{
DWORD ret;
TRACE("ppUdpTable %p, bOrder %d, heap %p, flags 0x%08x\n",
ppUdpTable, bOrder, heap, flags);
ret = getUdpTable(ppUdpTable, heap, flags);
if (!ret && bOrder)
qsort((*ppUdpTable)->table, (*ppUdpTable)->dwNumEntries,
sizeof(MIB_UDPROW), UdpTableSorter);
TRACE("returning %d\n", ret);
return ret;
}
/******************************************************************
* CreateIpForwardEntry (IPHLPAPI.@)
*
@ -1650,7 +1599,7 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
if (!pdwSize) return ERROR_INVALID_PARAMETER;
ret = getUdpTable(&table, GetProcessHeap(), 0);
ret = AllocateAndGetUdpTableFromStack( &table, bOrder, GetProcessHeap(), 0 );
if (!ret) {
DWORD size = FIELD_OFFSET( MIB_UDPTABLE, table[table->dwNumEntries] );
if (!pUdpTable || *pdwSize < size) {
@ -1660,9 +1609,6 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
else {
*pdwSize = size;
memcpy(pUdpTable, table, size);
if (bOrder)
qsort(pUdpTable->table, pUdpTable->dwNumEntries,
sizeof(MIB_UDPROW), UdpTableSorter);
}
HeapFree(GetProcessHeap(), 0, table);
}

View File

@ -1454,12 +1454,43 @@ static MIB_UDPTABLE *append_udp_row( HANDLE heap, DWORD flags, MIB_UDPTABLE *tab
return table;
}
DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
static int compare_udp_rows(const void *a, const void *b)
{
const MIB_UDPROW *rowA = a;
const MIB_UDPROW *rowB = b;
int ret;
if ((ret = rowA->dwLocalAddr - rowB->dwLocalAddr) != 0) return ret;
return rowA->dwLocalPort - rowB->dwLocalPort;
}
/******************************************************************
* AllocateAndGetUdpTableFromStack (IPHLPAPI.@)
*
* Get the UDP listener table.
* Like GetUdpTable(), but allocate the returned table from heap.
*
* PARAMS
* ppUdpTable [Out] pointer into which the MIB_UDPTABLE 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 ppUdpTable is NULL, whatever GetUdpTable()
* returns otherwise.
*/
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder,
HANDLE heap, DWORD flags)
{
MIB_UDPTABLE *table;
MIB_UDPROW row;
DWORD ret = NO_ERROR, count = 16;
TRACE("table %p, bOrder %d, heap %p, flags 0x%08x\n", ppUdpTable, bOrder, heap, flags);
if (!ppUdpTable) return ERROR_INVALID_PARAMETER;
if (!(table = HeapAlloc( heap, flags, FIELD_OFFSET(MIB_UDPTABLE, table[count] ))))
@ -1496,8 +1527,14 @@ DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
#endif
if (!table) return ERROR_OUTOFMEMORY;
if (!ret) *ppUdpTable = table;
if (!ret)
{
if (bOrder && table->dwNumEntries)
qsort( table->table, table->dwNumEntries, sizeof(row), compare_udp_rows );
*ppUdpTable = table;
}
else HeapFree( heap, flags, table );
TRACE( "returning ret %u table %p\n", ret, table );
return ret;
}

View File

@ -72,11 +72,6 @@ DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags);
/* Returns the number of entries in the UDP state table. */
DWORD getNumUdpEntries(void);
/* Allocates the UDP state table from heap and returns it to you in *ppUdpTable.
* Returns NO_ERROR on success, something else on failure.
*/
DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags);
/* Returns the number of entries in the TCP state table. */
DWORD getNumTcpEntries(void);
@ -85,4 +80,6 @@ DWORD getNumTcpEntries(void);
*/
DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, HANDLE heap, DWORD flags);
DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags);
#endif /* ndef WINE_IPSTATS_H_ */