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 *pGetTcpTable)(PMIB_TCPTABLE,PDWORD,BOOL);
64 static DWORD (WINAPI *pGetUdpTable)(PMIB_UDPTABLE,PDWORD,BOOL);
65 static DWORD (WINAPI *pGetPerAdapterInfo)(ULONG,PIP_PER_ADAPTER_INFO,PULONG);
66 static DWORD (WINAPI *pGetAdaptersAddresses)(ULONG,ULONG,PVOID,PIP_ADAPTER_ADDRESSES,PULONG);
67 static DWORD (WINAPI *pNotifyAddrChange)(PHANDLE,LPOVERLAPPED);
68 static BOOL (WINAPI *pCancelIPChangeNotify)(LPOVERLAPPED);
69 static DWORD (WINAPI *pGetExtendedTcpTable)(PVOID,PDWORD,BOOL,ULONG,TCP_TABLE_CLASS,ULONG);
70 static DWORD (WINAPI *pSetTcpEntry)(PMIB_TCPROW);
72 static void loadIPHlpApi(void)
74 hLibrary = LoadLibraryA("iphlpapi.dll");
76 pGetNumberOfInterfaces = (void *)GetProcAddress(hLibrary, "GetNumberOfInterfaces");
77 pGetIpAddrTable = (void *)GetProcAddress(hLibrary, "GetIpAddrTable");
78 pGetIfEntry = (void *)GetProcAddress(hLibrary, "GetIfEntry");
79 pGetFriendlyIfIndex = (void *)GetProcAddress(hLibrary, "GetFriendlyIfIndex");
80 pGetIfTable = (void *)GetProcAddress(hLibrary, "GetIfTable");
81 pGetIpForwardTable = (void *)GetProcAddress(hLibrary, "GetIpForwardTable");
82 pGetIpNetTable = (void *)GetProcAddress(hLibrary, "GetIpNetTable");
83 pGetInterfaceInfo = (void *)GetProcAddress(hLibrary, "GetInterfaceInfo");
84 pGetAdaptersInfo = (void *)GetProcAddress(hLibrary, "GetAdaptersInfo");
85 pGetNetworkParams = (void *)GetProcAddress(hLibrary, "GetNetworkParams");
86 pGetIcmpStatistics = (void *)GetProcAddress(hLibrary, "GetIcmpStatistics");
87 pGetIpStatistics = (void *)GetProcAddress(hLibrary, "GetIpStatistics");
88 pGetTcpStatistics = (void *)GetProcAddress(hLibrary, "GetTcpStatistics");
89 pGetUdpStatistics = (void *)GetProcAddress(hLibrary, "GetUdpStatistics");
90 pGetTcpTable = (void *)GetProcAddress(hLibrary, "GetTcpTable");
91 pGetUdpTable = (void *)GetProcAddress(hLibrary, "GetUdpTable");
92 pGetPerAdapterInfo = (void *)GetProcAddress(hLibrary, "GetPerAdapterInfo");
93 pGetAdaptersAddresses = (void *)GetProcAddress(hLibrary, "GetAdaptersAddresses");
94 pNotifyAddrChange = (void *)GetProcAddress(hLibrary, "NotifyAddrChange");
95 pCancelIPChangeNotify = (void *)GetProcAddress(hLibrary, "CancelIPChangeNotify");
96 pGetExtendedTcpTable = (void *)GetProcAddress(hLibrary, "GetExtendedTcpTable");
97 pSetTcpEntry = (void *)GetProcAddress(hLibrary, "SetTcpEntry");
101 static void freeIPHlpApi(void)
103 FreeLibrary(hLibrary);
106 /* replacement for inet_ntoa */
107 static const char *ntoa( DWORD ip )
109 static char buffer[40];
112 sprintf( buffer, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff );
117 still-to-be-tested 98-only functions:
118 GetUniDirectionalAdapterInfo
120 static void testWin98OnlyFunctions(void)
124 static void testGetNumberOfInterfaces(void)
126 if (pGetNumberOfInterfaces) {
127 DWORD apiReturn, numInterfaces;
129 /* Crashes on Vista */
131 apiReturn = pGetNumberOfInterfaces(NULL);
132 if (apiReturn == ERROR_NOT_SUPPORTED)
134 ok(apiReturn == ERROR_INVALID_PARAMETER,
135 "GetNumberOfInterfaces(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
139 apiReturn = pGetNumberOfInterfaces(&numInterfaces);
140 if (apiReturn == ERROR_NOT_SUPPORTED) {
141 skip("GetNumberOfInterfaces is not supported\n");
144 ok(apiReturn == NO_ERROR,
145 "GetNumberOfInterfaces returned %d, expected 0\n", apiReturn);
149 static void testGetIfEntry(DWORD index)
155 memset(&row, 0, sizeof(row));
156 apiReturn = pGetIfEntry(NULL);
157 if (apiReturn == ERROR_NOT_SUPPORTED) {
158 skip("GetIfEntry is not supported\n");
161 ok(apiReturn == ERROR_INVALID_PARAMETER,
162 "GetIfEntry(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
164 row.dwIndex = -1; /* hope that's always bogus! */
165 apiReturn = pGetIfEntry(&row);
166 ok(apiReturn == ERROR_INVALID_DATA ||
167 apiReturn == ERROR_FILE_NOT_FOUND /* Vista */,
168 "GetIfEntry(bogus row) returned %d, expected ERROR_INVALID_DATA or ERROR_FILE_NOT_FOUND\n",
171 apiReturn = pGetIfEntry(&row);
172 ok(apiReturn == NO_ERROR,
173 "GetIfEntry returned %d, expected NO_ERROR\n", apiReturn);
177 static void testGetIpAddrTable(void)
179 if (pGetIpAddrTable) {
183 apiReturn = pGetIpAddrTable(NULL, NULL, FALSE);
184 if (apiReturn == ERROR_NOT_SUPPORTED) {
185 skip("GetIpAddrTable is not supported\n");
188 ok(apiReturn == ERROR_INVALID_PARAMETER,
189 "GetIpAddrTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
191 apiReturn = pGetIpAddrTable(NULL, &dwSize, FALSE);
192 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
193 "GetIpAddrTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
195 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
196 PMIB_IPADDRTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
198 apiReturn = pGetIpAddrTable(buf, &dwSize, FALSE);
199 ok(apiReturn == NO_ERROR,
200 "GetIpAddrTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
202 if (apiReturn == NO_ERROR && buf->dwNumEntries)
203 testGetIfEntry(buf->table[0].dwIndex);
204 HeapFree(GetProcessHeap(), 0, buf);
209 static void testGetIfTable(void)
215 apiReturn = pGetIfTable(NULL, NULL, FALSE);
216 if (apiReturn == ERROR_NOT_SUPPORTED) {
217 skip("GetIfTable is not supported\n");
220 ok(apiReturn == ERROR_INVALID_PARAMETER,
221 "GetIfTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
223 apiReturn = pGetIfTable(NULL, &dwSize, FALSE);
224 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
225 "GetIfTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
227 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
228 PMIB_IFTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
230 apiReturn = pGetIfTable(buf, &dwSize, FALSE);
231 ok(apiReturn == NO_ERROR,
232 "GetIfTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n\n",
235 if (apiReturn == NO_ERROR && winetest_debug > 1)
238 char name[MAX_INTERFACE_NAME_LEN];
240 trace( "interface table: %u entries\n", buf->dwNumEntries );
241 for (i = 0; i < buf->dwNumEntries; i++)
243 MIB_IFROW *row = &buf->table[i];
244 WideCharToMultiByte( CP_ACP, 0, row->wszName, -1, name, MAX_INTERFACE_NAME_LEN, NULL, NULL );
245 trace( "%u: '%s' type %u mtu %u speed %u phys",
246 row->dwIndex, name, row->dwType, row->dwMtu, row->dwSpeed );
247 for (j = 0; j < row->dwPhysAddrLen; j++)
248 printf( " %02x", row->bPhysAddr[j] );
250 trace( " in: bytes %u upkts %u nupkts %u disc %u err %u unk %u\n",
251 row->dwInOctets, row->dwInUcastPkts, row->dwInNUcastPkts,
252 row->dwInDiscards, row->dwInErrors, row->dwInUnknownProtos );
253 trace( " out: bytes %u upkts %u nupkts %u disc %u err %u\n",
254 row->dwOutOctets, row->dwOutUcastPkts, row->dwOutNUcastPkts,
255 row->dwOutDiscards, row->dwOutErrors );
258 HeapFree(GetProcessHeap(), 0, buf);
263 static void testGetIpForwardTable(void)
265 if (pGetIpForwardTable) {
269 apiReturn = pGetIpForwardTable(NULL, NULL, FALSE);
270 if (apiReturn == ERROR_NOT_SUPPORTED) {
271 skip("GetIpForwardTable is not supported\n");
274 ok(apiReturn == ERROR_INVALID_PARAMETER,
275 "GetIpForwardTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
277 apiReturn = pGetIpForwardTable(NULL, &dwSize, FALSE);
278 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
279 "GetIpForwardTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
281 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
282 PMIB_IPFORWARDTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
284 apiReturn = pGetIpForwardTable(buf, &dwSize, FALSE);
285 ok(apiReturn == NO_ERROR,
286 "GetIpForwardTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
289 if (apiReturn == NO_ERROR && winetest_debug > 1)
293 trace( "IP forward table: %u entries\n", buf->dwNumEntries );
294 for (i = 0; i < buf->dwNumEntries; i++)
297 sprintf( buffer, "dest %s", ntoa( buf->table[i].dwForwardDest ));
298 sprintf( buffer + strlen(buffer), " mask %s", ntoa( buf->table[i].dwForwardMask ));
299 trace( "%u: %s gw %s if %u type %u\n", i, buffer,
300 ntoa( buf->table[i].dwForwardNextHop ),
301 buf->table[i].dwForwardIfIndex, U1(buf->table[i]).dwForwardType );
304 HeapFree(GetProcessHeap(), 0, buf);
309 static void testGetIpNetTable(void)
311 if (pGetIpNetTable) {
315 apiReturn = pGetIpNetTable(NULL, NULL, FALSE);
316 if (apiReturn == ERROR_NOT_SUPPORTED) {
317 skip("GetIpNetTable is not supported\n");
320 ok(apiReturn == ERROR_INVALID_PARAMETER,
321 "GetIpNetTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
323 apiReturn = pGetIpNetTable(NULL, &dwSize, FALSE);
324 ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_INSUFFICIENT_BUFFER,
325 "GetIpNetTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_NO_DATA or ERROR_INSUFFICIENT_BUFFER\n",
327 if (apiReturn == ERROR_NO_DATA)
328 ; /* empty ARP table's okay */
329 else if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
330 PMIB_IPNETTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
332 apiReturn = pGetIpNetTable(buf, &dwSize, FALSE);
333 ok(apiReturn == NO_ERROR ||
334 apiReturn == ERROR_NO_DATA, /* empty ARP table's okay */
335 "GetIpNetTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
338 if (apiReturn == NO_ERROR && winetest_debug > 1)
342 trace( "IP net table: %u entries\n", buf->dwNumEntries );
343 for (i = 0; i < buf->dwNumEntries; i++)
345 trace( "%u: idx %u type %u addr %s phys",
346 i, buf->table[i].dwIndex, U(buf->table[i]).dwType, ntoa( buf->table[i].dwAddr ));
347 for (j = 0; j < buf->table[i].dwPhysAddrLen; j++)
348 printf( " %02x", buf->table[i].bPhysAddr[j] );
352 HeapFree(GetProcessHeap(), 0, buf);
357 static void testGetIcmpStatistics(void)
359 if (pGetIcmpStatistics) {
363 /* Crashes on Vista */
365 apiReturn = pGetIcmpStatistics(NULL);
366 if (apiReturn == ERROR_NOT_SUPPORTED)
368 ok(apiReturn == ERROR_INVALID_PARAMETER,
369 "GetIcmpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
373 apiReturn = pGetIcmpStatistics(&stats);
374 if (apiReturn == ERROR_NOT_SUPPORTED)
376 skip("GetIcmpStatistics is not supported\n");
379 ok(apiReturn == NO_ERROR,
380 "GetIcmpStatistics returned %d, expected NO_ERROR\n", apiReturn);
381 if (apiReturn == NO_ERROR && winetest_debug > 1)
383 trace( "ICMP stats: %8s %8s\n", "in", "out" );
384 trace( " dwMsgs: %8u %8u\n", stats.stats.icmpInStats.dwMsgs, stats.stats.icmpOutStats.dwMsgs );
385 trace( " dwErrors: %8u %8u\n", stats.stats.icmpInStats.dwErrors, stats.stats.icmpOutStats.dwErrors );
386 trace( " dwDestUnreachs: %8u %8u\n", stats.stats.icmpInStats.dwDestUnreachs, stats.stats.icmpOutStats.dwDestUnreachs );
387 trace( " dwTimeExcds: %8u %8u\n", stats.stats.icmpInStats.dwTimeExcds, stats.stats.icmpOutStats.dwTimeExcds );
388 trace( " dwParmProbs: %8u %8u\n", stats.stats.icmpInStats.dwParmProbs, stats.stats.icmpOutStats.dwParmProbs );
389 trace( " dwSrcQuenchs: %8u %8u\n", stats.stats.icmpInStats.dwSrcQuenchs, stats.stats.icmpOutStats.dwSrcQuenchs );
390 trace( " dwRedirects: %8u %8u\n", stats.stats.icmpInStats.dwRedirects, stats.stats.icmpOutStats.dwRedirects );
391 trace( " dwEchos: %8u %8u\n", stats.stats.icmpInStats.dwEchos, stats.stats.icmpOutStats.dwEchos );
392 trace( " dwEchoReps: %8u %8u\n", stats.stats.icmpInStats.dwEchoReps, stats.stats.icmpOutStats.dwEchoReps );
393 trace( " dwTimestamps: %8u %8u\n", stats.stats.icmpInStats.dwTimestamps, stats.stats.icmpOutStats.dwTimestamps );
394 trace( " dwTimestampReps: %8u %8u\n", stats.stats.icmpInStats.dwTimestampReps, stats.stats.icmpOutStats.dwTimestampReps );
395 trace( " dwAddrMasks: %8u %8u\n", stats.stats.icmpInStats.dwAddrMasks, stats.stats.icmpOutStats.dwAddrMasks );
396 trace( " dwAddrMaskReps: %8u %8u\n", stats.stats.icmpInStats.dwAddrMaskReps, stats.stats.icmpOutStats.dwAddrMaskReps );
401 static void testGetIpStatistics(void)
403 if (pGetIpStatistics) {
407 apiReturn = pGetIpStatistics(NULL);
408 if (apiReturn == ERROR_NOT_SUPPORTED) {
409 skip("GetIpStatistics is not supported\n");
412 ok(apiReturn == ERROR_INVALID_PARAMETER,
413 "GetIpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
415 apiReturn = pGetIpStatistics(&stats);
416 ok(apiReturn == NO_ERROR,
417 "GetIpStatistics returned %d, expected NO_ERROR\n", apiReturn);
418 if (apiReturn == NO_ERROR && winetest_debug > 1)
420 trace( "IP stats:\n" );
421 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
422 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
423 trace( " dwInReceives: %u\n", stats.dwInReceives );
424 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
425 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
426 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
427 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
428 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
429 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
430 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
431 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
432 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
433 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
434 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
435 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
436 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
437 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
438 trace( " dwFragOks: %u\n", stats.dwFragOks );
439 trace( " dwFragFails: %u\n", stats.dwFragFails );
440 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
441 trace( " dwNumIf: %u\n", stats.dwNumIf );
442 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
443 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
448 static void testGetTcpStatistics(void)
450 if (pGetTcpStatistics) {
454 apiReturn = pGetTcpStatistics(NULL);
455 if (apiReturn == ERROR_NOT_SUPPORTED) {
456 skip("GetTcpStatistics is not supported\n");
459 ok(apiReturn == ERROR_INVALID_PARAMETER,
460 "GetTcpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
462 apiReturn = pGetTcpStatistics(&stats);
463 ok(apiReturn == NO_ERROR,
464 "GetTcpStatistics returned %d, expected NO_ERROR\n", apiReturn);
465 if (apiReturn == NO_ERROR && winetest_debug > 1)
467 trace( "TCP stats:\n" );
468 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
469 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
470 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
471 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
472 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
473 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
474 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
475 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
476 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
477 trace( " dwInSegs: %u\n", stats.dwInSegs );
478 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
479 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
480 trace( " dwInErrs: %u\n", stats.dwInErrs );
481 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
482 trace( " dwNumConns: %u\n", stats.dwNumConns );
487 static void testGetUdpStatistics(void)
489 if (pGetUdpStatistics) {
493 apiReturn = pGetUdpStatistics(NULL);
494 if (apiReturn == ERROR_NOT_SUPPORTED) {
495 skip("GetUdpStatistics is not supported\n");
498 ok(apiReturn == ERROR_INVALID_PARAMETER,
499 "GetUdpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
501 apiReturn = pGetUdpStatistics(&stats);
502 ok(apiReturn == NO_ERROR,
503 "GetUdpStatistics returned %d, expected NO_ERROR\n", apiReturn);
504 if (apiReturn == NO_ERROR && winetest_debug > 1)
506 trace( "UDP stats:\n" );
507 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
508 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
509 trace( " dwInErrors: %u\n", stats.dwInErrors );
510 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
511 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
516 static void testGetTcpTable(void)
522 apiReturn = pGetTcpTable(NULL, &dwSize, FALSE);
523 if (apiReturn == ERROR_NOT_SUPPORTED) {
524 skip("GetTcpTable is not supported\n");
527 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER ||
528 broken(apiReturn == ERROR_NO_DATA), /* win95 */
529 "GetTcpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
531 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
532 PMIB_TCPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
534 apiReturn = pGetTcpTable(buf, &dwSize, FALSE);
535 ok(apiReturn == NO_ERROR,
536 "GetTcpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
539 if (apiReturn == NO_ERROR && winetest_debug > 1)
542 trace( "TCP table: %u entries\n", buf->dwNumEntries );
543 for (i = 0; i < buf->dwNumEntries; i++)
546 sprintf( buffer, "local %s:%u",
547 ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) );
548 trace( "%u: %s remote %s:%u state %u\n",
549 i, buffer, ntoa( buf->table[i].dwRemoteAddr ),
550 ntohs(buf->table[i].dwRemotePort), U(buf->table[i]).dwState );
553 HeapFree(GetProcessHeap(), 0, buf);
558 static void testGetUdpTable(void)
564 apiReturn = pGetUdpTable(NULL, &dwSize, FALSE);
565 if (apiReturn == ERROR_NOT_SUPPORTED) {
566 skip("GetUdpTable is not supported\n");
569 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
570 "GetUdpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
572 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
573 PMIB_UDPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
575 apiReturn = pGetUdpTable(buf, &dwSize, FALSE);
576 ok(apiReturn == NO_ERROR,
577 "GetUdpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
580 if (apiReturn == NO_ERROR && winetest_debug > 1)
583 trace( "UDP table: %u entries\n", buf->dwNumEntries );
584 for (i = 0; i < buf->dwNumEntries; i++)
585 trace( "%u: %s:%u\n",
586 i, ntoa( buf->table[i].dwLocalAddr ), ntohs(buf->table[i].dwLocalPort) );
588 HeapFree(GetProcessHeap(), 0, buf);
593 static void testSetTcpEntry(void)
598 memset(&row, 0, sizeof(row));
599 if(0) /* This test crashes in OS >= VISTA */
601 ret = pSetTcpEntry(NULL);
602 ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
605 ret = pSetTcpEntry(&row);
606 todo_wine ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
608 U(row).dwState = MIB_TCP_STATE_DELETE_TCB;
609 ret = pSetTcpEntry(&row);
610 todo_wine ok( ret == ERROR_MR_MID_NOT_FOUND || broken(ret == ERROR_INVALID_PARAMETER),
611 "got %u, expected %u\n", ret, ERROR_MR_MID_NOT_FOUND);
615 still-to-be-tested NT4-onward functions:
628 static void testWinNT4Functions(void)
630 testGetNumberOfInterfaces();
631 testGetIpAddrTable();
633 testGetIpForwardTable();
635 testGetIcmpStatistics();
636 testGetIpStatistics();
637 testGetTcpStatistics();
638 testGetUdpStatistics();
644 static void testGetInterfaceInfo(void)
646 if (pGetInterfaceInfo) {
650 apiReturn = pGetInterfaceInfo(NULL, NULL);
651 if (apiReturn == ERROR_NOT_SUPPORTED) {
652 skip("GetInterfaceInfo is not supported\n");
655 ok(apiReturn == ERROR_INVALID_PARAMETER,
656 "GetInterfaceInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
658 apiReturn = pGetInterfaceInfo(NULL, &len);
659 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
660 "GetInterfaceInfo returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
662 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
663 PIP_INTERFACE_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
665 apiReturn = pGetInterfaceInfo(buf, &len);
666 ok(apiReturn == NO_ERROR,
667 "GetInterfaceInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
669 HeapFree(GetProcessHeap(), 0, buf);
674 static void testGetAdaptersInfo(void)
676 if (pGetAdaptersInfo) {
680 apiReturn = pGetAdaptersInfo(NULL, NULL);
681 if (apiReturn == ERROR_NOT_SUPPORTED) {
682 skip("GetAdaptersInfo is not supported\n");
685 ok(apiReturn == ERROR_INVALID_PARAMETER,
686 "GetAdaptersInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
688 apiReturn = pGetAdaptersInfo(NULL, &len);
689 ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_BUFFER_OVERFLOW,
690 "GetAdaptersInfo returned %d, expected ERROR_NO_DATA or ERROR_BUFFER_OVERFLOW\n",
692 if (apiReturn == ERROR_NO_DATA)
693 ; /* no adapter's, that's okay */
694 else if (apiReturn == ERROR_BUFFER_OVERFLOW) {
695 PIP_ADAPTER_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
697 apiReturn = pGetAdaptersInfo(buf, &len);
698 ok(apiReturn == NO_ERROR,
699 "GetAdaptersInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
701 HeapFree(GetProcessHeap(), 0, buf);
706 static void testGetNetworkParams(void)
708 if (pGetNetworkParams) {
712 apiReturn = pGetNetworkParams(NULL, NULL);
713 if (apiReturn == ERROR_NOT_SUPPORTED) {
714 skip("GetNetworkParams is not supported\n");
717 ok(apiReturn == ERROR_INVALID_PARAMETER,
718 "GetNetworkParams returned %d, expected ERROR_INVALID_PARAMETER\n",
720 apiReturn = pGetNetworkParams(NULL, &len);
721 ok(apiReturn == ERROR_BUFFER_OVERFLOW,
722 "GetNetworkParams returned %d, expected ERROR_BUFFER_OVERFLOW\n",
724 if (apiReturn == ERROR_BUFFER_OVERFLOW) {
725 PFIXED_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
727 apiReturn = pGetNetworkParams(buf, &len);
728 ok(apiReturn == NO_ERROR,
729 "GetNetworkParams(buf, &dwSize) returned %d, expected NO_ERROR\n",
731 HeapFree(GetProcessHeap(), 0, buf);
737 still-to-be-tested 98-onward functions:
743 static DWORD CALLBACK testWin98Functions(void *p)
745 testGetInterfaceInfo();
746 testGetAdaptersInfo();
747 testGetNetworkParams();
751 static void testGetPerAdapterInfo(void)
756 if (!pGetPerAdapterInfo) return;
757 ret = pGetPerAdapterInfo(1, NULL, NULL);
758 if (ret == ERROR_NOT_SUPPORTED) {
759 skip("GetPerAdapterInfo is not supported\n");
762 ok( ret == ERROR_INVALID_PARAMETER, "got %u instead of ERROR_INVALID_PARAMETER\n", ret );
764 ret = pGetPerAdapterInfo(1, NULL, &needed);
765 if (ret == ERROR_NO_DATA) return; /* no such adapter */
766 ok( ret == ERROR_BUFFER_OVERFLOW, "got %u instead of ERROR_BUFFER_OVERFLOW\n", ret );
767 ok( needed != 0xdeadbeef, "needed not set\n" );
768 buffer = HeapAlloc( GetProcessHeap(), 0, needed );
769 ret = pGetPerAdapterInfo(1, buffer, &needed);
770 ok( ret == NO_ERROR, "got %u instead of NO_ERROR\n", ret );
771 HeapFree( GetProcessHeap(), 0, buffer );
774 static void testNotifyAddrChange(void)
777 OVERLAPPED overlapped;
781 if (!pNotifyAddrChange)
783 win_skip("NotifyAddrChange not present\n");
786 if (!pCancelIPChangeNotify)
788 win_skip("CancelIPChangeNotify not present\n");
793 ZeroMemory(&overlapped, sizeof(overlapped));
794 ret = pNotifyAddrChange(&handle, &overlapped);
795 if (ret == ERROR_NOT_SUPPORTED)
797 win_skip("NotifyAddrChange is not supported\n");
800 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
801 ret = GetLastError();
802 todo_wine ok(ret == ERROR_IO_PENDING, "GetLastError returned %d, expected ERROR_IO_PENDING\n", ret);
803 success = pCancelIPChangeNotify(&overlapped);
804 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
806 ZeroMemory(&overlapped, sizeof(overlapped));
807 success = pCancelIPChangeNotify(&overlapped);
808 ok(success == FALSE, "CancelIPChangeNotify returned TRUE, expected FALSE\n");
811 ZeroMemory(&overlapped, sizeof(overlapped));
812 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
813 ret = pNotifyAddrChange(&handle, &overlapped);
814 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
815 todo_wine ok(handle != INVALID_HANDLE_VALUE, "NotifyAddrChange returned invalid file handle\n");
816 success = GetOverlappedResult(handle, &overlapped, &bytes, FALSE);
817 ok(success == FALSE, "GetOverlappedResult returned TRUE, expected FALSE\n");
818 ret = GetLastError();
819 ok(ret == ERROR_IO_INCOMPLETE, "GetLastError returned %d, expected ERROR_IO_INCOMPLETE\n", ret);
820 success = pCancelIPChangeNotify(&overlapped);
821 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
823 if (winetest_interactive)
826 ZeroMemory(&overlapped, sizeof(overlapped));
827 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
828 trace("Testing asynchronous ipv4 address change notification. Please "
829 "change the ipv4 address of one of your network interfaces\n");
830 ret = pNotifyAddrChange(&handle, &overlapped);
831 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
832 success = GetOverlappedResult(handle, &overlapped, &bytes, TRUE);
833 ok(success == TRUE, "GetOverlappedResult returned FALSE, expected TRUE\n");
836 /* test synchronous functionality */
837 if (winetest_interactive)
839 trace("Testing synchronous ipv4 address change notification. Please "
840 "change the ipv4 address of one of your network interfaces\n");
841 ret = pNotifyAddrChange(NULL, NULL);
842 todo_wine ok(ret == NO_ERROR, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
847 still-to-be-tested 2K-onward functions:
855 NotifyRouteChange + CancelIPChangeNotify
859 static void testWin2KFunctions(void)
861 testGetPerAdapterInfo();
862 testNotifyAddrChange();
865 static void test_GetAdaptersAddresses(void)
868 IP_ADAPTER_ADDRESSES *aa, *ptr;
869 IP_ADAPTER_UNICAST_ADDRESS *ua;
871 if (!pGetAdaptersAddresses)
873 win_skip("GetAdaptersAddresses not present\n");
877 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, NULL);
878 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", ret);
880 /* size should be ignored and overwritten if buffer is NULL */
882 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size);
883 ok(ret == ERROR_BUFFER_OVERFLOW, "expected ERROR_BUFFER_OVERFLOW, got %u\n", ret);
884 if (ret != ERROR_BUFFER_OVERFLOW) return;
886 ptr = HeapAlloc(GetProcessHeap(), 0, size);
887 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, ptr, &size);
888 ok(!ret, "expected ERROR_SUCCESS got %u\n", ret);
890 for (aa = ptr; !ret && aa; aa = aa->Next)
892 ok(aa->DnsSuffix != NULL, "DnsSuffix is not a valid pointer\n");
893 ok(aa->Description != NULL, "Description is not a valid pointer\n");
894 ok(aa->FriendlyName != NULL, "FriendlyName is not a valid pointer\n");
896 if (winetest_debug <= 1)
899 trace("Length: %u\n", S(U(*aa)).Length);
900 trace("IfIndex: %u\n", S(U(*aa)).IfIndex);
901 trace("Next: %p\n", aa->Next);
902 trace("AdapterName: %s\n", aa->AdapterName);
903 trace("FirstUnicastAddress: %p\n", aa->FirstUnicastAddress);
904 ua = aa->FirstUnicastAddress;
907 trace("\tLength: %u\n", S(U(*ua)).Length);
908 trace("\tFlags: 0x%08x\n", S(U(*ua)).Flags);
909 trace("\tNext: %p\n", ua->Next);
910 trace("\tAddress.lpSockaddr: %p\n", ua->Address.lpSockaddr);
911 trace("\tAddress.iSockaddrLength: %d\n", ua->Address.iSockaddrLength);
912 trace("\tPrefixOrigin: %u\n", ua->PrefixOrigin);
913 trace("\tSuffixOrigin: %u\n", ua->SuffixOrigin);
914 trace("\tDadState: %u\n", ua->DadState);
915 trace("\tValidLifetime: 0x%08x\n", ua->ValidLifetime);
916 trace("\tPreferredLifetime: 0x%08x\n", ua->PreferredLifetime);
917 trace("\tLeaseLifetime: 0x%08x\n", ua->LeaseLifetime);
921 trace("FirstAnycastAddress: %p\n", aa->FirstAnycastAddress);
922 trace("FirstMulticastAddress: %p\n", aa->FirstMulticastAddress);
923 trace("FirstDnsServerAddress: %p\n", aa->FirstDnsServerAddress);
924 trace("DnsSuffix: %p\n", aa->DnsSuffix);
925 trace("Description: %p\n", aa->Description);
926 trace("FriendlyName: %p\n", aa->FriendlyName);
927 trace("PhysicalAddress: %02x\n", aa->PhysicalAddress[0]);
928 trace("PhysicalAddressLength: %u\n", aa->PhysicalAddressLength);
929 trace("Flags: 0x%08x\n", aa->Flags);
930 trace("Mtu: %u\n", aa->Mtu);
931 trace("IfType: %u\n", aa->IfType);
932 trace("OperStatus: %u\n", aa->OperStatus);
935 HeapFree(GetProcessHeap(), 0, ptr);
938 static void test_GetExtendedTcpTable(void)
942 MIB_TCPTABLE_OWNER_PID *table_pid;
944 if (!pGetExtendedTcpTable)
946 win_skip("GetExtendedTcpTable not available\n");
949 ret = pGetExtendedTcpTable( NULL, NULL, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
950 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
953 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
954 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
956 table = HeapAlloc( GetProcessHeap(), 0, size );
957 ret = pGetExtendedTcpTable( table, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
958 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
959 HeapFree( GetProcessHeap(), 0, table );
962 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
963 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
965 table_pid = HeapAlloc( GetProcessHeap(), 0, size );
966 ret = pGetExtendedTcpTable( table_pid, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
967 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
968 HeapFree( GetProcessHeap(), 0, table_pid );
978 testWin98OnlyFunctions();
979 testWinNT4Functions();
981 /* run testGetXXXX in two threads at once to make sure we don't crash in that case */
982 thread = CreateThread(NULL, 0, testWin98Functions, NULL, 0, NULL);
983 testWin98Functions(NULL);
984 WaitForSingleObject(thread, INFINITE);
986 testWin2KFunctions();
987 test_GetAdaptersAddresses();
988 test_GetExtendedTcpTable();