From: Paul Gofman pgofman@codeweavers.com
--- dlls/iphlpapi/iphlpapi_main.c | 3 +++ dlls/iphlpapi/tests/iphlpapi.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 5d904d875fe..75024a249bb 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -2282,6 +2282,9 @@ err: static int ipnetrow_cmp( const void *a, const void *b ) { const MIB_IPNETROW *rowA = a, *rowB = b; + + if (rowA->dwIndex != rowB->dwIndex) return rowA->dwIndex < rowB->dwIndex ? -1 : 1; + return DWORD_cmp(RtlUlongByteSwap( rowA->dwAddr ), RtlUlongByteSwap( rowB->dwAddr )); }
diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c index 29256eb2774..af893aeae54 100644 --- a/dlls/iphlpapi/tests/iphlpapi.c +++ b/dlls/iphlpapi/tests/iphlpapi.c @@ -370,6 +370,7 @@ static void testGetIpNetTable(void) { DWORD apiReturn; ULONG dwSize = 0; + unsigned int i;
apiReturn = GetIpNetTable(NULL, NULL, FALSE); if (apiReturn == ERROR_NOT_SUPPORTED) { @@ -389,11 +390,23 @@ static void testGetIpNetTable(void) PMIB_IPNETTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
memset(buf, 0xcc, dwSize); - apiReturn = GetIpNetTable(buf, &dwSize, FALSE); + apiReturn = GetIpNetTable(buf, &dwSize, TRUE); ok((apiReturn == NO_ERROR && buf->dwNumEntries) || (apiReturn == ERROR_NO_DATA && !buf->dwNumEntries), "got apiReturn %lu, dwSize %lu, buf->dwNumEntries %lu.\n", apiReturn, dwSize, buf->dwNumEntries);
+ if (apiReturn == NO_ERROR) + { + for (i = 0; i < buf->dwNumEntries - 1; ++i) + { + ok( buf->table[i].dwIndex <= buf->table[i + 1].dwIndex, + "Entries are not sorted by index, i %u.\n", i ); + if (buf->table[i].dwIndex == buf->table[i + 1].dwIndex) + ok(ntohl(buf->table[i].dwAddr) <= ntohl(buf->table[i + 1].dwAddr), + "Entries are not sorted by address, i %u.\n", i ); + } + } + if (apiReturn == NO_ERROR && winetest_debug > 1) { DWORD i, j;