4 * Copyright (C) 2003 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Some observations that an automated test can't produce:
23 * An adapter index is a key for an adapter. That is, if an index is returned
24 * from one API, that same index may be used successfully in another API, as
25 * long as the adapter remains present.
26 * If the adapter is removed and reinserted, however, the index may change (and
27 * indeed it does change on Win2K).
29 * The Name field of the IP_ADAPTER_INDEX_MAP entries returned by
30 * GetInterfaceInfo is declared as a wide string, but the bytes are actually
31 * an ASCII string on some versions of the IP helper API under Win9x. This was
32 * apparently an MS bug, it's corrected in later versions.
34 * The DomainName field of FIXED_INFO isn't NULL-terminated on Win98.
43 #include "wine/test.h"
47 static HMODULE hLibrary = NULL;
49 static DWORD (WINAPI *pGetNumberOfInterfaces)(PDWORD);
50 static DWORD (WINAPI *pGetIpAddrTable)(PMIB_IPADDRTABLE,PULONG,BOOL);
51 static DWORD (WINAPI *pGetIfEntry)(PMIB_IFROW);
52 static DWORD (WINAPI *pGetFriendlyIfIndex)(DWORD);
53 static DWORD (WINAPI *pGetIfTable)(PMIB_IFTABLE,PULONG,BOOL);
54 static DWORD (WINAPI *pGetIpForwardTable)(PMIB_IPFORWARDTABLE,PULONG,BOOL);
55 static DWORD (WINAPI *pGetIpNetTable)(PMIB_IPNETTABLE,PULONG,BOOL);
56 static DWORD (WINAPI *pGetInterfaceInfo)(PIP_INTERFACE_INFO,PULONG);
57 static DWORD (WINAPI *pGetAdaptersInfo)(PIP_ADAPTER_INFO,PULONG);
58 static DWORD (WINAPI *pGetNetworkParams)(PFIXED_INFO,PULONG);
59 static DWORD (WINAPI *pGetIcmpStatistics)(PMIB_ICMP);
60 static DWORD (WINAPI *pGetIpStatistics)(PMIB_IPSTATS);
61 static DWORD (WINAPI *pGetTcpStatistics)(PMIB_TCPSTATS);
62 static DWORD (WINAPI *pGetUdpStatistics)(PMIB_UDPSTATS);
63 static DWORD (WINAPI *pGetIcmpStatisticsEx)(PMIB_ICMP_EX,DWORD);
64 static DWORD (WINAPI *pGetIpStatisticsEx)(PMIB_IPSTATS,DWORD);
65 static DWORD (WINAPI *pGetTcpStatisticsEx)(PMIB_TCPSTATS,DWORD);
66 static DWORD (WINAPI *pGetUdpStatisticsEx)(PMIB_UDPSTATS,DWORD);
67 static DWORD (WINAPI *pGetTcpTable)(PMIB_TCPTABLE,PDWORD,BOOL);
68 static DWORD (WINAPI *pGetUdpTable)(PMIB_UDPTABLE,PDWORD,BOOL);
69 static DWORD (WINAPI *pGetPerAdapterInfo)(ULONG,PIP_PER_ADAPTER_INFO,PULONG);
70 static DWORD (WINAPI *pGetAdaptersAddresses)(ULONG,ULONG,PVOID,PIP_ADAPTER_ADDRESSES,PULONG);
71 static DWORD (WINAPI *pNotifyAddrChange)(PHANDLE,LPOVERLAPPED);
72 static BOOL (WINAPI *pCancelIPChangeNotify)(LPOVERLAPPED);
73 static DWORD (WINAPI *pGetExtendedTcpTable)(PVOID,PDWORD,BOOL,ULONG,TCP_TABLE_CLASS,ULONG);
74 static DWORD (WINAPI *pGetExtendedUdpTable)(PVOID,PDWORD,BOOL,ULONG,UDP_TABLE_CLASS,ULONG);
75 static DWORD (WINAPI *pSetTcpEntry)(PMIB_TCPROW);
77 static void loadIPHlpApi(void)
79 hLibrary = LoadLibraryA("iphlpapi.dll");
81 pGetNumberOfInterfaces = (void *)GetProcAddress(hLibrary, "GetNumberOfInterfaces");
82 pGetIpAddrTable = (void *)GetProcAddress(hLibrary, "GetIpAddrTable");
83 pGetIfEntry = (void *)GetProcAddress(hLibrary, "GetIfEntry");
84 pGetFriendlyIfIndex = (void *)GetProcAddress(hLibrary, "GetFriendlyIfIndex");
85 pGetIfTable = (void *)GetProcAddress(hLibrary, "GetIfTable");
86 pGetIpForwardTable = (void *)GetProcAddress(hLibrary, "GetIpForwardTable");
87 pGetIpNetTable = (void *)GetProcAddress(hLibrary, "GetIpNetTable");
88 pGetInterfaceInfo = (void *)GetProcAddress(hLibrary, "GetInterfaceInfo");
89 pGetAdaptersInfo = (void *)GetProcAddress(hLibrary, "GetAdaptersInfo");
90 pGetNetworkParams = (void *)GetProcAddress(hLibrary, "GetNetworkParams");
91 pGetIcmpStatistics = (void *)GetProcAddress(hLibrary, "GetIcmpStatistics");
92 pGetIpStatistics = (void *)GetProcAddress(hLibrary, "GetIpStatistics");
93 pGetTcpStatistics = (void *)GetProcAddress(hLibrary, "GetTcpStatistics");
94 pGetUdpStatistics = (void *)GetProcAddress(hLibrary, "GetUdpStatistics");
95 pGetIcmpStatisticsEx = (void *)GetProcAddress(hLibrary, "GetIcmpStatisticsEx");
96 pGetIpStatisticsEx = (void *)GetProcAddress(hLibrary, "GetIpStatisticsEx");
97 pGetTcpStatisticsEx = (void *)GetProcAddress(hLibrary, "GetTcpStatisticsEx");
98 pGetUdpStatisticsEx = (void *)GetProcAddress(hLibrary, "GetUdpStatisticsEx");
99 pGetTcpTable = (void *)GetProcAddress(hLibrary, "GetTcpTable");
100 pGetUdpTable = (void *)GetProcAddress(hLibrary, "GetUdpTable");
101 pGetPerAdapterInfo = (void *)GetProcAddress(hLibrary, "GetPerAdapterInfo");
102 pGetAdaptersAddresses = (void *)GetProcAddress(hLibrary, "GetAdaptersAddresses");
103 pNotifyAddrChange = (void *)GetProcAddress(hLibrary, "NotifyAddrChange");
104 pCancelIPChangeNotify = (void *)GetProcAddress(hLibrary, "CancelIPChangeNotify");
105 pGetExtendedTcpTable = (void *)GetProcAddress(hLibrary, "GetExtendedTcpTable");
106 pGetExtendedUdpTable = (void *)GetProcAddress(hLibrary, "GetExtendedUdpTable");
107 pSetTcpEntry = (void *)GetProcAddress(hLibrary, "SetTcpEntry");
111 static void freeIPHlpApi(void)
113 FreeLibrary(hLibrary);
116 /* replacement for inet_ntoa */
117 static const char *ntoa( DWORD ip )
119 static char buffer[40];
122 sprintf( buffer, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff );
127 still-to-be-tested 98-only functions:
128 GetUniDirectionalAdapterInfo
130 static void testWin98OnlyFunctions(void)
134 static void testGetNumberOfInterfaces(void)
136 if (pGetNumberOfInterfaces) {
137 DWORD apiReturn, numInterfaces;
139 /* Crashes on Vista */
141 apiReturn = pGetNumberOfInterfaces(NULL);
142 if (apiReturn == ERROR_NOT_SUPPORTED)
144 ok(apiReturn == ERROR_INVALID_PARAMETER,
145 "GetNumberOfInterfaces(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
149 apiReturn = pGetNumberOfInterfaces(&numInterfaces);
150 if (apiReturn == ERROR_NOT_SUPPORTED) {
151 skip("GetNumberOfInterfaces is not supported\n");
154 ok(apiReturn == NO_ERROR,
155 "GetNumberOfInterfaces returned %d, expected 0\n", apiReturn);
159 static void testGetIfEntry(DWORD index)
165 memset(&row, 0, sizeof(row));
166 apiReturn = pGetIfEntry(NULL);
167 if (apiReturn == ERROR_NOT_SUPPORTED) {
168 skip("GetIfEntry is not supported\n");
171 ok(apiReturn == ERROR_INVALID_PARAMETER,
172 "GetIfEntry(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
174 row.dwIndex = -1; /* hope that's always bogus! */
175 apiReturn = pGetIfEntry(&row);
176 ok(apiReturn == ERROR_INVALID_DATA ||
177 apiReturn == ERROR_FILE_NOT_FOUND /* Vista */,
178 "GetIfEntry(bogus row) returned %d, expected ERROR_INVALID_DATA or ERROR_FILE_NOT_FOUND\n",
181 apiReturn = pGetIfEntry(&row);
182 ok(apiReturn == NO_ERROR,
183 "GetIfEntry returned %d, expected NO_ERROR\n", apiReturn);
187 static void testGetIpAddrTable(void)
189 if (pGetIpAddrTable) {
193 apiReturn = pGetIpAddrTable(NULL, NULL, FALSE);
194 if (apiReturn == ERROR_NOT_SUPPORTED) {
195 skip("GetIpAddrTable is not supported\n");
198 ok(apiReturn == ERROR_INVALID_PARAMETER,
199 "GetIpAddrTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
201 apiReturn = pGetIpAddrTable(NULL, &dwSize, FALSE);
202 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
203 "GetIpAddrTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
205 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
206 PMIB_IPADDRTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
208 apiReturn = pGetIpAddrTable(buf, &dwSize, FALSE);
209 ok(apiReturn == NO_ERROR,
210 "GetIpAddrTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
212 if (apiReturn == NO_ERROR && buf->dwNumEntries)
213 testGetIfEntry(buf->table[0].dwIndex);
214 HeapFree(GetProcessHeap(), 0, buf);
219 static void testGetIfTable(void)
225 apiReturn = pGetIfTable(NULL, NULL, FALSE);
226 if (apiReturn == ERROR_NOT_SUPPORTED) {
227 skip("GetIfTable is not supported\n");
230 ok(apiReturn == ERROR_INVALID_PARAMETER,
231 "GetIfTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
233 apiReturn = pGetIfTable(NULL, &dwSize, FALSE);
234 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
235 "GetIfTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
237 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
238 PMIB_IFTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
240 apiReturn = pGetIfTable(buf, &dwSize, FALSE);
241 ok(apiReturn == NO_ERROR,
242 "GetIfTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n\n",
245 if (apiReturn == NO_ERROR && winetest_debug > 1)
248 char name[MAX_INTERFACE_NAME_LEN];
250 trace( "interface table: %u entries\n", buf->dwNumEntries );
251 for (i = 0; i < buf->dwNumEntries; i++)
253 MIB_IFROW *row = &buf->table[i];
254 WideCharToMultiByte( CP_ACP, 0, row->wszName, -1, name, MAX_INTERFACE_NAME_LEN, NULL, NULL );
255 trace( "%u: '%s' type %u mtu %u speed %u phys",
256 row->dwIndex, name, row->dwType, row->dwMtu, row->dwSpeed );
257 for (j = 0; j < row->dwPhysAddrLen; j++)
258 printf( " %02x", row->bPhysAddr[j] );
260 trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
261 row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
262 row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
263 trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
264 row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
265 row->dwOutDiscards, row->dwOutErrors );
268 HeapFree(GetProcessHeap(), 0, buf);
273 static void testGetIpForwardTable(void)
275 if (pGetIpForwardTable) {
279 apiReturn = pGetIpForwardTable(NULL, NULL, FALSE);
280 if (apiReturn == ERROR_NOT_SUPPORTED) {
281 skip("GetIpForwardTable is not supported\n");
284 ok(apiReturn == ERROR_INVALID_PARAMETER,
285 "GetIpForwardTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
287 apiReturn = pGetIpForwardTable(NULL, &dwSize, FALSE);
288 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
289 "GetIpForwardTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
291 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
292 PMIB_IPFORWARDTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
294 apiReturn = pGetIpForwardTable(buf, &dwSize, FALSE);
295 ok(apiReturn == NO_ERROR,
296 "GetIpForwardTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
299 if (apiReturn == NO_ERROR && winetest_debug > 1)
303 trace( "IP forward table: %u entries\n", buf->dwNumEntries );
304 for (i = 0; i < buf->dwNumEntries; i++)
307 sprintf( buffer, "dest %s", ntoa( buf->table[i].dwForwardDest ));
308 sprintf( buffer + strlen(buffer), " mask %s", ntoa( buf->table[i].dwForwardMask ));
309 trace( "%u: %s gw %s if %u type %u\n", i, buffer,
310 ntoa( buf->table[i].dwForwardNextHop ),
311 buf->table[i].dwForwardIfIndex, U1(buf->table[i]).dwForwardType );
314 HeapFree(GetProcessHeap(), 0, buf);
319 static void testGetIpNetTable(void)
321 if (pGetIpNetTable) {
325 apiReturn = pGetIpNetTable(NULL, NULL, FALSE);
326 if (apiReturn == ERROR_NOT_SUPPORTED) {
327 skip("GetIpNetTable is not supported\n");
330 ok(apiReturn == ERROR_INVALID_PARAMETER,
331 "GetIpNetTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
333 apiReturn = pGetIpNetTable(NULL, &dwSize, FALSE);
334 ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_INSUFFICIENT_BUFFER,
335 "GetIpNetTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_NO_DATA or ERROR_INSUFFICIENT_BUFFER\n",
337 if (apiReturn == ERROR_NO_DATA)
338 ; /* empty ARP table's okay */
339 else if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
340 PMIB_IPNETTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
342 apiReturn = pGetIpNetTable(buf, &dwSize, FALSE);
343 ok(apiReturn == NO_ERROR ||
344 apiReturn == ERROR_NO_DATA, /* empty ARP table's okay */
345 "GetIpNetTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
348 if (apiReturn == NO_ERROR && winetest_debug > 1)
352 trace( "IP net table: %u entries\n", buf->dwNumEntries );
353 for (i = 0; i < buf->dwNumEntries; i++)
355 trace( "%u: idx %u type %u addr %s phys",
356 i, buf->table[i].dwIndex, U(buf->table[i]).dwType, ntoa( buf->table[i].dwAddr ));
357 for (j = 0; j < buf->table[i].dwPhysAddrLen; j++)
358 printf( " %02x", buf->table[i].bPhysAddr[j] );
362 HeapFree(GetProcessHeap(), 0, buf);
367 static void testGetIcmpStatistics(void)
369 if (pGetIcmpStatistics) {
373 /* Crashes on Vista */
375 apiReturn = pGetIcmpStatistics(NULL);
376 if (apiReturn == ERROR_NOT_SUPPORTED)
378 ok(apiReturn == ERROR_INVALID_PARAMETER,
379 "GetIcmpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
383 apiReturn = pGetIcmpStatistics(&stats);
384 if (apiReturn == ERROR_NOT_SUPPORTED)
386 skip("GetIcmpStatistics is not supported\n");
389 ok(apiReturn == NO_ERROR,
390 "GetIcmpStatistics returned %d, expected NO_ERROR\n", apiReturn);
391 if (apiReturn == NO_ERROR && winetest_debug > 1)
393 trace( "ICMP stats: %8s %8s\n", "in", "out" );
394 trace( " dwMsgs: %8u %8u\n", stats.stats.icmpInStats.dwMsgs, stats.stats.icmpOutStats.dwMsgs );
395 trace( " dwErrors: %8u %8u\n", stats.stats.icmpInStats.dwErrors, stats.stats.icmpOutStats.dwErrors );
396 trace( " dwDestUnreachs: %8u %8u\n", stats.stats.icmpInStats.dwDestUnreachs, stats.stats.icmpOutStats.dwDestUnreachs );
397 trace( " dwTimeExcds: %8u %8u\n", stats.stats.icmpInStats.dwTimeExcds, stats.stats.icmpOutStats.dwTimeExcds );
398 trace( " dwParmProbs: %8u %8u\n", stats.stats.icmpInStats.dwParmProbs, stats.stats.icmpOutStats.dwParmProbs );
399 trace( " dwSrcQuenchs: %8u %8u\n", stats.stats.icmpInStats.dwSrcQuenchs, stats.stats.icmpOutStats.dwSrcQuenchs );
400 trace( " dwRedirects: %8u %8u\n", stats.stats.icmpInStats.dwRedirects, stats.stats.icmpOutStats.dwRedirects );
401 trace( " dwEchos: %8u %8u\n", stats.stats.icmpInStats.dwEchos, stats.stats.icmpOutStats.dwEchos );
402 trace( " dwEchoReps: %8u %8u\n", stats.stats.icmpInStats.dwEchoReps, stats.stats.icmpOutStats.dwEchoReps );
403 trace( " dwTimestamps: %8u %8u\n", stats.stats.icmpInStats.dwTimestamps, stats.stats.icmpOutStats.dwTimestamps );
404 trace( " dwTimestampReps: %8u %8u\n", stats.stats.icmpInStats.dwTimestampReps, stats.stats.icmpOutStats.dwTimestampReps );
405 trace( " dwAddrMasks: %8u %8u\n", stats.stats.icmpInStats.dwAddrMasks, stats.stats.icmpOutStats.dwAddrMasks );
406 trace( " dwAddrMaskReps: %8u %8u\n", stats.stats.icmpInStats.dwAddrMaskReps, stats.stats.icmpOutStats.dwAddrMaskReps );
411 static void testGetIpStatistics(void)
413 if (pGetIpStatistics) {
417 apiReturn = pGetIpStatistics(NULL);
418 if (apiReturn == ERROR_NOT_SUPPORTED) {
419 skip("GetIpStatistics is not supported\n");
422 ok(apiReturn == ERROR_INVALID_PARAMETER,
423 "GetIpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
425 apiReturn = pGetIpStatistics(&stats);
426 ok(apiReturn == NO_ERROR,
427 "GetIpStatistics returned %d, expected NO_ERROR\n", apiReturn);
428 if (apiReturn == NO_ERROR && winetest_debug > 1)
430 trace( "IP stats:\n" );
431 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
432 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
433 trace( " dwInReceives: %u\n", stats.dwInReceives );
434 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
435 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
436 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
437 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
438 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
439 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
440 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
441 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
442 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
443 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
444 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
445 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
446 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
447 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
448 trace( " dwFragOks: %u\n", stats.dwFragOks );
449 trace( " dwFragFails: %u\n", stats.dwFragFails );
450 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
451 trace( " dwNumIf: %u\n", stats.dwNumIf );
452 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
453 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
458 static void testGetTcpStatistics(void)
460 if (pGetTcpStatistics) {
464 apiReturn = pGetTcpStatistics(NULL);
465 if (apiReturn == ERROR_NOT_SUPPORTED) {
466 skip("GetTcpStatistics is not supported\n");
469 ok(apiReturn == ERROR_INVALID_PARAMETER,
470 "GetTcpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
472 apiReturn = pGetTcpStatistics(&stats);
473 ok(apiReturn == NO_ERROR,
474 "GetTcpStatistics returned %d, expected NO_ERROR\n", apiReturn);
475 if (apiReturn == NO_ERROR && winetest_debug > 1)
477 trace( "TCP stats:\n" );
478 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
479 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
480 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
481 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
482 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
483 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
484 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
485 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
486 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
487 trace( " dwInSegs: %u\n", stats.dwInSegs );
488 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
489 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
490 trace( " dwInErrs: %u\n", stats.dwInErrs );
491 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
492 trace( " dwNumConns: %u\n", stats.dwNumConns );
497 static void testGetUdpStatistics(void)
499 if (pGetUdpStatistics) {
503 apiReturn = pGetUdpStatistics(NULL);
504 if (apiReturn == ERROR_NOT_SUPPORTED) {
505 skip("GetUdpStatistics is not supported\n");
508 ok(apiReturn == ERROR_INVALID_PARAMETER,
509 "GetUdpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
511 apiReturn = pGetUdpStatistics(&stats);
512 ok(apiReturn == NO_ERROR,
513 "GetUdpStatistics returned %d, expected NO_ERROR\n", apiReturn);
514 if (apiReturn == NO_ERROR && winetest_debug > 1)
516 trace( "UDP stats:\n" );
517 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
518 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
519 trace( " dwInErrors: %u\n", stats.dwInErrors );
520 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
521 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
526 static void testGetIcmpStatisticsEx(void)
531 if (!pGetIcmpStatisticsEx)
533 skip( "GetIcmpStatisticsEx not available\n" );
537 /* Crashes on Vista */
539 apiReturn = pGetIcmpStatisticsEx(NULL, AF_INET);
540 ok(apiReturn == ERROR_INVALID_PARAMETER,
541 "GetIcmpStatisticsEx(NULL, AF_INET) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
544 apiReturn = pGetIcmpStatisticsEx(&stats, AF_INET);
545 ok(apiReturn == NO_ERROR, "GetIcmpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
546 if (apiReturn == NO_ERROR && winetest_debug > 1)
549 trace( "ICMP Ex stats: %8s %8s\n", "in", "out" );
550 trace( " dwMsgs: %8u %8u\n", stats.icmpInStats.dwMsgs, stats.icmpOutStats.dwMsgs );
551 trace( " dwErrors: %8u %8u\n", stats.icmpInStats.dwErrors, stats.icmpOutStats.dwErrors );
552 for (i = 0; i < 256; i++)
553 trace( " rgdwTypeCount[%3i]: %8u %8u\n", i, stats.icmpInStats.rgdwTypeCount[i], stats.icmpOutStats.rgdwTypeCount[i] );
556 apiReturn = pGetIcmpStatisticsEx(&stats, AF_INET6);
557 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
558 "GetIcmpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
559 if (apiReturn == NO_ERROR && winetest_debug > 1)
562 trace( "ICMP Ex stats: %8s %8s\n", "in", "out" );
563 trace( " dwMsgs: %8u %8u\n", stats.icmpInStats.dwMsgs, stats.icmpOutStats.dwMsgs );
564 trace( " dwErrors: %8u %8u\n", stats.icmpInStats.dwErrors, stats.icmpOutStats.dwErrors );
565 for (i = 0; i < 256; i++)
566 trace( " rgdwTypeCount[%3i]: %8u %8u\n", i, stats.icmpInStats.rgdwTypeCount[i], stats.icmpOutStats.rgdwTypeCount[i] );
570 static void testGetIpStatisticsEx(void)
575 if (!pGetIpStatisticsEx)
577 win_skip( "GetIpStatisticsEx not available\n" );
581 apiReturn = pGetIpStatisticsEx(NULL, AF_INET);
582 ok(apiReturn == ERROR_INVALID_PARAMETER,
583 "GetIpStatisticsEx(NULL, AF_INET) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
585 apiReturn = pGetIpStatisticsEx(&stats, AF_BAN);
586 ok(apiReturn == ERROR_INVALID_PARAMETER,
587 "GetIpStatisticsEx(&stats, AF_BAN) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
589 apiReturn = pGetIpStatisticsEx(&stats, AF_INET);
590 ok(apiReturn == NO_ERROR, "GetIpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
591 if (apiReturn == NO_ERROR && winetest_debug > 1)
593 trace( "IP Ex stats:\n" );
594 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
595 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
596 trace( " dwInReceives: %u\n", stats.dwInReceives );
597 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
598 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
599 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
600 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
601 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
602 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
603 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
604 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
605 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
606 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
607 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
608 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
609 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
610 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
611 trace( " dwFragOks: %u\n", stats.dwFragOks );
612 trace( " dwFragFails: %u\n", stats.dwFragFails );
613 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
614 trace( " dwNumIf: %u\n", stats.dwNumIf );
615 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
616 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
619 apiReturn = pGetIpStatisticsEx(&stats, AF_INET6);
620 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
621 "GetIpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
622 if (apiReturn == NO_ERROR && winetest_debug > 1)
624 trace( "IP Ex stats:\n" );
625 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
626 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
627 trace( " dwInReceives: %u\n", stats.dwInReceives );
628 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
629 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
630 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
631 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
632 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
633 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
634 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
635 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
636 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
637 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
638 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
639 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
640 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
641 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
642 trace( " dwFragOks: %u\n", stats.dwFragOks );
643 trace( " dwFragFails: %u\n", stats.dwFragFails );
644 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
645 trace( " dwNumIf: %u\n", stats.dwNumIf );
646 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
647 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
651 static void testGetTcpStatisticsEx(void)
656 if (!pGetTcpStatisticsEx)
658 skip( "GetTcpStatisticsEx not available\n" );
662 apiReturn = pGetTcpStatisticsEx(NULL, AF_INET);
663 ok(apiReturn == ERROR_INVALID_PARAMETER,
664 "GetTcpStatisticsEx(NULL, AF_INET); returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
666 apiReturn = pGetTcpStatisticsEx(&stats, AF_INET);
667 ok(apiReturn == NO_ERROR, "GetTcpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
668 if (apiReturn == NO_ERROR && winetest_debug > 1)
670 trace( "TCP stats:\n" );
671 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
672 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
673 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
674 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
675 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
676 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
677 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
678 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
679 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
680 trace( " dwInSegs: %u\n", stats.dwInSegs );
681 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
682 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
683 trace( " dwInErrs: %u\n", stats.dwInErrs );
684 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
685 trace( " dwNumConns: %u\n", stats.dwNumConns );
688 apiReturn = pGetTcpStatisticsEx(&stats, AF_INET6);
689 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
690 "GetTcpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
691 if (apiReturn == NO_ERROR && winetest_debug > 1)
693 trace( "TCP stats:\n" );
694 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
695 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
696 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
697 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
698 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
699 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
700 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
701 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
702 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
703 trace( " dwInSegs: %u\n", stats.dwInSegs );
704 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
705 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
706 trace( " dwInErrs: %u\n", stats.dwInErrs );
707 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
708 trace( " dwNumConns: %u\n", stats.dwNumConns );
712 static void testGetUdpStatisticsEx(void)
717 if (!pGetUdpStatisticsEx)
719 skip( "GetUdpStatisticsEx not available\n" );
723 apiReturn = pGetUdpStatisticsEx(NULL, AF_INET);
724 ok(apiReturn == ERROR_INVALID_PARAMETER,
725 "GetUdpStatisticsEx(NULL, AF_INET); returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
727 apiReturn = pGetUdpStatisticsEx(&stats, AF_INET);
728 ok(apiReturn == NO_ERROR, "GetUdpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
729 if (apiReturn == NO_ERROR && winetest_debug > 1)
731 trace( "UDP stats:\n" );
732 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
733 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
734 trace( " dwInErrors: %u\n", stats.dwInErrors );
735 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
736 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
739 apiReturn = pGetUdpStatisticsEx(&stats, AF_INET6);
740 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
741 "GetUdpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
742 if (apiReturn == NO_ERROR && winetest_debug > 1)
744 trace( "UDP stats:\n" );
745 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
746 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
747 trace( " dwInErrors: %u\n", stats.dwInErrors );
748 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
749 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
753 static void testGetTcpTable(void)
759 apiReturn = pGetTcpTable(NULL, &dwSize, FALSE);
760 if (apiReturn == ERROR_NOT_SUPPORTED) {
761 skip("GetTcpTable is not supported\n");
764 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER ||
765 broken(apiReturn == ERROR_NO_DATA), /* win95 */
766 "GetTcpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
768 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
769 PMIB_TCPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
771 apiReturn = pGetTcpTable(buf, &dwSize, FALSE);
772 ok(apiReturn == NO_ERROR,
773 "GetTcpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
776 if (apiReturn == NO_ERROR && winetest_debug > 1)
779 trace( "TCP table: %u entries\n", buf->dwNumEntries );
780 for (i = 0; i < buf->dwNumEntries; i++)
783 sprintf( buffer, "local %s:%u",
784 ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) );
785 trace( "%u: %s remote %s:%u state %u\n",
786 i, buffer, ntoa( buf->table[i].dwRemoteAddr ),
787 ntohs(buf->table[i].dwRemotePort), U(buf->table[i]).dwState );
790 HeapFree(GetProcessHeap(), 0, buf);
795 static void testGetUdpTable(void)
801 apiReturn = pGetUdpTable(NULL, &dwSize, FALSE);
802 if (apiReturn == ERROR_NOT_SUPPORTED) {
803 skip("GetUdpTable is not supported\n");
806 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
807 "GetUdpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
809 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
810 PMIB_UDPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
812 apiReturn = pGetUdpTable(buf, &dwSize, FALSE);
813 ok(apiReturn == NO_ERROR,
814 "GetUdpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
817 if (apiReturn == NO_ERROR && winetest_debug > 1)
820 trace( "UDP table: %u entries\n", buf->dwNumEntries );
821 for (i = 0; i < buf->dwNumEntries; i++)
822 trace( "%u: %s:%u\n",
823 i, ntoa( buf->table[i].dwLocalAddr ), ntohs(buf->table[i].dwLocalPort) );
825 HeapFree(GetProcessHeap(), 0, buf);
830 static void testSetTcpEntry(void)
835 memset(&row, 0, sizeof(row));
836 if(0) /* This test crashes in OS >= VISTA */
838 ret = pSetTcpEntry(NULL);
839 ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
842 ret = pSetTcpEntry(&row);
843 todo_wine ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
845 U(row).dwState = MIB_TCP_STATE_DELETE_TCB;
846 ret = pSetTcpEntry(&row);
847 todo_wine ok( ret == ERROR_MR_MID_NOT_FOUND || broken(ret == ERROR_INVALID_PARAMETER),
848 "got %u, expected %u\n", ret, ERROR_MR_MID_NOT_FOUND);
852 still-to-be-tested NT4-onward functions:
865 static void testWinNT4Functions(void)
867 testGetNumberOfInterfaces();
868 testGetIpAddrTable();
870 testGetIpForwardTable();
872 testGetIcmpStatistics();
873 testGetIpStatistics();
874 testGetTcpStatistics();
875 testGetUdpStatistics();
876 testGetIcmpStatisticsEx();
877 testGetIpStatisticsEx();
878 testGetTcpStatisticsEx();
879 testGetUdpStatisticsEx();
885 static void testGetInterfaceInfo(void)
887 if (pGetInterfaceInfo) {
891 apiReturn = pGetInterfaceInfo(NULL, NULL);
892 if (apiReturn == ERROR_NOT_SUPPORTED) {
893 skip("GetInterfaceInfo is not supported\n");
896 ok(apiReturn == ERROR_INVALID_PARAMETER,
897 "GetInterfaceInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
899 apiReturn = pGetInterfaceInfo(NULL, &len);
900 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
901 "GetInterfaceInfo returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
903 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
904 PIP_INTERFACE_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
906 apiReturn = pGetInterfaceInfo(buf, &len);
907 ok(apiReturn == NO_ERROR,
908 "GetInterfaceInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
910 HeapFree(GetProcessHeap(), 0, buf);
915 static void testGetAdaptersInfo(void)
917 if (pGetAdaptersInfo) {
921 apiReturn = pGetAdaptersInfo(NULL, NULL);
922 if (apiReturn == ERROR_NOT_SUPPORTED) {
923 skip("GetAdaptersInfo is not supported\n");
926 ok(apiReturn == ERROR_INVALID_PARAMETER,
927 "GetAdaptersInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
929 apiReturn = pGetAdaptersInfo(NULL, &len);
930 ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_BUFFER_OVERFLOW,
931 "GetAdaptersInfo returned %d, expected ERROR_NO_DATA or ERROR_BUFFER_OVERFLOW\n",
933 if (apiReturn == ERROR_NO_DATA)
934 ; /* no adapter's, that's okay */
935 else if (apiReturn == ERROR_BUFFER_OVERFLOW) {
936 PIP_ADAPTER_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
938 apiReturn = pGetAdaptersInfo(buf, &len);
939 ok(apiReturn == NO_ERROR,
940 "GetAdaptersInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
942 HeapFree(GetProcessHeap(), 0, buf);
947 static void testGetNetworkParams(void)
949 if (pGetNetworkParams) {
953 apiReturn = pGetNetworkParams(NULL, NULL);
954 if (apiReturn == ERROR_NOT_SUPPORTED) {
955 skip("GetNetworkParams is not supported\n");
958 ok(apiReturn == ERROR_INVALID_PARAMETER,
959 "GetNetworkParams returned %d, expected ERROR_INVALID_PARAMETER\n",
961 apiReturn = pGetNetworkParams(NULL, &len);
962 ok(apiReturn == ERROR_BUFFER_OVERFLOW,
963 "GetNetworkParams returned %d, expected ERROR_BUFFER_OVERFLOW\n",
965 if (apiReturn == ERROR_BUFFER_OVERFLOW) {
966 PFIXED_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
968 apiReturn = pGetNetworkParams(buf, &len);
969 ok(apiReturn == NO_ERROR,
970 "GetNetworkParams(buf, &dwSize) returned %d, expected NO_ERROR\n",
972 HeapFree(GetProcessHeap(), 0, buf);
978 still-to-be-tested 98-onward functions:
984 static DWORD CALLBACK testWin98Functions(void *p)
986 testGetInterfaceInfo();
987 testGetAdaptersInfo();
988 testGetNetworkParams();
992 static void testGetPerAdapterInfo(void)
997 if (!pGetPerAdapterInfo) return;
998 ret = pGetPerAdapterInfo(1, NULL, NULL);
999 if (ret == ERROR_NOT_SUPPORTED) {
1000 skip("GetPerAdapterInfo is not supported\n");
1003 ok( ret == ERROR_INVALID_PARAMETER, "got %u instead of ERROR_INVALID_PARAMETER\n", ret );
1004 needed = 0xdeadbeef;
1005 ret = pGetPerAdapterInfo(1, NULL, &needed);
1006 if (ret == ERROR_NO_DATA) return; /* no such adapter */
1007 ok( ret == ERROR_BUFFER_OVERFLOW, "got %u instead of ERROR_BUFFER_OVERFLOW\n", ret );
1008 ok( needed != 0xdeadbeef, "needed not set\n" );
1009 buffer = HeapAlloc( GetProcessHeap(), 0, needed );
1010 ret = pGetPerAdapterInfo(1, buffer, &needed);
1011 ok( ret == NO_ERROR, "got %u instead of NO_ERROR\n", ret );
1012 HeapFree( GetProcessHeap(), 0, buffer );
1015 static void testNotifyAddrChange(void)
1018 OVERLAPPED overlapped;
1022 if (!pNotifyAddrChange)
1024 win_skip("NotifyAddrChange not present\n");
1027 if (!pCancelIPChangeNotify)
1029 win_skip("CancelIPChangeNotify not present\n");
1034 ZeroMemory(&overlapped, sizeof(overlapped));
1035 ret = pNotifyAddrChange(&handle, &overlapped);
1036 if (ret == ERROR_NOT_SUPPORTED)
1038 win_skip("NotifyAddrChange is not supported\n");
1041 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
1042 ret = GetLastError();
1043 todo_wine ok(ret == ERROR_IO_PENDING, "GetLastError returned %d, expected ERROR_IO_PENDING\n", ret);
1044 success = pCancelIPChangeNotify(&overlapped);
1045 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
1047 ZeroMemory(&overlapped, sizeof(overlapped));
1048 success = pCancelIPChangeNotify(&overlapped);
1049 ok(success == FALSE, "CancelIPChangeNotify returned TRUE, expected FALSE\n");
1052 ZeroMemory(&overlapped, sizeof(overlapped));
1053 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1054 ret = pNotifyAddrChange(&handle, &overlapped);
1055 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
1056 todo_wine ok(handle != INVALID_HANDLE_VALUE, "NotifyAddrChange returned invalid file handle\n");
1057 success = GetOverlappedResult(handle, &overlapped, &bytes, FALSE);
1058 ok(success == FALSE, "GetOverlappedResult returned TRUE, expected FALSE\n");
1059 ret = GetLastError();
1060 ok(ret == ERROR_IO_INCOMPLETE, "GetLastError returned %d, expected ERROR_IO_INCOMPLETE\n", ret);
1061 success = pCancelIPChangeNotify(&overlapped);
1062 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
1064 if (winetest_interactive)
1067 ZeroMemory(&overlapped, sizeof(overlapped));
1068 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1069 trace("Testing asynchronous ipv4 address change notification. Please "
1070 "change the ipv4 address of one of your network interfaces\n");
1071 ret = pNotifyAddrChange(&handle, &overlapped);
1072 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
1073 success = GetOverlappedResult(handle, &overlapped, &bytes, TRUE);
1074 ok(success == TRUE, "GetOverlappedResult returned FALSE, expected TRUE\n");
1077 /* test synchronous functionality */
1078 if (winetest_interactive)
1080 trace("Testing synchronous ipv4 address change notification. Please "
1081 "change the ipv4 address of one of your network interfaces\n");
1082 ret = pNotifyAddrChange(NULL, NULL);
1083 todo_wine ok(ret == NO_ERROR, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
1088 still-to-be-tested 2K-onward functions:
1096 NotifyRouteChange + CancelIPChangeNotify
1100 static void testWin2KFunctions(void)
1102 testGetPerAdapterInfo();
1103 testNotifyAddrChange();
1106 static void test_GetAdaptersAddresses(void)
1109 IP_ADAPTER_ADDRESSES *aa, *ptr;
1110 IP_ADAPTER_UNICAST_ADDRESS *ua;
1112 if (!pGetAdaptersAddresses)
1114 win_skip("GetAdaptersAddresses not present\n");
1118 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, NULL);
1119 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", ret);
1121 /* size should be ignored and overwritten if buffer is NULL */
1123 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size);
1124 ok(ret == ERROR_BUFFER_OVERFLOW, "expected ERROR_BUFFER_OVERFLOW, got %u\n", ret);
1125 if (ret != ERROR_BUFFER_OVERFLOW) return;
1127 ptr = HeapAlloc(GetProcessHeap(), 0, size);
1128 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, ptr, &size);
1129 ok(!ret, "expected ERROR_SUCCESS got %u\n", ret);
1131 for (aa = ptr; !ret && aa; aa = aa->Next)
1133 ok(aa->DnsSuffix != NULL, "DnsSuffix is not a valid pointer\n");
1134 ok(aa->Description != NULL, "Description is not a valid pointer\n");
1135 ok(aa->FriendlyName != NULL, "FriendlyName is not a valid pointer\n");
1137 if (winetest_debug <= 1)
1140 trace("Length: %u\n", S(U(*aa)).Length);
1141 trace("IfIndex: %u\n", S(U(*aa)).IfIndex);
1142 trace("Next: %p\n", aa->Next);
1143 trace("AdapterName: %s\n", aa->AdapterName);
1144 trace("FirstUnicastAddress: %p\n", aa->FirstUnicastAddress);
1145 ua = aa->FirstUnicastAddress;
1148 trace("\tLength: %u\n", S(U(*ua)).Length);
1149 trace("\tFlags: 0x%08x\n", S(U(*ua)).Flags);
1150 trace("\tNext: %p\n", ua->Next);
1151 trace("\tAddress.lpSockaddr: %p\n", ua->Address.lpSockaddr);
1152 trace("\tAddress.iSockaddrLength: %d\n", ua->Address.iSockaddrLength);
1153 trace("\tPrefixOrigin: %u\n", ua->PrefixOrigin);
1154 trace("\tSuffixOrigin: %u\n", ua->SuffixOrigin);
1155 trace("\tDadState: %u\n", ua->DadState);
1156 trace("\tValidLifetime: 0x%08x\n", ua->ValidLifetime);
1157 trace("\tPreferredLifetime: 0x%08x\n", ua->PreferredLifetime);
1158 trace("\tLeaseLifetime: 0x%08x\n", ua->LeaseLifetime);
1162 trace("FirstAnycastAddress: %p\n", aa->FirstAnycastAddress);
1163 trace("FirstMulticastAddress: %p\n", aa->FirstMulticastAddress);
1164 trace("FirstDnsServerAddress: %p\n", aa->FirstDnsServerAddress);
1165 trace("DnsSuffix: %p\n", aa->DnsSuffix);
1166 trace("Description: %p\n", aa->Description);
1167 trace("FriendlyName: %p\n", aa->FriendlyName);
1168 trace("PhysicalAddress: %02x\n", aa->PhysicalAddress[0]);
1169 trace("PhysicalAddressLength: %u\n", aa->PhysicalAddressLength);
1170 trace("Flags: 0x%08x\n", aa->Flags);
1171 trace("Mtu: %u\n", aa->Mtu);
1172 trace("IfType: %u\n", aa->IfType);
1173 trace("OperStatus: %u\n", aa->OperStatus);
1176 HeapFree(GetProcessHeap(), 0, ptr);
1179 static void test_GetExtendedTcpTable(void)
1182 MIB_TCPTABLE *table;
1183 MIB_TCPTABLE_OWNER_PID *table_pid;
1185 if (!pGetExtendedTcpTable)
1187 win_skip("GetExtendedTcpTable not available\n");
1190 ret = pGetExtendedTcpTable( NULL, NULL, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1191 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
1194 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1195 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1197 table = HeapAlloc( GetProcessHeap(), 0, size );
1198 ret = pGetExtendedTcpTable( table, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1199 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1200 HeapFree( GetProcessHeap(), 0, table );
1203 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
1204 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1206 table_pid = HeapAlloc( GetProcessHeap(), 0, size );
1207 ret = pGetExtendedTcpTable( table_pid, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
1208 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1209 HeapFree( GetProcessHeap(), 0, table_pid );
1212 static void test_GetExtendedUdpTable(void)
1215 MIB_UDPTABLE *table;
1216 MIB_UDPTABLE_OWNER_PID *table_pid;
1218 if (!pGetExtendedUdpTable)
1220 win_skip("GetExtendedUdpTable not available\n");
1223 ret = pGetExtendedUdpTable( NULL, NULL, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1224 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
1227 ret = pGetExtendedUdpTable( NULL, &size, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1228 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1230 table = HeapAlloc( GetProcessHeap(), 0, size );
1231 ret = pGetExtendedUdpTable( table, &size, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1232 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1233 HeapFree( GetProcessHeap(), 0, table );
1236 ret = pGetExtendedUdpTable( NULL, &size, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0 );
1237 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1239 table_pid = HeapAlloc( GetProcessHeap(), 0, size );
1240 ret = pGetExtendedUdpTable( table_pid, &size, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0 );
1241 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1242 HeapFree( GetProcessHeap(), 0, table_pid );
1245 START_TEST(iphlpapi)
1252 testWin98OnlyFunctions();
1253 testWinNT4Functions();
1255 /* run testGetXXXX in two threads at once to make sure we don't crash in that case */
1256 thread = CreateThread(NULL, 0, testWin98Functions, NULL, 0, NULL);
1257 testWin98Functions(NULL);
1258 WaitForSingleObject(thread, INFINITE);
1260 testWin2KFunctions();
1261 test_GetAdaptersAddresses();
1262 test_GetExtendedTcpTable();
1263 test_GetExtendedUdpTable();