Release 1.6-rc2.
[wine/testsucceed.git] / dlls / iphlpapi / tests / iphlpapi.c
blob26bf26ef8cafc62f12209a73bb4240dc300077a1
1 /*
2 * iphlpapi dll test
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.
37 #include <stdarg.h>
38 #include "winsock2.h"
39 #include "windef.h"
40 #include "winbase.h"
41 #include "iphlpapi.h"
42 #include "iprtrmib.h"
43 #include "wine/test.h"
44 #include <stdio.h>
45 #include <stdlib.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");
80 if (hLibrary) {
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];
121 ip = htonl(ip);
122 sprintf( buffer, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff );
123 return buffer;
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 */
140 if (0) {
141 apiReturn = pGetNumberOfInterfaces(NULL);
142 if (apiReturn == ERROR_NOT_SUPPORTED)
143 return;
144 ok(apiReturn == ERROR_INVALID_PARAMETER,
145 "GetNumberOfInterfaces(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
146 apiReturn);
149 apiReturn = pGetNumberOfInterfaces(&numInterfaces);
150 if (apiReturn == ERROR_NOT_SUPPORTED) {
151 skip("GetNumberOfInterfaces is not supported\n");
152 return;
154 ok(apiReturn == NO_ERROR,
155 "GetNumberOfInterfaces returned %d, expected 0\n", apiReturn);
159 static void testGetIfEntry(DWORD index)
161 if (pGetIfEntry) {
162 DWORD apiReturn;
163 MIB_IFROW row;
165 memset(&row, 0, sizeof(row));
166 apiReturn = pGetIfEntry(NULL);
167 if (apiReturn == ERROR_NOT_SUPPORTED) {
168 skip("GetIfEntry is not supported\n");
169 return;
171 ok(apiReturn == ERROR_INVALID_PARAMETER,
172 "GetIfEntry(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
173 apiReturn);
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",
179 apiReturn);
180 row.dwIndex = index;
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) {
190 DWORD apiReturn;
191 ULONG dwSize = 0;
193 apiReturn = pGetIpAddrTable(NULL, NULL, FALSE);
194 if (apiReturn == ERROR_NOT_SUPPORTED) {
195 skip("GetIpAddrTable is not supported\n");
196 return;
198 ok(apiReturn == ERROR_INVALID_PARAMETER,
199 "GetIpAddrTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
200 apiReturn);
201 apiReturn = pGetIpAddrTable(NULL, &dwSize, FALSE);
202 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
203 "GetIpAddrTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
204 apiReturn);
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",
211 apiReturn);
212 if (apiReturn == NO_ERROR && buf->dwNumEntries)
213 testGetIfEntry(buf->table[0].dwIndex);
214 HeapFree(GetProcessHeap(), 0, buf);
219 static void testGetIfTable(void)
221 if (pGetIfTable) {
222 DWORD apiReturn;
223 ULONG dwSize = 0;
225 apiReturn = pGetIfTable(NULL, NULL, FALSE);
226 if (apiReturn == ERROR_NOT_SUPPORTED) {
227 skip("GetIfTable is not supported\n");
228 return;
230 ok(apiReturn == ERROR_INVALID_PARAMETER,
231 "GetIfTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
232 apiReturn);
233 apiReturn = pGetIfTable(NULL, &dwSize, FALSE);
234 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
235 "GetIfTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
236 apiReturn);
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",
243 apiReturn);
245 if (apiReturn == NO_ERROR && winetest_debug > 1)
247 DWORD i, j;
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] );
259 printf( "\n" );
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) {
276 DWORD apiReturn;
277 ULONG dwSize = 0;
279 apiReturn = pGetIpForwardTable(NULL, NULL, FALSE);
280 if (apiReturn == ERROR_NOT_SUPPORTED) {
281 skip("GetIpForwardTable is not supported\n");
282 return;
284 ok(apiReturn == ERROR_INVALID_PARAMETER,
285 "GetIpForwardTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
286 apiReturn);
287 apiReturn = pGetIpForwardTable(NULL, &dwSize, FALSE);
288 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
289 "GetIpForwardTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
290 apiReturn);
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",
297 apiReturn);
299 if (apiReturn == NO_ERROR && winetest_debug > 1)
301 DWORD i;
303 trace( "IP forward table: %u entries\n", buf->dwNumEntries );
304 for (i = 0; i < buf->dwNumEntries; i++)
306 char buffer[40];
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) {
322 DWORD apiReturn;
323 ULONG dwSize = 0;
325 apiReturn = pGetIpNetTable(NULL, NULL, FALSE);
326 if (apiReturn == ERROR_NOT_SUPPORTED) {
327 skip("GetIpNetTable is not supported\n");
328 return;
330 ok(apiReturn == ERROR_INVALID_PARAMETER,
331 "GetIpNetTable(NULL, NULL, FALSE) returned %d, expected ERROR_INVALID_PARAMETER\n",
332 apiReturn);
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",
336 apiReturn);
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",
346 apiReturn);
348 if (apiReturn == NO_ERROR && winetest_debug > 1)
350 DWORD i, j;
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] );
359 printf( "\n" );
362 HeapFree(GetProcessHeap(), 0, buf);
367 static void testGetIcmpStatistics(void)
369 if (pGetIcmpStatistics) {
370 DWORD apiReturn;
371 MIB_ICMP stats;
373 /* Crashes on Vista */
374 if (0) {
375 apiReturn = pGetIcmpStatistics(NULL);
376 if (apiReturn == ERROR_NOT_SUPPORTED)
377 return;
378 ok(apiReturn == ERROR_INVALID_PARAMETER,
379 "GetIcmpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
380 apiReturn);
383 apiReturn = pGetIcmpStatistics(&stats);
384 if (apiReturn == ERROR_NOT_SUPPORTED)
386 skip("GetIcmpStatistics is not supported\n");
387 return;
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) {
414 DWORD apiReturn;
415 MIB_IPSTATS stats;
417 apiReturn = pGetIpStatistics(NULL);
418 if (apiReturn == ERROR_NOT_SUPPORTED) {
419 skip("GetIpStatistics is not supported\n");
420 return;
422 ok(apiReturn == ERROR_INVALID_PARAMETER,
423 "GetIpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
424 apiReturn);
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) {
461 DWORD apiReturn;
462 MIB_TCPSTATS stats;
464 apiReturn = pGetTcpStatistics(NULL);
465 if (apiReturn == ERROR_NOT_SUPPORTED) {
466 skip("GetTcpStatistics is not supported\n");
467 return;
469 ok(apiReturn == ERROR_INVALID_PARAMETER,
470 "GetTcpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
471 apiReturn);
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) {
500 DWORD apiReturn;
501 MIB_UDPSTATS stats;
503 apiReturn = pGetUdpStatistics(NULL);
504 if (apiReturn == ERROR_NOT_SUPPORTED) {
505 skip("GetUdpStatistics is not supported\n");
506 return;
508 ok(apiReturn == ERROR_INVALID_PARAMETER,
509 "GetUdpStatistics(NULL) returned %d, expected ERROR_INVALID_PARAMETER\n",
510 apiReturn);
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)
528 DWORD apiReturn;
529 MIB_ICMP_EX stats;
531 if (!pGetIcmpStatisticsEx)
533 win_skip( "GetIcmpStatisticsEx not available\n" );
534 return;
537 /* Crashes on Vista */
538 if (1) {
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_BAN);
545 ok(apiReturn == ERROR_INVALID_PARAMETER,
546 "GetIcmpStatisticsEx(&stats, AF_BAN) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
548 apiReturn = pGetIcmpStatisticsEx(&stats, AF_INET);
549 ok(apiReturn == NO_ERROR, "GetIcmpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
550 if (apiReturn == NO_ERROR && winetest_debug > 1)
552 INT i;
553 trace( "ICMP IPv4 Ex stats: %8s %8s\n", "in", "out" );
554 trace( " dwMsgs: %8u %8u\n", stats.icmpInStats.dwMsgs, stats.icmpOutStats.dwMsgs );
555 trace( " dwErrors: %8u %8u\n", stats.icmpInStats.dwErrors, stats.icmpOutStats.dwErrors );
556 for (i = 0; i < 256; i++)
557 trace( " rgdwTypeCount[%3i]: %8u %8u\n", i, stats.icmpInStats.rgdwTypeCount[i], stats.icmpOutStats.rgdwTypeCount[i] );
560 apiReturn = pGetIcmpStatisticsEx(&stats, AF_INET6);
561 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
562 "GetIcmpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
563 if (apiReturn == NO_ERROR && winetest_debug > 1)
565 INT i;
566 trace( "ICMP IPv6 Ex stats: %8s %8s\n", "in", "out" );
567 trace( " dwMsgs: %8u %8u\n", stats.icmpInStats.dwMsgs, stats.icmpOutStats.dwMsgs );
568 trace( " dwErrors: %8u %8u\n", stats.icmpInStats.dwErrors, stats.icmpOutStats.dwErrors );
569 for (i = 0; i < 256; i++)
570 trace( " rgdwTypeCount[%3i]: %8u %8u\n", i, stats.icmpInStats.rgdwTypeCount[i], stats.icmpOutStats.rgdwTypeCount[i] );
574 static void testGetIpStatisticsEx(void)
576 DWORD apiReturn;
577 MIB_IPSTATS stats;
579 if (!pGetIpStatisticsEx)
581 win_skip( "GetIpStatisticsEx not available\n" );
582 return;
585 apiReturn = pGetIpStatisticsEx(NULL, AF_INET);
586 ok(apiReturn == ERROR_INVALID_PARAMETER,
587 "GetIpStatisticsEx(NULL, AF_INET) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
589 apiReturn = pGetIpStatisticsEx(&stats, AF_BAN);
590 ok(apiReturn == ERROR_INVALID_PARAMETER,
591 "GetIpStatisticsEx(&stats, AF_BAN) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
593 apiReturn = pGetIpStatisticsEx(&stats, AF_INET);
594 ok(apiReturn == NO_ERROR, "GetIpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
595 if (apiReturn == NO_ERROR && winetest_debug > 1)
597 trace( "IP IPv4 Ex stats:\n" );
598 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
599 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
600 trace( " dwInReceives: %u\n", stats.dwInReceives );
601 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
602 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
603 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
604 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
605 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
606 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
607 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
608 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
609 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
610 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
611 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
612 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
613 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
614 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
615 trace( " dwFragOks: %u\n", stats.dwFragOks );
616 trace( " dwFragFails: %u\n", stats.dwFragFails );
617 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
618 trace( " dwNumIf: %u\n", stats.dwNumIf );
619 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
620 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
623 apiReturn = pGetIpStatisticsEx(&stats, AF_INET6);
624 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
625 "GetIpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
626 if (apiReturn == NO_ERROR && winetest_debug > 1)
628 trace( "IP IPv6 Ex stats:\n" );
629 trace( " dwForwarding: %u\n", U(stats).dwForwarding );
630 trace( " dwDefaultTTL: %u\n", stats.dwDefaultTTL );
631 trace( " dwInReceives: %u\n", stats.dwInReceives );
632 trace( " dwInHdrErrors: %u\n", stats.dwInHdrErrors );
633 trace( " dwInAddrErrors: %u\n", stats.dwInAddrErrors );
634 trace( " dwForwDatagrams: %u\n", stats.dwForwDatagrams );
635 trace( " dwInUnknownProtos: %u\n", stats.dwInUnknownProtos );
636 trace( " dwInDiscards: %u\n", stats.dwInDiscards );
637 trace( " dwInDelivers: %u\n", stats.dwInDelivers );
638 trace( " dwOutRequests: %u\n", stats.dwOutRequests );
639 trace( " dwRoutingDiscards: %u\n", stats.dwRoutingDiscards );
640 trace( " dwOutDiscards: %u\n", stats.dwOutDiscards );
641 trace( " dwOutNoRoutes: %u\n", stats.dwOutNoRoutes );
642 trace( " dwReasmTimeout: %u\n", stats.dwReasmTimeout );
643 trace( " dwReasmReqds: %u\n", stats.dwReasmReqds );
644 trace( " dwReasmOks: %u\n", stats.dwReasmOks );
645 trace( " dwReasmFails: %u\n", stats.dwReasmFails );
646 trace( " dwFragOks: %u\n", stats.dwFragOks );
647 trace( " dwFragFails: %u\n", stats.dwFragFails );
648 trace( " dwFragCreates: %u\n", stats.dwFragCreates );
649 trace( " dwNumIf: %u\n", stats.dwNumIf );
650 trace( " dwNumAddr: %u\n", stats.dwNumAddr );
651 trace( " dwNumRoutes: %u\n", stats.dwNumRoutes );
655 static void testGetTcpStatisticsEx(void)
657 DWORD apiReturn;
658 MIB_TCPSTATS stats;
660 if (!pGetTcpStatisticsEx)
662 win_skip( "GetTcpStatisticsEx not available\n" );
663 return;
666 apiReturn = pGetTcpStatisticsEx(NULL, AF_INET);
667 ok(apiReturn == ERROR_INVALID_PARAMETER,
668 "GetTcpStatisticsEx(NULL, AF_INET); returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
670 apiReturn = pGetTcpStatisticsEx(&stats, AF_BAN);
671 ok(apiReturn == ERROR_INVALID_PARAMETER || apiReturn == ERROR_NOT_SUPPORTED,
672 "GetTcpStatisticsEx(&stats, AF_BAN) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
674 apiReturn = pGetTcpStatisticsEx(&stats, AF_INET);
675 ok(apiReturn == NO_ERROR, "GetTcpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
676 if (apiReturn == NO_ERROR && winetest_debug > 1)
678 trace( "TCP IPv4 Ex stats:\n" );
679 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
680 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
681 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
682 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
683 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
684 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
685 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
686 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
687 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
688 trace( " dwInSegs: %u\n", stats.dwInSegs );
689 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
690 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
691 trace( " dwInErrs: %u\n", stats.dwInErrs );
692 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
693 trace( " dwNumConns: %u\n", stats.dwNumConns );
696 apiReturn = pGetTcpStatisticsEx(&stats, AF_INET6);
697 todo_wine ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
698 "GetTcpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
699 if (apiReturn == NO_ERROR && winetest_debug > 1)
701 trace( "TCP IPv6 Ex stats:\n" );
702 trace( " dwRtoAlgorithm: %u\n", U(stats).dwRtoAlgorithm );
703 trace( " dwRtoMin: %u\n", stats.dwRtoMin );
704 trace( " dwRtoMax: %u\n", stats.dwRtoMax );
705 trace( " dwMaxConn: %u\n", stats.dwMaxConn );
706 trace( " dwActiveOpens: %u\n", stats.dwActiveOpens );
707 trace( " dwPassiveOpens: %u\n", stats.dwPassiveOpens );
708 trace( " dwAttemptFails: %u\n", stats.dwAttemptFails );
709 trace( " dwEstabResets: %u\n", stats.dwEstabResets );
710 trace( " dwCurrEstab: %u\n", stats.dwCurrEstab );
711 trace( " dwInSegs: %u\n", stats.dwInSegs );
712 trace( " dwOutSegs: %u\n", stats.dwOutSegs );
713 trace( " dwRetransSegs: %u\n", stats.dwRetransSegs );
714 trace( " dwInErrs: %u\n", stats.dwInErrs );
715 trace( " dwOutRsts: %u\n", stats.dwOutRsts );
716 trace( " dwNumConns: %u\n", stats.dwNumConns );
720 static void testGetUdpStatisticsEx(void)
722 DWORD apiReturn;
723 MIB_UDPSTATS stats;
725 if (!pGetUdpStatisticsEx)
727 win_skip( "GetUdpStatisticsEx not available\n" );
728 return;
731 apiReturn = pGetUdpStatisticsEx(NULL, AF_INET);
732 ok(apiReturn == ERROR_INVALID_PARAMETER,
733 "GetUdpStatisticsEx(NULL, AF_INET); returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
735 apiReturn = pGetUdpStatisticsEx(&stats, AF_BAN);
736 ok(apiReturn == ERROR_INVALID_PARAMETER || apiReturn == ERROR_NOT_SUPPORTED,
737 "GetUdpStatisticsEx(&stats, AF_BAN) returned %d, expected ERROR_INVALID_PARAMETER\n", apiReturn);
739 apiReturn = pGetUdpStatisticsEx(&stats, AF_INET);
740 ok(apiReturn == NO_ERROR, "GetUdpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
741 if (apiReturn == NO_ERROR && winetest_debug > 1)
743 trace( "UDP IPv4 Ex stats:\n" );
744 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
745 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
746 trace( " dwInErrors: %u\n", stats.dwInErrors );
747 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
748 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
751 apiReturn = pGetUdpStatisticsEx(&stats, AF_INET6);
752 ok(apiReturn == NO_ERROR || broken(apiReturn == ERROR_NOT_SUPPORTED),
753 "GetUdpStatisticsEx returned %d, expected NO_ERROR\n", apiReturn);
754 if (apiReturn == NO_ERROR && winetest_debug > 1)
756 trace( "UDP IPv6 Ex stats:\n" );
757 trace( " dwInDatagrams: %u\n", stats.dwInDatagrams );
758 trace( " dwNoPorts: %u\n", stats.dwNoPorts );
759 trace( " dwInErrors: %u\n", stats.dwInErrors );
760 trace( " dwOutDatagrams: %u\n", stats.dwOutDatagrams );
761 trace( " dwNumAddrs: %u\n", stats.dwNumAddrs );
765 static void testGetTcpTable(void)
767 if (pGetTcpTable) {
768 DWORD apiReturn;
769 ULONG dwSize = 0;
771 apiReturn = pGetTcpTable(NULL, &dwSize, FALSE);
772 if (apiReturn == ERROR_NOT_SUPPORTED) {
773 skip("GetTcpTable is not supported\n");
774 return;
776 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER ||
777 broken(apiReturn == ERROR_NO_DATA), /* win95 */
778 "GetTcpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
779 apiReturn);
780 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
781 PMIB_TCPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
783 apiReturn = pGetTcpTable(buf, &dwSize, FALSE);
784 ok(apiReturn == NO_ERROR,
785 "GetTcpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
786 apiReturn);
788 if (apiReturn == NO_ERROR && winetest_debug > 1)
790 DWORD i;
791 trace( "TCP table: %u entries\n", buf->dwNumEntries );
792 for (i = 0; i < buf->dwNumEntries; i++)
794 char buffer[40];
795 sprintf( buffer, "local %s:%u",
796 ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) );
797 trace( "%u: %s remote %s:%u state %u\n",
798 i, buffer, ntoa( buf->table[i].dwRemoteAddr ),
799 ntohs(buf->table[i].dwRemotePort), U(buf->table[i]).dwState );
802 HeapFree(GetProcessHeap(), 0, buf);
807 static void testGetUdpTable(void)
809 if (pGetUdpTable) {
810 DWORD apiReturn;
811 ULONG dwSize = 0;
813 apiReturn = pGetUdpTable(NULL, &dwSize, FALSE);
814 if (apiReturn == ERROR_NOT_SUPPORTED) {
815 skip("GetUdpTable is not supported\n");
816 return;
818 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
819 "GetUdpTable(NULL, &dwSize, FALSE) returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
820 apiReturn);
821 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
822 PMIB_UDPTABLE buf = HeapAlloc(GetProcessHeap(), 0, dwSize);
824 apiReturn = pGetUdpTable(buf, &dwSize, FALSE);
825 ok(apiReturn == NO_ERROR,
826 "GetUdpTable(buf, &dwSize, FALSE) returned %d, expected NO_ERROR\n",
827 apiReturn);
829 if (apiReturn == NO_ERROR && winetest_debug > 1)
831 DWORD i;
832 trace( "UDP table: %u entries\n", buf->dwNumEntries );
833 for (i = 0; i < buf->dwNumEntries; i++)
834 trace( "%u: %s:%u\n",
835 i, ntoa( buf->table[i].dwLocalAddr ), ntohs(buf->table[i].dwLocalPort) );
837 HeapFree(GetProcessHeap(), 0, buf);
842 static void testSetTcpEntry(void)
844 DWORD ret;
845 MIB_TCPROW row;
847 memset(&row, 0, sizeof(row));
848 if(0) /* This test crashes in OS >= VISTA */
850 ret = pSetTcpEntry(NULL);
851 ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
854 ret = pSetTcpEntry(&row);
855 todo_wine ok( ret == ERROR_INVALID_PARAMETER, "got %u, expected %u\n", ret, ERROR_INVALID_PARAMETER);
857 U(row).dwState = MIB_TCP_STATE_DELETE_TCB;
858 ret = pSetTcpEntry(&row);
859 todo_wine ok( ret == ERROR_MR_MID_NOT_FOUND || broken(ret == ERROR_INVALID_PARAMETER),
860 "got %u, expected %u\n", ret, ERROR_MR_MID_NOT_FOUND);
864 still-to-be-tested NT4-onward functions:
865 CreateIpForwardEntry
866 DeleteIpForwardEntry
867 CreateIpNetEntry
868 DeleteIpNetEntry
869 GetFriendlyIfIndex
870 GetRTTAndHopCount
871 SetIfEntry
872 SetIpForwardEntry
873 SetIpNetEntry
874 SetIpStatistics
875 SetIpTTL
877 static void testWinNT4Functions(void)
879 testGetNumberOfInterfaces();
880 testGetIpAddrTable();
881 testGetIfTable();
882 testGetIpForwardTable();
883 testGetIpNetTable();
884 testGetIcmpStatistics();
885 testGetIpStatistics();
886 testGetTcpStatistics();
887 testGetUdpStatistics();
888 testGetIcmpStatisticsEx();
889 testGetIpStatisticsEx();
890 testGetTcpStatisticsEx();
891 testGetUdpStatisticsEx();
892 testGetTcpTable();
893 testGetUdpTable();
894 testSetTcpEntry();
897 static void testGetInterfaceInfo(void)
899 if (pGetInterfaceInfo) {
900 DWORD apiReturn;
901 ULONG len = 0;
903 apiReturn = pGetInterfaceInfo(NULL, NULL);
904 if (apiReturn == ERROR_NOT_SUPPORTED) {
905 skip("GetInterfaceInfo is not supported\n");
906 return;
908 ok(apiReturn == ERROR_INVALID_PARAMETER,
909 "GetInterfaceInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
910 apiReturn);
911 apiReturn = pGetInterfaceInfo(NULL, &len);
912 ok(apiReturn == ERROR_INSUFFICIENT_BUFFER,
913 "GetInterfaceInfo returned %d, expected ERROR_INSUFFICIENT_BUFFER\n",
914 apiReturn);
915 if (apiReturn == ERROR_INSUFFICIENT_BUFFER) {
916 PIP_INTERFACE_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
918 apiReturn = pGetInterfaceInfo(buf, &len);
919 ok(apiReturn == NO_ERROR,
920 "GetInterfaceInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
921 apiReturn);
922 HeapFree(GetProcessHeap(), 0, buf);
927 static void testGetAdaptersInfo(void)
929 if (pGetAdaptersInfo) {
930 DWORD apiReturn;
931 ULONG len = 0;
933 apiReturn = pGetAdaptersInfo(NULL, NULL);
934 if (apiReturn == ERROR_NOT_SUPPORTED) {
935 skip("GetAdaptersInfo is not supported\n");
936 return;
938 ok(apiReturn == ERROR_INVALID_PARAMETER,
939 "GetAdaptersInfo returned %d, expected ERROR_INVALID_PARAMETER\n",
940 apiReturn);
941 apiReturn = pGetAdaptersInfo(NULL, &len);
942 ok(apiReturn == ERROR_NO_DATA || apiReturn == ERROR_BUFFER_OVERFLOW,
943 "GetAdaptersInfo returned %d, expected ERROR_NO_DATA or ERROR_BUFFER_OVERFLOW\n",
944 apiReturn);
945 if (apiReturn == ERROR_NO_DATA)
946 ; /* no adapter's, that's okay */
947 else if (apiReturn == ERROR_BUFFER_OVERFLOW) {
948 PIP_ADAPTER_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
950 apiReturn = pGetAdaptersInfo(buf, &len);
951 ok(apiReturn == NO_ERROR,
952 "GetAdaptersInfo(buf, &dwSize) returned %d, expected NO_ERROR\n",
953 apiReturn);
954 HeapFree(GetProcessHeap(), 0, buf);
959 static void testGetNetworkParams(void)
961 if (pGetNetworkParams) {
962 DWORD apiReturn;
963 ULONG len = 0;
965 apiReturn = pGetNetworkParams(NULL, NULL);
966 if (apiReturn == ERROR_NOT_SUPPORTED) {
967 skip("GetNetworkParams is not supported\n");
968 return;
970 ok(apiReturn == ERROR_INVALID_PARAMETER,
971 "GetNetworkParams returned %d, expected ERROR_INVALID_PARAMETER\n",
972 apiReturn);
973 apiReturn = pGetNetworkParams(NULL, &len);
974 ok(apiReturn == ERROR_BUFFER_OVERFLOW,
975 "GetNetworkParams returned %d, expected ERROR_BUFFER_OVERFLOW\n",
976 apiReturn);
977 if (apiReturn == ERROR_BUFFER_OVERFLOW) {
978 PFIXED_INFO buf = HeapAlloc(GetProcessHeap(), 0, len);
980 apiReturn = pGetNetworkParams(buf, &len);
981 ok(apiReturn == NO_ERROR,
982 "GetNetworkParams(buf, &dwSize) returned %d, expected NO_ERROR\n",
983 apiReturn);
984 HeapFree(GetProcessHeap(), 0, buf);
990 still-to-be-tested 98-onward functions:
991 GetBestInterface
992 GetBestRoute
993 IpReleaseAddress
994 IpRenewAddress
996 static DWORD CALLBACK testWin98Functions(void *p)
998 testGetInterfaceInfo();
999 testGetAdaptersInfo();
1000 testGetNetworkParams();
1001 return 0;
1004 static void testGetPerAdapterInfo(void)
1006 DWORD ret, needed;
1007 void *buffer;
1009 if (!pGetPerAdapterInfo) return;
1010 ret = pGetPerAdapterInfo(1, NULL, NULL);
1011 if (ret == ERROR_NOT_SUPPORTED) {
1012 skip("GetPerAdapterInfo is not supported\n");
1013 return;
1015 ok( ret == ERROR_INVALID_PARAMETER, "got %u instead of ERROR_INVALID_PARAMETER\n", ret );
1016 needed = 0xdeadbeef;
1017 ret = pGetPerAdapterInfo(1, NULL, &needed);
1018 if (ret == ERROR_NO_DATA) return; /* no such adapter */
1019 ok( ret == ERROR_BUFFER_OVERFLOW, "got %u instead of ERROR_BUFFER_OVERFLOW\n", ret );
1020 ok( needed != 0xdeadbeef, "needed not set\n" );
1021 buffer = HeapAlloc( GetProcessHeap(), 0, needed );
1022 ret = pGetPerAdapterInfo(1, buffer, &needed);
1023 ok( ret == NO_ERROR, "got %u instead of NO_ERROR\n", ret );
1024 HeapFree( GetProcessHeap(), 0, buffer );
1027 static void testNotifyAddrChange(void)
1029 DWORD ret, bytes;
1030 OVERLAPPED overlapped;
1031 HANDLE handle;
1032 BOOL success;
1034 if (!pNotifyAddrChange)
1036 win_skip("NotifyAddrChange not present\n");
1037 return;
1039 if (!pCancelIPChangeNotify)
1041 win_skip("CancelIPChangeNotify not present\n");
1042 return;
1045 handle = NULL;
1046 ZeroMemory(&overlapped, sizeof(overlapped));
1047 ret = pNotifyAddrChange(&handle, &overlapped);
1048 if (ret == ERROR_NOT_SUPPORTED)
1050 win_skip("NotifyAddrChange is not supported\n");
1051 return;
1053 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
1054 ret = GetLastError();
1055 todo_wine ok(ret == ERROR_IO_PENDING, "GetLastError returned %d, expected ERROR_IO_PENDING\n", ret);
1056 success = pCancelIPChangeNotify(&overlapped);
1057 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
1059 ZeroMemory(&overlapped, sizeof(overlapped));
1060 success = pCancelIPChangeNotify(&overlapped);
1061 ok(success == FALSE, "CancelIPChangeNotify returned TRUE, expected FALSE\n");
1063 handle = NULL;
1064 ZeroMemory(&overlapped, sizeof(overlapped));
1065 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1066 ret = pNotifyAddrChange(&handle, &overlapped);
1067 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected ERROR_IO_PENDING\n", ret);
1068 todo_wine ok(handle != INVALID_HANDLE_VALUE, "NotifyAddrChange returned invalid file handle\n");
1069 success = GetOverlappedResult(handle, &overlapped, &bytes, FALSE);
1070 ok(success == FALSE, "GetOverlappedResult returned TRUE, expected FALSE\n");
1071 ret = GetLastError();
1072 ok(ret == ERROR_IO_INCOMPLETE, "GetLastError returned %d, expected ERROR_IO_INCOMPLETE\n", ret);
1073 success = pCancelIPChangeNotify(&overlapped);
1074 todo_wine ok(success == TRUE, "CancelIPChangeNotify returned FALSE, expected TRUE\n");
1076 if (winetest_interactive)
1078 handle = NULL;
1079 ZeroMemory(&overlapped, sizeof(overlapped));
1080 overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1081 trace("Testing asynchronous ipv4 address change notification. Please "
1082 "change the ipv4 address of one of your network interfaces\n");
1083 ret = pNotifyAddrChange(&handle, &overlapped);
1084 ok(ret == ERROR_IO_PENDING, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
1085 success = GetOverlappedResult(handle, &overlapped, &bytes, TRUE);
1086 ok(success == TRUE, "GetOverlappedResult returned FALSE, expected TRUE\n");
1089 /* test synchronous functionality */
1090 if (winetest_interactive)
1092 trace("Testing synchronous ipv4 address change notification. Please "
1093 "change the ipv4 address of one of your network interfaces\n");
1094 ret = pNotifyAddrChange(NULL, NULL);
1095 todo_wine ok(ret == NO_ERROR, "NotifyAddrChange returned %d, expected NO_ERROR\n", ret);
1100 still-to-be-tested 2K-onward functions:
1101 AddIPAddress
1102 CreateProxyArpEntry
1103 DeleteIPAddress
1104 DeleteProxyArpEntry
1105 EnableRouter
1106 FlushIpNetTable
1107 GetAdapterIndex
1108 NotifyRouteChange + CancelIPChangeNotify
1109 SendARP
1110 UnenableRouter
1112 static void testWin2KFunctions(void)
1114 testGetPerAdapterInfo();
1115 testNotifyAddrChange();
1118 static void test_GetAdaptersAddresses(void)
1120 ULONG ret, size;
1121 IP_ADAPTER_ADDRESSES *aa, *ptr;
1122 IP_ADAPTER_UNICAST_ADDRESS *ua;
1124 if (!pGetAdaptersAddresses)
1126 win_skip("GetAdaptersAddresses not present\n");
1127 return;
1130 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, NULL);
1131 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", ret);
1133 /* size should be ignored and overwritten if buffer is NULL */
1134 size = 0x7fffffff;
1135 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size);
1136 ok(ret == ERROR_BUFFER_OVERFLOW, "expected ERROR_BUFFER_OVERFLOW, got %u\n", ret);
1137 if (ret != ERROR_BUFFER_OVERFLOW) return;
1139 ptr = HeapAlloc(GetProcessHeap(), 0, size);
1140 ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, ptr, &size);
1141 ok(!ret, "expected ERROR_SUCCESS got %u\n", ret);
1143 for (aa = ptr; !ret && aa; aa = aa->Next)
1145 ok(aa->DnsSuffix != NULL, "DnsSuffix is not a valid pointer\n");
1146 ok(aa->Description != NULL, "Description is not a valid pointer\n");
1147 ok(aa->FriendlyName != NULL, "FriendlyName is not a valid pointer\n");
1149 if (winetest_debug <= 1)
1150 continue;
1152 trace("Length: %u\n", S(U(*aa)).Length);
1153 trace("IfIndex: %u\n", S(U(*aa)).IfIndex);
1154 trace("Next: %p\n", aa->Next);
1155 trace("AdapterName: %s\n", aa->AdapterName);
1156 trace("FirstUnicastAddress: %p\n", aa->FirstUnicastAddress);
1157 ua = aa->FirstUnicastAddress;
1158 while (ua)
1160 trace("\tLength: %u\n", S(U(*ua)).Length);
1161 trace("\tFlags: 0x%08x\n", S(U(*ua)).Flags);
1162 trace("\tNext: %p\n", ua->Next);
1163 trace("\tAddress.lpSockaddr: %p\n", ua->Address.lpSockaddr);
1164 trace("\tAddress.iSockaddrLength: %d\n", ua->Address.iSockaddrLength);
1165 trace("\tPrefixOrigin: %u\n", ua->PrefixOrigin);
1166 trace("\tSuffixOrigin: %u\n", ua->SuffixOrigin);
1167 trace("\tDadState: %u\n", ua->DadState);
1168 trace("\tValidLifetime: 0x%08x\n", ua->ValidLifetime);
1169 trace("\tPreferredLifetime: 0x%08x\n", ua->PreferredLifetime);
1170 trace("\tLeaseLifetime: 0x%08x\n", ua->LeaseLifetime);
1171 trace("\n");
1172 ua = ua->Next;
1174 trace("FirstAnycastAddress: %p\n", aa->FirstAnycastAddress);
1175 trace("FirstMulticastAddress: %p\n", aa->FirstMulticastAddress);
1176 trace("FirstDnsServerAddress: %p\n", aa->FirstDnsServerAddress);
1177 trace("DnsSuffix: %p\n", aa->DnsSuffix);
1178 trace("Description: %p\n", aa->Description);
1179 trace("FriendlyName: %p\n", aa->FriendlyName);
1180 trace("PhysicalAddress: %02x\n", aa->PhysicalAddress[0]);
1181 trace("PhysicalAddressLength: %u\n", aa->PhysicalAddressLength);
1182 trace("Flags: 0x%08x\n", aa->Flags);
1183 trace("Mtu: %u\n", aa->Mtu);
1184 trace("IfType: %u\n", aa->IfType);
1185 trace("OperStatus: %u\n", aa->OperStatus);
1186 trace("\n");
1188 HeapFree(GetProcessHeap(), 0, ptr);
1191 static void test_GetExtendedTcpTable(void)
1193 DWORD ret, size;
1194 MIB_TCPTABLE *table;
1195 MIB_TCPTABLE_OWNER_PID *table_pid;
1197 if (!pGetExtendedTcpTable)
1199 win_skip("GetExtendedTcpTable not available\n");
1200 return;
1202 ret = pGetExtendedTcpTable( NULL, NULL, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1203 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
1205 size = 0;
1206 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1207 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1209 table = HeapAlloc( GetProcessHeap(), 0, size );
1210 ret = pGetExtendedTcpTable( table, &size, TRUE, AF_INET, TCP_TABLE_BASIC_ALL, 0 );
1211 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1212 HeapFree( GetProcessHeap(), 0, table );
1214 size = 0;
1215 ret = pGetExtendedTcpTable( NULL, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
1216 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1218 table_pid = HeapAlloc( GetProcessHeap(), 0, size );
1219 ret = pGetExtendedTcpTable( table_pid, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0 );
1220 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1221 HeapFree( GetProcessHeap(), 0, table_pid );
1224 static void test_GetExtendedUdpTable(void)
1226 DWORD ret, size;
1227 MIB_UDPTABLE *table;
1228 MIB_UDPTABLE_OWNER_PID *table_pid;
1230 if (!pGetExtendedUdpTable)
1232 win_skip("GetExtendedUdpTable not available\n");
1233 return;
1235 ret = pGetExtendedUdpTable( NULL, NULL, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1236 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
1238 size = 0;
1239 ret = pGetExtendedUdpTable( NULL, &size, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1240 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1242 table = HeapAlloc( GetProcessHeap(), 0, size );
1243 ret = pGetExtendedUdpTable( table, &size, TRUE, AF_INET, UDP_TABLE_BASIC, 0 );
1244 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1245 HeapFree( GetProcessHeap(), 0, table );
1247 size = 0;
1248 ret = pGetExtendedUdpTable( NULL, &size, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0 );
1249 ok( ret == ERROR_INSUFFICIENT_BUFFER, "got %u\n", ret );
1251 table_pid = HeapAlloc( GetProcessHeap(), 0, size );
1252 ret = pGetExtendedUdpTable( table_pid, &size, TRUE, AF_INET, UDP_TABLE_OWNER_PID, 0 );
1253 ok( ret == ERROR_SUCCESS, "got %u\n", ret );
1254 HeapFree( GetProcessHeap(), 0, table_pid );
1257 START_TEST(iphlpapi)
1260 loadIPHlpApi();
1261 if (hLibrary) {
1262 HANDLE thread;
1264 testWin98OnlyFunctions();
1265 testWinNT4Functions();
1267 /* run testGetXXXX in two threads at once to make sure we don't crash in that case */
1268 thread = CreateThread(NULL, 0, testWin98Functions, NULL, 0, NULL);
1269 testWin98Functions(NULL);
1270 WaitForSingleObject(thread, INFINITE);
1272 testWin2KFunctions();
1273 test_GetAdaptersAddresses();
1274 test_GetExtendedTcpTable();
1275 test_GetExtendedUdpTable();
1276 freeIPHlpApi();