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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
42 #include "wine/test.h"
46 static HMODULE hLibrary
= NULL
;
48 typedef DWORD (WINAPI
*GetNumberOfInterfacesFunc
)(PDWORD
);
49 typedef DWORD (WINAPI
*GetIpAddrTableFunc
)(PMIB_IPADDRTABLE
,PULONG
,BOOL
);
50 typedef DWORD (WINAPI
*GetIfEntryFunc
)(PMIB_IFROW
);
51 typedef DWORD (WINAPI
*GetFriendlyIfIndexFunc
)(DWORD
);
52 typedef DWORD (WINAPI
*GetIfTableFunc
)(PMIB_IFTABLE
,PULONG
,BOOL
);
53 typedef DWORD (WINAPI
*GetIpForwardTableFunc
)(PMIB_IPFORWARDTABLE
,PULONG
,BOOL
);
54 typedef DWORD (WINAPI
*GetIpNetTableFunc
)(PMIB_IPNETTABLE
,PULONG
,BOOL
);
55 typedef DWORD (WINAPI
*GetInterfaceInfoFunc
)(PIP_INTERFACE_INFO
,PULONG
);
56 typedef DWORD (WINAPI
*GetAdaptersInfoFunc
)(PIP_ADAPTER_INFO
,PULONG
);
57 typedef DWORD (WINAPI
*GetNetworkParamsFunc
)(PFIXED_INFO
,PULONG
);
58 typedef DWORD (WINAPI
*GetIcmpStatisticsFunc
)(PMIB_ICMP
);
59 typedef DWORD (WINAPI
*GetIpStatisticsFunc
)(PMIB_IPSTATS
);
60 typedef DWORD (WINAPI
*GetTcpStatisticsFunc
)(PMIB_TCPSTATS
);
61 typedef DWORD (WINAPI
*GetUdpStatisticsFunc
)(PMIB_UDPSTATS
);
62 typedef DWORD (WINAPI
*GetTcpTableFunc
)(PMIB_TCPTABLE
,PDWORD
,BOOL
);
63 typedef DWORD (WINAPI
*GetUdpTableFunc
)(PMIB_UDPTABLE
,PDWORD
,BOOL
);
65 static GetNumberOfInterfacesFunc gGetNumberOfInterfaces
= NULL
;
66 static GetIpAddrTableFunc gGetIpAddrTable
= NULL
;
67 static GetIfEntryFunc gGetIfEntry
= NULL
;
68 static GetFriendlyIfIndexFunc gGetFriendlyIfIndex
= NULL
;
69 static GetIfTableFunc gGetIfTable
= NULL
;
70 static GetIpForwardTableFunc gGetIpForwardTable
= NULL
;
71 static GetIpNetTableFunc gGetIpNetTable
= NULL
;
72 static GetInterfaceInfoFunc gGetInterfaceInfo
= NULL
;
73 static GetAdaptersInfoFunc gGetAdaptersInfo
= NULL
;
74 static GetNetworkParamsFunc gGetNetworkParams
= NULL
;
75 static GetIcmpStatisticsFunc gGetIcmpStatistics
= NULL
;
76 static GetIpStatisticsFunc gGetIpStatistics
= NULL
;
77 static GetTcpStatisticsFunc gGetTcpStatistics
= NULL
;
78 static GetUdpStatisticsFunc gGetUdpStatistics
= NULL
;
79 static GetTcpTableFunc gGetTcpTable
= NULL
;
80 static GetUdpTableFunc gGetUdpTable
= NULL
;
82 static void loadIPHlpApi(void)
84 hLibrary
= LoadLibraryA("iphlpapi.dll");
86 gGetNumberOfInterfaces
= (GetNumberOfInterfacesFunc
)GetProcAddress(
87 hLibrary
, "GetNumberOfInterfaces");
88 gGetIpAddrTable
= (GetIpAddrTableFunc
)GetProcAddress(
89 hLibrary
, "GetIpAddrTable");
90 gGetIfEntry
= (GetIfEntryFunc
)GetProcAddress(
91 hLibrary
, "GetIfEntry");
92 gGetFriendlyIfIndex
= (GetFriendlyIfIndexFunc
)GetProcAddress(
93 hLibrary
, "GetFriendlyIfIndex");
94 gGetIfTable
= (GetIfTableFunc
)GetProcAddress(
95 hLibrary
, "GetIfTable");
96 gGetIpForwardTable
= (GetIpForwardTableFunc
)GetProcAddress(
97 hLibrary
, "GetIpForwardTable");
98 gGetIpNetTable
= (GetIpNetTableFunc
)GetProcAddress(
99 hLibrary
, "GetIpNetTable");
100 gGetInterfaceInfo
= (GetInterfaceInfoFunc
)GetProcAddress(
101 hLibrary
, "GetInterfaceInfo");
102 gGetAdaptersInfo
= (GetAdaptersInfoFunc
)GetProcAddress(
103 hLibrary
, "GetAdaptersInfo");
104 gGetNetworkParams
= (GetNetworkParamsFunc
)GetProcAddress(
105 hLibrary
, "GetNetworkParams");
106 gGetIcmpStatistics
= (GetIcmpStatisticsFunc
)GetProcAddress(
107 hLibrary
, "GetIcmpStatistics");
108 gGetIpStatistics
= (GetIpStatisticsFunc
)GetProcAddress(
109 hLibrary
, "GetIpStatistics");
110 gGetTcpStatistics
= (GetTcpStatisticsFunc
)GetProcAddress(
111 hLibrary
, "GetTcpStatistics");
112 gGetUdpStatistics
= (GetUdpStatisticsFunc
)GetProcAddress(
113 hLibrary
, "GetUdpStatistics");
114 gGetTcpTable
= (GetTcpTableFunc
)GetProcAddress(
115 hLibrary
, "GetTcpTable");
116 gGetUdpTable
= (GetUdpTableFunc
)GetProcAddress(
117 hLibrary
, "GetUdpTable");
121 static void freeIPHlpApi(void)
124 gGetNumberOfInterfaces
= NULL
;
125 gGetIpAddrTable
= NULL
;
127 gGetFriendlyIfIndex
= NULL
;
129 gGetIpForwardTable
= NULL
;
130 gGetIpNetTable
= NULL
;
131 gGetInterfaceInfo
= NULL
;
132 gGetAdaptersInfo
= NULL
;
133 gGetNetworkParams
= NULL
;
134 gGetIcmpStatistics
= NULL
;
135 gGetIpStatistics
= NULL
;
136 gGetTcpStatistics
= NULL
;
137 gGetUdpStatistics
= NULL
;
140 FreeLibrary(hLibrary
);
146 still-to-be-tested 98-only functions:
147 GetUniDirectionalAdapterInfo
149 void testWin98OnlyFunctions(void)
153 static void testGetNumberOfInterfaces(void)
155 if (gGetNumberOfInterfaces
) {
156 DWORD apiReturn
= gGetNumberOfInterfaces(NULL
), numInterfaces
;
158 if (apiReturn
== ERROR_NOT_SUPPORTED
)
160 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
161 "GetNumberOfInterfaces(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
163 apiReturn
= gGetNumberOfInterfaces(&numInterfaces
);
164 ok(apiReturn
== NO_ERROR
,
165 "GetNumberOfInterfaces returned %ld, expected 0\n", apiReturn
);
169 static void testGetIfEntry(DWORD index
)
175 memset(&row
, 0, sizeof(row
));
176 apiReturn
= gGetIfEntry(NULL
);
177 if (apiReturn
== ERROR_NOT_SUPPORTED
)
179 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
180 "GetIfEntry(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
182 row
.dwIndex
= -1; /* hope that's always bogus! */
183 apiReturn
= gGetIfEntry(&row
);
184 ok(apiReturn
== ERROR_INVALID_DATA
,
185 "GetIfEntry(bogus row) returned %ld, expected ERROR_INVALID_DATA\n",
188 apiReturn
= gGetIfEntry(&row
);
189 ok(apiReturn
== NO_ERROR
,
190 "GetIfEntry returned %ld, expected NO_ERROR\n", apiReturn
);
194 static void testGetIpAddrTable(void)
196 if (gGetIpAddrTable
) {
200 apiReturn
= gGetIpAddrTable(NULL
, NULL
, FALSE
);
201 if (apiReturn
== ERROR_NOT_SUPPORTED
)
203 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
204 "GetIpAddrTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
206 apiReturn
= gGetIpAddrTable(NULL
, &dwSize
, FALSE
);
207 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
208 "GetIpAddrTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
210 if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
211 PMIB_IPADDRTABLE buf
= (PMIB_IPADDRTABLE
)malloc(dwSize
);
213 apiReturn
= gGetIpAddrTable(buf
, &dwSize
, FALSE
);
214 ok(apiReturn
== NO_ERROR
,
215 "GetIpAddrTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n",
217 if (apiReturn
== NO_ERROR
&& buf
->dwNumEntries
)
218 testGetIfEntry(buf
->table
[0].dwIndex
);
224 static void testGetIfTable(void)
230 apiReturn
= gGetIfTable(NULL
, NULL
, FALSE
);
231 if (apiReturn
== ERROR_NOT_SUPPORTED
)
233 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
234 "GetIfTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
236 apiReturn
= gGetIfTable(NULL
, &dwSize
, FALSE
);
237 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
238 "GetIfTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
240 if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
241 PMIB_IFTABLE buf
= (PMIB_IFTABLE
)malloc(dwSize
);
243 apiReturn
= gGetIfTable(buf
, &dwSize
, FALSE
);
244 ok(apiReturn
== NO_ERROR
,
245 "GetIfTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n\n",
252 static void testGetIpForwardTable(void)
254 if (gGetIpForwardTable
) {
258 apiReturn
= gGetIpForwardTable(NULL
, NULL
, FALSE
);
259 if (apiReturn
== ERROR_NOT_SUPPORTED
)
261 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
262 "GetIpForwardTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
264 apiReturn
= gGetIpForwardTable(NULL
, &dwSize
, FALSE
);
265 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
266 "GetIpForwardTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
268 if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
269 PMIB_IPFORWARDTABLE buf
= (PMIB_IPFORWARDTABLE
)malloc(dwSize
);
271 apiReturn
= gGetIpForwardTable(buf
, &dwSize
, FALSE
);
272 ok(apiReturn
== NO_ERROR
,
273 "GetIpForwardTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n",
280 void testGetIpNetTable(void)
282 if (gGetIpNetTable
) {
286 apiReturn
= gGetIpNetTable(NULL
, NULL
, FALSE
);
287 if (apiReturn
== ERROR_NOT_SUPPORTED
)
289 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
290 "GetIpNetTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
292 apiReturn
= gGetIpNetTable(NULL
, &dwSize
, FALSE
);
293 ok(apiReturn
== ERROR_NO_DATA
|| apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
294 "GetIpNetTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_NO_DATA or ERROR_INSUFFICIENT_BUFFER\n",
296 if (apiReturn
== ERROR_NO_DATA
)
297 ; /* empty ARP table's okay */
298 else if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
299 PMIB_IPNETTABLE buf
= (PMIB_IPNETTABLE
)malloc(dwSize
);
301 apiReturn
= gGetIpNetTable(buf
, &dwSize
, FALSE
);
302 ok(apiReturn
== NO_ERROR
,
303 "GetIpNetTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n",
310 void testGetIcmpStatistics(void)
312 if (gGetIcmpStatistics
) {
316 apiReturn
= gGetIcmpStatistics(NULL
);
317 if (apiReturn
== ERROR_NOT_SUPPORTED
)
319 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
320 "GetIcmpStatistics(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
322 apiReturn
= gGetIcmpStatistics(&stats
);
323 ok(apiReturn
== NO_ERROR
,
324 "GetIcmpStatistics returned %ld, expected NO_ERROR\n", apiReturn
);
328 void testGetIpStatistics(void)
330 if (gGetIpStatistics
) {
334 apiReturn
= gGetIpStatistics(NULL
);
335 if (apiReturn
== ERROR_NOT_SUPPORTED
)
337 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
338 "GetIpStatistics(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
340 apiReturn
= gGetIpStatistics(&stats
);
341 ok(apiReturn
== NO_ERROR
,
342 "GetIpStatistics returned %ld, expected NO_ERROR\n", apiReturn
);
346 void testGetTcpStatistics(void)
348 if (gGetTcpStatistics
) {
352 apiReturn
= gGetTcpStatistics(NULL
);
353 if (apiReturn
== ERROR_NOT_SUPPORTED
)
355 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
356 "GetTcpStatistics(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
358 apiReturn
= gGetTcpStatistics(&stats
);
359 ok(apiReturn
== NO_ERROR
,
360 "GetTcpStatistics returned %ld, expected NO_ERROR\n", apiReturn
);
364 void testGetUdpStatistics(void)
366 if (gGetUdpStatistics
) {
370 apiReturn
= gGetUdpStatistics(NULL
);
371 if (apiReturn
== ERROR_NOT_SUPPORTED
)
373 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
374 "GetUdpStatistics(NULL) returned %ld, expected ERROR_INVALID_PARAMETER\n",
376 apiReturn
= gGetUdpStatistics(&stats
);
377 ok(apiReturn
== NO_ERROR
,
378 "GetUdpStatistics returned %ld, expected NO_ERROR\n", apiReturn
);
382 void testGetTcpTable(void)
388 apiReturn
= gGetTcpTable(NULL
, NULL
, FALSE
);
389 if (apiReturn
== ERROR_NOT_SUPPORTED
)
391 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
392 "GetTcpTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
394 apiReturn
= gGetTcpTable(NULL
, &dwSize
, FALSE
);
395 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
396 "GetTcpTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
398 if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
399 PMIB_TCPTABLE buf
= (PMIB_TCPTABLE
)malloc(dwSize
);
401 apiReturn
= gGetTcpTable(buf
, &dwSize
, FALSE
);
402 ok(apiReturn
== NO_ERROR
,
403 "GetTcpTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n",
410 void testGetUdpTable(void)
416 apiReturn
= gGetUdpTable(NULL
, NULL
, FALSE
);
417 if (apiReturn
== ERROR_NOT_SUPPORTED
)
419 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
420 "GetUdpTable(NULL, NULL, FALSE) returned %ld, expected ERROR_INVALID_PARAMETER\n",
422 apiReturn
= gGetUdpTable(NULL
, &dwSize
, FALSE
);
423 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
424 "GetUdpTable(NULL, &dwSize, FALSE) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
426 if (apiReturn
!= ERROR_INSUFFICIENT_BUFFER
) {
427 PMIB_UDPTABLE buf
= (PMIB_UDPTABLE
)malloc(dwSize
);
429 apiReturn
= gGetUdpTable(buf
, &dwSize
, FALSE
);
430 ok(apiReturn
== NO_ERROR
,
431 "GetUdpTable(buf, &dwSize, FALSE) returned %ld, expected NO_ERROR\n",
439 still-to-be-tested NT4-onward functions:
453 static void testWinNT4Functions(void)
455 testGetNumberOfInterfaces();
456 testGetIpAddrTable();
458 testGetIpForwardTable();
460 testGetIcmpStatistics();
461 testGetIpStatistics();
462 testGetTcpStatistics();
463 testGetUdpStatistics();
468 static void testGetInterfaceInfo(void)
470 if (gGetInterfaceInfo
) {
474 apiReturn
= gGetInterfaceInfo(NULL
, NULL
);
475 if (apiReturn
== ERROR_NOT_SUPPORTED
)
477 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
478 "GetInterfaceInfo returned %ld, expected ERROR_INVALID_PARAMETER\n",
480 apiReturn
= gGetInterfaceInfo(NULL
, &len
);
481 ok(apiReturn
== ERROR_INSUFFICIENT_BUFFER
,
482 "GetInterfaceInfo returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
484 if (apiReturn
== ERROR_INSUFFICIENT_BUFFER
) {
485 PIP_INTERFACE_INFO buf
= (PIP_INTERFACE_INFO
)malloc(len
);
487 apiReturn
= gGetInterfaceInfo(buf
, &len
);
488 ok(apiReturn
== NO_ERROR
,
489 "GetInterfaceInfo(buf, &dwSize) returned %ld, expected NO_ERROR\n",
496 static void testGetAdaptersInfo(void)
498 if (gGetAdaptersInfo
) {
502 apiReturn
= gGetAdaptersInfo(NULL
, NULL
);
503 if (apiReturn
== ERROR_NOT_SUPPORTED
)
505 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
506 "GetAdaptersInfo returned %ld, expected ERROR_INVALID_PARAMETER\n",
508 apiReturn
= gGetAdaptersInfo(NULL
, &len
);
509 ok(apiReturn
== ERROR_NO_DATA
|| apiReturn
== ERROR_BUFFER_OVERFLOW
,
510 "GetAdaptersInfo returned %ld, expected ERROR_NO_DATA or ERROR_BUFFER_OVERFLOW\n",
512 if (apiReturn
== ERROR_NO_DATA
)
513 ; /* no adapter's, that's okay */
514 else if (apiReturn
== ERROR_BUFFER_OVERFLOW
) {
515 PIP_ADAPTER_INFO buf
= (PIP_ADAPTER_INFO
)malloc(len
);
517 apiReturn
= gGetAdaptersInfo(buf
, &len
);
518 ok(apiReturn
== NO_ERROR
,
519 "GetAdaptersInfo(buf, &dwSize) returned %ld, expected NO_ERROR\n",
526 static void testGetNetworkParams(void)
528 if (gGetNetworkParams
) {
532 apiReturn
= gGetNetworkParams(NULL
, NULL
);
533 if (apiReturn
== ERROR_NOT_SUPPORTED
)
535 ok(apiReturn
== ERROR_INVALID_PARAMETER
,
536 "GetNetworkParams returned %ld, expected ERROR_INVALID_PARAMETER\n",
538 apiReturn
= gGetNetworkParams(NULL
, &len
);
539 ok(apiReturn
== ERROR_BUFFER_OVERFLOW
,
540 "GetNetworkParams returned %ld, expected ERROR_BUFFER_OVERFLOW\n",
542 if (apiReturn
== ERROR_BUFFER_OVERFLOW
) {
543 PFIXED_INFO buf
= (PFIXED_INFO
)malloc(len
);
545 apiReturn
= gGetNetworkParams(buf
, &len
);
546 ok(apiReturn
== NO_ERROR
,
547 "GetNetworkParams(buf, &dwSize) returned %ld, expected NO_ERROR\n",
555 still-to-be-tested 98-onward functions:
561 static void testWin98Functions(void)
563 testGetInterfaceInfo();
564 testGetAdaptersInfo();
565 testGetNetworkParams();
569 still-to-be-tested 2K-onward functions:
583 static void testWin2KFunctions(void)
592 testWin98OnlyFunctions();
593 testWinNT4Functions();
594 testWin98Functions();
595 testWin2KFunctions();