2 * Unit test suite for protocol functions
4 * Copyright 2004 Hans Leidekker
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
24 #define WIN32_NO_STATUS
33 #include "wine/test.h"
35 static void (WINAPI
*pFreeAddrInfoExW
)(ADDRINFOEXW
*ai
);
36 static int (WINAPI
*pGetAddrInfoExW
)(const WCHAR
*name
, const WCHAR
*servname
, DWORD
namespace,
37 GUID
*namespace_id
, const ADDRINFOEXW
*hints
, ADDRINFOEXW
**result
,
38 struct timeval
*timeout
, OVERLAPPED
*overlapped
,
39 LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine
, HANDLE
*handle
);
40 static int (WINAPI
*pGetAddrInfoExOverlappedResult
)(OVERLAPPED
*overlapped
);
41 static int (WINAPI
*pGetHostNameW
)(WCHAR
*name
, int len
);
42 static const char *(WINAPI
*p_inet_ntop
)(int family
, void *addr
, char *string
, ULONG size
);
43 static const WCHAR
*(WINAPI
*pInetNtopW
)(int family
, void *addr
, WCHAR
*string
, ULONG size
);
44 static int (WINAPI
*p_inet_pton
)(int family
, const char *string
, void *addr
);
45 static int (WINAPI
*pInetPtonW
)(int family
, WCHAR
*string
, void *addr
);
46 static int (WINAPI
*pWSCGetProviderInfo
)(GUID
*provider
, WSC_PROVIDER_INFO_TYPE type
, BYTE
*info
, size_t *size
, DWORD flags
, INT
*err
);
48 /* TCP and UDP over IP fixed set of service flags */
49 #define TCPIP_SERVICE_FLAGS (XP1_GUARANTEED_DELIVERY \
50 | XP1_GUARANTEED_ORDER \
51 | XP1_GRACEFUL_CLOSE \
52 | XP1_EXPEDITED_DATA \
55 #define UDPIP_SERVICE_FLAGS (XP1_CONNECTIONLESS \
56 | XP1_MESSAGE_ORIENTED \
57 | XP1_SUPPORT_BROADCAST \
58 | XP1_SUPPORT_MULTIPOINT \
61 static void test_service_flags(int family
, int version
, int socktype
, int protocol
, DWORD testflags
)
63 DWORD expectedflags
= 0;
64 if (socktype
== SOCK_STREAM
&& protocol
== IPPROTO_TCP
)
65 expectedflags
= TCPIP_SERVICE_FLAGS
;
66 if (socktype
== SOCK_DGRAM
&& protocol
== IPPROTO_UDP
)
67 expectedflags
= UDPIP_SERVICE_FLAGS
;
69 /* check if standard TCP and UDP protocols are offering the correct service flags */
70 if ((family
== AF_INET
|| family
== AF_INET6
) && version
== 2 && expectedflags
)
72 /* QOS may or may not be installed */
73 testflags
&= ~XP1_QOS_SUPPORTED
;
74 ok(expectedflags
== testflags
,
75 "Incorrect flags, expected 0x%x, received 0x%x\n",
76 expectedflags
, testflags
);
80 static void test_WSAEnumProtocolsA(void)
84 WSAPROTOCOL_INFOA info
, *buffer
;
85 INT ptest
[] = {0xdead, IPPROTO_TCP
, 0xcafe, IPPROTO_UDP
, 0xbeef, 0};
87 ret
= WSAEnumProtocolsA( NULL
, NULL
, &len
);
88 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsA() succeeded unexpectedly\n");
89 error
= WSAGetLastError();
90 ok( error
== WSAENOBUFS
, "Expected 10055, received %d\n", error
);
94 ret
= WSAEnumProtocolsA( NULL
, &info
, &len
);
95 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsA() succeeded unexpectedly\n");
96 error
= WSAGetLastError();
97 ok( error
== WSAENOBUFS
, "Expected 10055, received %d\n", error
);
99 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
103 ret
= WSAEnumProtocolsA( NULL
, buffer
, &len
);
104 ok( ret
!= SOCKET_ERROR
, "WSAEnumProtocolsA() failed unexpectedly: %d\n",
107 for (i
= 0; i
< ret
; i
++)
109 ok( strlen( buffer
[i
].szProtocol
), "No protocol name found\n" );
110 test_service_flags( buffer
[i
].iAddressFamily
, buffer
[i
].iVersion
,
111 buffer
[i
].iSocketType
, buffer
[i
].iProtocol
,
112 buffer
[i
].dwServiceFlags1
);
115 HeapFree( GetProcessHeap(), 0, buffer
);
118 /* Test invalid protocols in the list */
119 ret
= WSAEnumProtocolsA( ptest
, NULL
, &len
);
120 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsA() succeeded unexpectedly\n");
121 error
= WSAGetLastError();
122 ok( error
== WSAENOBUFS
|| broken(error
== WSAEFAULT
) /* NT4 */,
123 "Expected 10055, received %d\n", error
);
125 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
129 ret
= WSAEnumProtocolsA( ptest
, buffer
, &len
);
130 ok( ret
!= SOCKET_ERROR
, "WSAEnumProtocolsA() failed unexpectedly: %d\n",
132 ok( ret
>= 2, "Expected at least 2 items, received %d\n", ret
);
134 for (i
= found
= 0; i
< ret
; i
++)
135 for (j
= 0; j
< ARRAY_SIZE(ptest
); j
++)
136 if (buffer
[i
].iProtocol
== ptest
[j
])
141 ok(found
== 0x0A, "Expected 2 bits represented as 0xA, received 0x%x\n", found
);
143 HeapFree( GetProcessHeap(), 0, buffer
);
147 static void test_WSAEnumProtocolsW(void)
149 INT ret
, i
, j
, found
;
150 DWORD len
= 0, error
;
151 WSAPROTOCOL_INFOW info
, *buffer
;
152 INT ptest
[] = {0xdead, IPPROTO_TCP
, 0xcafe, IPPROTO_UDP
, 0xbeef, 0};
154 ret
= WSAEnumProtocolsW( NULL
, NULL
, &len
);
155 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsW() succeeded unexpectedly\n");
156 error
= WSAGetLastError();
157 ok( error
== WSAENOBUFS
, "Expected 10055, received %d\n", error
);
161 ret
= WSAEnumProtocolsW( NULL
, &info
, &len
);
162 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsW() succeeded unexpectedly\n");
163 error
= WSAGetLastError();
164 ok( error
== WSAENOBUFS
, "Expected 10055, received %d\n", error
);
166 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
170 ret
= WSAEnumProtocolsW( NULL
, buffer
, &len
);
171 ok( ret
!= SOCKET_ERROR
, "WSAEnumProtocolsW() failed unexpectedly: %d\n",
174 for (i
= 0; i
< ret
; i
++)
176 ok( lstrlenW( buffer
[i
].szProtocol
), "No protocol name found\n" );
177 test_service_flags( buffer
[i
].iAddressFamily
, buffer
[i
].iVersion
,
178 buffer
[i
].iSocketType
, buffer
[i
].iProtocol
,
179 buffer
[i
].dwServiceFlags1
);
182 HeapFree( GetProcessHeap(), 0, buffer
);
185 /* Test invalid protocols in the list */
186 ret
= WSAEnumProtocolsW( ptest
, NULL
, &len
);
187 ok( ret
== SOCKET_ERROR
, "WSAEnumProtocolsW() succeeded unexpectedly\n");
188 error
= WSAGetLastError();
189 ok( error
== WSAENOBUFS
|| broken(error
== WSAEFAULT
) /* NT4 */,
190 "Expected 10055, received %d\n", error
);
192 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
196 ret
= WSAEnumProtocolsW( ptest
, buffer
, &len
);
197 ok( ret
!= SOCKET_ERROR
, "WSAEnumProtocolsW() failed unexpectedly: %d\n",
199 ok( ret
>= 2, "Expected at least 2 items, received %d\n", ret
);
201 for (i
= found
= 0; i
< ret
; i
++)
202 for (j
= 0; j
< ARRAY_SIZE(ptest
); j
++)
203 if (buffer
[i
].iProtocol
== ptest
[j
])
208 ok(found
== 0x0A, "Expected 2 bits represented as 0xA, received 0x%x\n", found
);
210 HeapFree( GetProcessHeap(), 0, buffer
);
217 const char *names
[2];
218 BOOL missing_from_xp
;
221 static const struct protocol protocols
[] =
223 { 0, { "ip", "IP" }},
224 { 1, { "icmp", "ICMP" }},
225 { 3, { "ggp", "GGP" }},
226 { 6, { "tcp", "TCP" }},
227 { 8, { "egp", "EGP" }},
228 { 12, { "pup", "PUP" }},
229 { 17, { "udp", "UDP" }},
230 { 20, { "hmp", "HMP" }},
231 { 22, { "xns-idp", "XNS-IDP" }},
232 { 27, { "rdp", "RDP" }},
233 { 41, { "ipv6", "IPv6" }, TRUE
},
234 { 43, { "ipv6-route", "IPv6-Route" }, TRUE
},
235 { 44, { "ipv6-frag", "IPv6-Frag" }, TRUE
},
236 { 50, { "esp", "ESP" }, TRUE
},
237 { 51, { "ah", "AH" }, TRUE
},
238 { 58, { "ipv6-icmp", "IPv6-ICMP" }, TRUE
},
239 { 59, { "ipv6-nonxt", "IPv6-NoNxt" }, TRUE
},
240 { 60, { "ipv6-opts", "IPv6-Opts" }, TRUE
},
241 { 66, { "rvd", "RVD" }},
244 static const struct protocol
*find_protocol(int number
)
247 for (i
= 0; i
< ARRAY_SIZE(protocols
); i
++)
249 if (protocols
[i
].prot
== number
)
250 return &protocols
[i
];
255 static void test_getprotobyname(void)
257 struct protoent
*ent
;
258 char all_caps_name
[16];
261 for (i
= 0; i
< ARRAY_SIZE(protocols
); i
++)
263 for (j
= 0; j
< ARRAY_SIZE(protocols
[0].names
); j
++)
265 ent
= getprotobyname(protocols
[i
].names
[j
]);
266 ok((ent
&& ent
->p_proto
== protocols
[i
].prot
) || broken(!ent
&& protocols
[i
].missing_from_xp
),
267 "Expected %s to be protocol number %d, got %d\n",
268 wine_dbgstr_a(protocols
[i
].names
[j
]), protocols
[i
].prot
, ent
? ent
->p_proto
: -1);
271 for (j
= 0; protocols
[i
].names
[0][j
]; j
++)
272 all_caps_name
[j
] = toupper(protocols
[i
].names
[0][j
]);
273 all_caps_name
[j
] = 0;
274 ent
= getprotobyname(all_caps_name
);
275 ok((ent
&& ent
->p_proto
== protocols
[i
].prot
) || broken(!ent
&& protocols
[i
].missing_from_xp
),
276 "Expected %s to be protocol number %d, got %d\n",
277 wine_dbgstr_a(all_caps_name
), protocols
[i
].prot
, ent
? ent
->p_proto
: -1);
281 static void test_getprotobynumber(void)
283 struct protoent
*ent
;
284 const struct protocol
*ref
;
287 for (i
= -1; i
<= 256; i
++)
289 ent
= getprotobynumber(i
);
290 ref
= find_protocol(i
);
294 ok(!ent
, "Expected protocol number %d to be undefined, got %s\n",
295 i
, wine_dbgstr_a(ent
? ent
->p_name
: NULL
));
299 ok((ent
&& ent
->p_name
&& !strcmp(ent
->p_name
, ref
->names
[0])) ||
300 broken(!ent
&& ref
->missing_from_xp
),
301 "Expected protocol number %d to be %s, got %s\n",
302 i
, ref
->names
[0], wine_dbgstr_a(ent
? ent
->p_name
: NULL
));
304 ok((ent
&& ent
->p_aliases
&& ent
->p_aliases
[0] &&
305 !strcmp(ent
->p_aliases
[0], ref
->names
[1])) ||
306 broken(!ent
&& ref
->missing_from_xp
),
307 "Expected protocol number %d alias 0 to be %s, got %s\n",
308 i
, ref
->names
[0], wine_dbgstr_a(ent
&& ent
->p_aliases
? ent
->p_aliases
[0] : NULL
));
312 #define NUM_THREADS 3 /* Number of threads to run getservbyname */
313 #define NUM_QUERIES 250 /* Number of getservbyname queries per thread */
315 static DWORD WINAPI
do_getservbyname( void *param
)
324 {"domain", "udp", 53},
325 {"telnet", "tcp", 23},
328 HANDLE
*starttest
= param
;
330 struct servent
*pserv
[2];
332 ok( WaitForSingleObject( *starttest
, 30 * 1000 ) != WAIT_TIMEOUT
,
333 "test_getservbyname: timeout waiting for start signal\n" );
335 /* ensure that necessary buffer resizes are completed */
336 for (j
= 0; j
< 2; j
++)
337 pserv
[j
] = getservbyname( serv
[j
].name
, serv
[j
].proto
);
339 for (i
= 0; i
< NUM_QUERIES
/ 2; i
++)
341 for (j
= 0; j
< 2; j
++)
343 pserv
[j
] = getservbyname( serv
[j
].name
, serv
[j
].proto
);
344 ok( pserv
[j
] != NULL
|| broken(pserv
[j
] == NULL
) /* win8, fixed in win81 */,
345 "getservbyname could not retrieve information for %s: %d\n", serv
[j
].name
, WSAGetLastError() );
346 if ( !pserv
[j
] ) continue;
347 ok( pserv
[j
]->s_port
== htons(serv
[j
].port
),
348 "getservbyname returned the wrong port for %s: %d\n", serv
[j
].name
, ntohs(pserv
[j
]->s_port
) );
349 ok( !strcmp( pserv
[j
]->s_proto
, serv
[j
].proto
),
350 "getservbyname returned the wrong protocol for %s: %s\n", serv
[j
].name
, pserv
[j
]->s_proto
);
351 ok( !strcmp( pserv
[j
]->s_name
, serv
[j
].name
),
352 "getservbyname returned the wrong name for %s: %s\n", serv
[j
].name
, pserv
[j
]->s_name
);
355 ok( pserv
[0] == pserv
[1] || broken(pserv
[0] != pserv
[1]) /* win8, fixed in win81 */,
356 "getservbyname: winsock resized servent buffer when not necessary\n" );
362 static void test_getservbyname(void)
365 HANDLE starttest
, thread
[NUM_THREADS
];
367 starttest
= CreateEventA( NULL
, 1, 0, "test_getservbyname_starttest" );
370 for (i
= 0; i
< NUM_THREADS
; i
++)
371 thread
[i
] = CreateThread( NULL
, 0, do_getservbyname
, &starttest
, 0, NULL
);
373 /* signal threads to start */
374 SetEvent( starttest
);
376 for (i
= 0; i
< NUM_THREADS
; i
++)
377 WaitForSingleObject( thread
[i
], 30 * 1000 );
380 static void test_WSALookupService(void)
382 char buffer
[4096], strbuff
[128];
383 WSAQUERYSETW
*qs
= NULL
;
387 DWORD error
, offset
, size
;
389 qs
= (WSAQUERYSETW
*)buffer
;
390 memset(qs
, 0, sizeof(*qs
));
392 /* invalid parameter tests */
393 ret
= WSALookupServiceBeginW(NULL
, 0, &handle
);
394 error
= WSAGetLastError();
395 ok(ret
== SOCKET_ERROR
, "WSALookupServiceBeginW should have failed\n");
397 ok(error
== WSAEFAULT
, "expected 10014, got %d\n", error
);
399 ret
= WSALookupServiceBeginW(qs
, 0, NULL
);
400 error
= WSAGetLastError();
401 ok(ret
== SOCKET_ERROR
, "WSALookupServiceBeginW should have failed\n");
403 ok(error
== WSAEFAULT
, "expected 10014, got %d\n", error
);
405 ret
= WSALookupServiceBeginW(qs
, 0, &handle
);
406 ok(ret
== SOCKET_ERROR
, "WSALookupServiceBeginW should have failed\n");
407 todo_wine
ok(WSAGetLastError() == ERROR_INVALID_PARAMETER
408 || broken(WSAGetLastError() == WSASERVICE_NOT_FOUND
) /* win10 1809 */,
409 "got error %u\n", WSAGetLastError());
411 ret
= WSALookupServiceEnd(NULL
);
412 error
= WSAGetLastError();
414 ok(ret
== SOCKET_ERROR
, "WSALookupServiceEnd should have failed\n");
416 ok(error
== ERROR_INVALID_HANDLE
, "expected 6, got %d\n", error
);
418 /* standard network list query */
419 qs
->dwSize
= sizeof(*qs
);
420 handle
= (HANDLE
)0xdeadbeef;
421 ret
= WSALookupServiceBeginW(qs
, LUP_RETURN_ALL
| LUP_DEEP
, &handle
);
422 error
= WSAGetLastError();
423 if (ret
&& error
== ERROR_INVALID_PARAMETER
)
425 win_skip("the current WSALookupServiceBeginW test is not supported in win <= 2000\n");
430 ok(!ret
, "WSALookupServiceBeginW failed unexpectedly with error %d\n", error
);
432 ok(handle
!= (HANDLE
)0xdeadbeef, "Handle was not filled\n");
437 memset(qs
, 0, sizeof(*qs
));
438 size
= sizeof(buffer
);
440 if (WSALookupServiceNextW(handle
, 0, &size
, qs
) == SOCKET_ERROR
)
442 ok(WSAGetLastError() == WSA_E_NO_MORE
, "got error %u\n", WSAGetLastError());
446 if (winetest_debug
<= 1) continue;
448 WideCharToMultiByte(CP_ACP
, 0, qs
->lpszServiceInstanceName
, -1,
449 strbuff
, sizeof(strbuff
), NULL
, NULL
);
450 trace("Network Name: %s\n", strbuff
);
452 /* network data is written in the blob field */
455 /* each network may have multiple NLA_BLOB information structures */
458 netdata
= (PNLA_BLOB
) &qs
->lpBlob
->pBlobData
[offset
];
459 switch (netdata
->header
.type
)
462 trace("\tNLA Data Type: NLA_RAW_DATA\n");
465 trace("\tNLA Data Type: NLA_INTERFACE\n");
466 trace("\t\tType: %d\n", netdata
->data
.interfaceData
.dwType
);
467 trace("\t\tSpeed: %d\n", netdata
->data
.interfaceData
.dwSpeed
);
468 trace("\t\tAdapter Name: %s\n", netdata
->data
.interfaceData
.adapterName
);
470 case NLA_802_1X_LOCATION
:
471 trace("\tNLA Data Type: NLA_802_1X_LOCATION\n");
472 trace("\t\tInformation: %s\n", netdata
->data
.locationData
.information
);
474 case NLA_CONNECTIVITY
:
475 switch (netdata
->data
.connectivity
.type
)
477 case NLA_NETWORK_AD_HOC
:
478 trace("\t\tNetwork Type: AD HOC\n");
480 case NLA_NETWORK_MANAGED
:
481 trace("\t\tNetwork Type: Managed\n");
483 case NLA_NETWORK_UNMANAGED
:
484 trace("\t\tNetwork Type: Unmanaged\n");
486 case NLA_NETWORK_UNKNOWN
:
487 trace("\t\tNetwork Type: Unknown\n");
489 switch (netdata
->data
.connectivity
.internet
)
491 case NLA_INTERNET_NO
:
492 trace("\t\tInternet connectivity: No\n");
494 case NLA_INTERNET_YES
:
495 trace("\t\tInternet connectivity: Yes\n");
497 case NLA_INTERNET_UNKNOWN
:
498 trace("\t\tInternet connectivity: Unknown\n");
503 trace("\tNLA Data Type: NLA_ICS\n");
504 trace("\t\tSpeed: %d\n",
505 netdata
->data
.ICS
.remote
.speed
);
506 trace("\t\tType: %d\n",
507 netdata
->data
.ICS
.remote
.type
);
508 trace("\t\tState: %d\n",
509 netdata
->data
.ICS
.remote
.state
);
510 WideCharToMultiByte(CP_ACP
, 0, netdata
->data
.ICS
.remote
.machineName
, -1,
511 strbuff
, sizeof(strbuff
), NULL
, NULL
);
512 trace("\t\tMachine Name: %s\n", strbuff
);
513 WideCharToMultiByte(CP_ACP
, 0, netdata
->data
.ICS
.remote
.sharedAdapterName
, -1,
514 strbuff
, sizeof(strbuff
), NULL
, NULL
);
515 trace("\t\tShared Adapter Name: %s\n", strbuff
);
518 trace("\tNLA Data Type: Unknown\n");
527 ret
= WSALookupServiceEnd(handle
);
528 ok(!ret
, "WSALookupServiceEnd failed unexpectedly\n");
531 #define WM_ASYNCCOMPLETE (WM_USER + 100)
532 static HWND
create_async_message_window(void)
534 static const char class_name
[] = "ws2_32 async message window class";
536 WNDCLASSEXA wndclass
;
539 wndclass
.cbSize
= sizeof(wndclass
);
540 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
541 wndclass
.lpfnWndProc
= DefWindowProcA
;
542 wndclass
.cbClsExtra
= 0;
543 wndclass
.cbWndExtra
= 0;
544 wndclass
.hInstance
= GetModuleHandleA(NULL
);
545 wndclass
.hIcon
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
546 wndclass
.hIconSm
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
547 wndclass
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
548 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
549 wndclass
.lpszClassName
= class_name
;
550 wndclass
.lpszMenuName
= NULL
;
552 RegisterClassExA(&wndclass
);
554 hWnd
= CreateWindowA(class_name
, "ws2_32 async message window", WS_OVERLAPPEDWINDOW
,
555 0, 0, 500, 500, NULL
, NULL
, GetModuleHandleA(NULL
), NULL
);
556 ok(!!hWnd
, "failed to create window\n");
561 static void wait_for_async_message(HWND hwnd
, HANDLE handle
)
566 while ((ret
= GetMessageA(&msg
, 0, 0, 0)) &&
567 !(msg
.hwnd
== hwnd
&& msg
.message
== WM_ASYNCCOMPLETE
))
569 TranslateMessage(&msg
);
570 DispatchMessageA(&msg
);
573 ok(ret
, "did not expect WM_QUIT message\n");
574 ok(msg
.wParam
== (WPARAM
)handle
, "expected wParam = %p, got %lx\n", handle
, msg
.wParam
);
577 static void test_WSAAsyncGetServByPort(void)
579 HWND hwnd
= create_async_message_window();
581 char buffer
[MAXGETHOSTSTRUCT
];
583 /* FIXME: The asynchronous window messages should be tested. */
585 /* Parameters are not checked when initiating the asynchronous operation. */
586 ret
= WSAAsyncGetServByPort(NULL
, 0, 0, NULL
, NULL
, 0);
587 ok(ret
!= NULL
, "WSAAsyncGetServByPort returned NULL\n");
589 ret
= WSAAsyncGetServByPort(hwnd
, WM_ASYNCCOMPLETE
, 0, NULL
, NULL
, 0);
590 ok(ret
!= NULL
, "WSAAsyncGetServByPort returned NULL\n");
591 wait_for_async_message(hwnd
, ret
);
593 ret
= WSAAsyncGetServByPort(hwnd
, WM_ASYNCCOMPLETE
, htons(80), NULL
, NULL
, 0);
594 ok(ret
!= NULL
, "WSAAsyncGetServByPort returned NULL\n");
595 wait_for_async_message(hwnd
, ret
);
597 ret
= WSAAsyncGetServByPort(hwnd
, WM_ASYNCCOMPLETE
, htons(80), NULL
, buffer
, MAXGETHOSTSTRUCT
);
598 ok(ret
!= NULL
, "WSAAsyncGetServByPort returned NULL\n");
599 wait_for_async_message(hwnd
, ret
);
604 static void test_WSAAsyncGetServByName(void)
606 HWND hwnd
= create_async_message_window();
608 char buffer
[MAXGETHOSTSTRUCT
];
610 /* FIXME: The asynchronous window messages should be tested. */
612 /* Parameters are not checked when initiating the asynchronous operation. */
613 ret
= WSAAsyncGetServByName(hwnd
, WM_ASYNCCOMPLETE
, "", NULL
, NULL
, 0);
614 ok(ret
!= NULL
, "WSAAsyncGetServByName returned NULL\n");
615 wait_for_async_message(hwnd
, ret
);
617 ret
= WSAAsyncGetServByName(hwnd
, WM_ASYNCCOMPLETE
, "", "", buffer
, MAXGETHOSTSTRUCT
);
618 ok(ret
!= NULL
, "WSAAsyncGetServByName returned NULL\n");
619 wait_for_async_message(hwnd
, ret
);
621 ret
= WSAAsyncGetServByName(hwnd
, WM_ASYNCCOMPLETE
, "http", NULL
, NULL
, 0);
622 ok(ret
!= NULL
, "WSAAsyncGetServByName returned NULL\n");
623 wait_for_async_message(hwnd
, ret
);
625 ret
= WSAAsyncGetServByName(hwnd
, WM_ASYNCCOMPLETE
, "http", "tcp", buffer
, MAXGETHOSTSTRUCT
);
626 ok(ret
!= NULL
, "WSAAsyncGetServByName returned NULL\n");
627 wait_for_async_message(hwnd
, ret
);
632 static DWORD WINAPI
inet_ntoa_thread_proc(void *param
)
636 HANDLE
*event
= param
;
638 addr
= inet_addr("4.3.2.1");
639 ok(addr
== htonl(0x04030201), "expected 0x04030201, got %08x\n", addr
);
640 str
= inet_ntoa(*(struct in_addr
*)&addr
);
641 ok(!strcmp(str
, "4.3.2.1"), "expected 4.3.2.1, got %s\n", str
);
644 WaitForSingleObject(event
[1], 3000);
649 static void test_inet_ntoa(void)
653 HANDLE thread
, event
[2];
656 addr
= inet_addr("1.2.3.4");
657 ok(addr
== htonl(0x01020304), "expected 0x01020304, got %08x\n", addr
);
658 str
= inet_ntoa(*(struct in_addr
*)&addr
);
659 ok(!strcmp(str
, "1.2.3.4"), "expected 1.2.3.4, got %s\n", str
);
661 event
[0] = CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
662 event
[1] = CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
664 thread
= CreateThread(NULL
, 0, inet_ntoa_thread_proc
, event
, 0, &tid
);
665 WaitForSingleObject(event
[0], 3000);
667 ok(!strcmp(str
, "1.2.3.4"), "expected 1.2.3.4, got %s\n", str
);
670 WaitForSingleObject(thread
, 3000);
672 CloseHandle(event
[0]);
673 CloseHandle(event
[1]);
677 static void test_inet_pton(void)
683 const char *printable
, *collapsed
, *raw_data
;
688 {AF_UNSPEC
, -1, WSAEFAULT
, NULL
, NULL
, NULL
},
689 {AF_INET
, -1, WSAEFAULT
, NULL
, NULL
, NULL
},
690 {AF_INET6
, -1, WSAEFAULT
, NULL
, NULL
, NULL
},
691 {AF_UNSPEC
, -1, WSAEAFNOSUPPORT
, "127.0.0.1", NULL
, NULL
},
692 {AF_INET
, 1, 0, "127.0.0.1", "127.0.0.1", "\x7f\x00\x00\x01"},
693 {AF_INET6
, 0, 0, "127.0.0.1", "127.0.0.1", NULL
},
694 {AF_INET
, 0, 0, "::1/128", NULL
, NULL
},
695 {AF_INET6
, 0, 0, "::1/128", NULL
, NULL
},
696 {AF_UNSPEC
, -1, WSAEAFNOSUPPORT
, "broken", NULL
, NULL
},
697 {AF_INET
, 0, 0, "broken", NULL
, NULL
},
699 {AF_INET6
, 0, 0, "broken", NULL
, NULL
},
700 {AF_UNSPEC
, -1, WSAEAFNOSUPPORT
, "177.32.45.20", NULL
, NULL
},
701 {AF_INET
, 1, 0, "177.32.45.20", "177.32.45.20", "\xb1\x20\x2d\x14"},
702 {AF_INET6
, 0, 0, "177.32.45.20", NULL
, NULL
},
703 {AF_INET
, 0, 0, "2607:f0d0:1002:51::4", NULL
, NULL
},
704 {AF_INET6
, 1, 0, "2607:f0d0:1002:51::4", "2607:f0d0:1002:51::4",
705 "\x26\x07\xf0\xd0\x10\x02\x00\x51\x00\x00\x00\x00\x00\x00\x00\x04"},
706 {AF_INET
, 0, 0, "::177.32.45.20", NULL
, NULL
},
707 {AF_INET6
, 1, 0, "::177.32.45.20", "::177.32.45.20",
708 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb1\x20\x2d\x14"},
709 {AF_INET
, 0, 0, "fe80::0202:b3ff:fe1e:8329", NULL
, NULL
},
710 {AF_INET6
, 1, 0, "fe80::0202:b3ff:fe1e:8329", "fe80::202:b3ff:fe1e:8329",
711 "\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"},
713 {AF_INET6
, 1, 0, "fe80::202:b3ff:fe1e:8329", "fe80::202:b3ff:fe1e:8329",
714 "\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"},
715 {AF_INET
, 0, 0, "a", NULL
, NULL
},
716 {AF_INET
, 0, 0, "a.b", NULL
, NULL
},
717 {AF_INET
, 0, 0, "a.b.c", NULL
, NULL
},
718 {AF_INET
, 0, 0, "a.b.c.d", NULL
, NULL
},
719 {AF_INET6
, 1, 0, "2001:cdba:0000:0000:0000:0000:3257:9652", "2001:cdba::3257:9652",
720 "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"},
721 {AF_INET6
, 1, 0, "2001:cdba::3257:9652", "2001:cdba::3257:9652",
722 "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"},
723 {AF_INET6
, 1, 0, "2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652",
724 "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"},
725 {AF_INET
, 0, 0, "0x12345678", NULL
, NULL
},
726 {AF_INET6
, 0, 0, "::1:2:3:4:5:6:7", NULL
, NULL
}, /* windows bug */
728 {AF_INET6
, 1, 0, "::5efe:1.2.3.4", "::5efe:1.2.3.4",
729 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5e\xfe\x01\x02\x03\x04"},
730 {AF_INET6
, 1, 0, "::ffff:0:1.2.3.4", "::ffff:0:1.2.3.4",
731 "\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x01\x02\x03\x04"},
735 char buffer
[64],str
[64];
736 WCHAR printableW
[64], collapsedW
[64];
740 /* inet_ntop and inet_pton became available in Vista and Win2008 */
743 win_skip("inet_ntop is not available\n");
747 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
749 WSASetLastError(0xdeadbeef);
750 ret
= p_inet_pton(tests
[i
].family
, tests
[i
].printable
, buffer
);
751 ok(ret
== tests
[i
].ret
, "Test [%d]: Expected %d, got %d\n", i
, tests
[i
].ret
, ret
);
752 err
= WSAGetLastError();
753 if (tests
[i
].ret
== -1)
754 ok(tests
[i
].err
== err
, "Test [%d]: Expected 0x%x, got 0x%x\n", i
, tests
[i
].err
, err
);
756 ok(err
== 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i
, err
);
757 if (tests
[i
].ret
!= 1) continue;
758 ok(memcmp(buffer
, tests
[i
].raw_data
,
759 tests
[i
].family
== AF_INET
? sizeof(struct in_addr
) : sizeof(struct in6_addr
)) == 0,
760 "Test [%d]: Expected binary data differs\n", i
);
762 /* Test the result from Pton with Ntop */
763 strcpy (str
, "deadbeef");
764 ptr
= p_inet_ntop(tests
[i
].family
, buffer
, str
, sizeof(str
));
765 ok(ptr
!= NULL
, "Test [%d]: Failed with NULL\n", i
);
766 ok(ptr
== str
, "Test [%d]: Pointers differ (%p != %p)\n", i
, ptr
, str
);
767 ok(strcmp(ptr
, tests
[i
].collapsed
) == 0, "Test [%d]: Expected '%s', got '%s'\n",
768 i
, tests
[i
].collapsed
, ptr
);
771 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
773 if (tests
[i
].printable
)
774 MultiByteToWideChar(CP_ACP
, 0, tests
[i
].printable
, -1, printableW
, ARRAY_SIZE(printableW
));
775 WSASetLastError(0xdeadbeef);
776 ret
= pInetPtonW(tests
[i
].family
, tests
[i
].printable
? printableW
: NULL
, buffer
);
777 ok(ret
== tests
[i
].ret
, "Test [%d]: Expected %d, got %d\n", i
, tests
[i
].ret
, ret
);
778 err
= WSAGetLastError();
779 if (tests
[i
].ret
== -1)
780 ok(tests
[i
].err
== err
, "Test [%d]: Expected 0x%x, got 0x%x\n", i
, tests
[i
].err
, err
);
781 else if (tests
[i
].ret
== 0)
782 ok(err
== WSAEINVAL
|| broken(err
== 0xdeadbeef) /* win2008 */,
783 "Test [%d]: Expected WSAEINVAL, got 0x%x\n", i
, err
);
785 ok(err
== 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i
, err
);
786 if (tests
[i
].ret
!= 1) continue;
787 ok(memcmp(buffer
, tests
[i
].raw_data
,
788 tests
[i
].family
== AF_INET
? sizeof(struct in_addr
) : sizeof(struct in6_addr
)) == 0,
789 "Test [%d]: Expected binary data differs\n", i
);
791 /* Test the result from Pton with Ntop */
792 printableW
[0] = 0xdead;
793 ptrW
= pInetNtopW(tests
[i
].family
, buffer
, printableW
, ARRAY_SIZE(printableW
));
794 ok(ptrW
!= NULL
, "Test [%d]: Failed with NULL\n", i
);
795 ok(ptrW
== printableW
, "Test [%d]: Pointers differ (%p != %p)\n", i
, ptrW
, printableW
);
797 MultiByteToWideChar(CP_ACP
, 0, tests
[i
].collapsed
, -1, collapsedW
, ARRAY_SIZE(collapsedW
));
798 ok(!wcscmp(ptrW
, collapsedW
), "Test [%d]: Expected '%s', got '%s'\n",
799 i
, tests
[i
].collapsed
, wine_dbgstr_w(ptrW
));
803 static void test_addr_to_print(void)
811 u_long addr0_Num
= 0x00000000;
812 const char *addr0_Str
= "0.0.0.0";
813 u_long addr1_Num
= 0x20201015;
814 const char *addr1_Str
= "21.16.32.32";
815 u_char addr2_Num
[16] = {0,0,0,0,0,0,0,0,0,0,0xff,0xfe,0xcC,0x98,0xbd,0x74};
816 const char *addr2_Str
= "::fffe:cc98:bd74";
817 u_char addr3_Num
[16] = {0x20,0x30,0xa4,0xb1};
818 const char *addr3_Str
= "2030:a4b1::";
819 u_char addr4_Num
[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0xcC,0x98,0xbd,0x74};
820 const char *addr4_Str
= "::204.152.189.116";
822 /* Test IPv4 addresses */
823 in
.s_addr
= addr0_Num
;
825 pdst
= inet_ntoa(*((struct in_addr
*)&in
.s_addr
));
826 ok(pdst
!= NULL
, "inet_ntoa failed %s\n", dst
);
827 ok(!strcmp(pdst
, addr0_Str
),"Address %s != %s\n", pdst
, addr0_Str
);
829 /* Test that inet_ntoa and inet_ntop return the same value */
830 in
.S_un
.S_addr
= addr1_Num
;
831 pdst
= inet_ntoa(*((struct in_addr
*)&in
.s_addr
));
832 ok(pdst
!= NULL
, "inet_ntoa failed %s\n", dst
);
833 ok(!strcmp(pdst
, addr1_Str
),"Address %s != %s\n", pdst
, addr1_Str
);
835 /* inet_ntop became available in Vista and Win2008 */
838 win_skip("InetNtop not present, not executing tests\n");
842 /* Second part of test */
843 pdst
= p_inet_ntop(AF_INET
, &in
.s_addr
, dst
, sizeof(dst
));
844 ok(pdst
!= NULL
, "InetNtop failed %s\n", dst
);
845 ok(!strcmp(pdst
, addr1_Str
),"Address %s != %s\n", pdst
, addr1_Str
);
847 /* Test invalid parm conditions */
848 pdst
= p_inet_ntop(1, (void *)&in
.s_addr
, dst
, sizeof(dst
));
849 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
850 ok(WSAGetLastError() == WSAEAFNOSUPPORT
, "Should be WSAEAFNOSUPPORT\n");
852 /* Test Null destination */
854 pdst
= p_inet_ntop(AF_INET
, &in
.s_addr
, NULL
, sizeof(dst
));
855 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
856 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
857 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
859 /* Test zero length passed */
862 pdst
= p_inet_ntop(AF_INET
, &in
.s_addr
, dst
, 0);
863 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
864 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
865 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
867 /* Test length one shorter than the address length */
870 pdst
= p_inet_ntop(AF_INET
, &in
.s_addr
, dst
, 6);
871 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
872 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
873 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
875 /* Test longer length is ok */
878 pdst
= p_inet_ntop(AF_INET
, &in
.s_addr
, dst
, sizeof(dst
)+1);
879 ok(pdst
!= NULL
, "The pointer should be returned (%p)\n", pdst
);
880 ok(!strcmp(pdst
, addr1_Str
),"Address %s != %s\n", pdst
, addr1_Str
);
882 /* Test the IPv6 addresses */
884 /* Test an zero prefixed IPV6 address */
885 memcpy(in6
.u
.Byte
, addr2_Num
, sizeof(addr2_Num
));
886 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, sizeof(dst6
));
887 ok(pdst
!= NULL
, "InetNtop failed %s\n", dst6
);
888 ok(!strcmp(pdst
, addr2_Str
),"Address %s != %s\n", pdst
, addr2_Str
);
890 /* Test an zero suffixed IPV6 address */
891 memcpy(in6
.s6_addr
, addr3_Num
, sizeof(addr3_Num
));
892 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, sizeof(dst6
));
893 ok(pdst
!= NULL
, "InetNtop failed %s\n", dst6
);
894 ok(!strcmp(pdst
, addr3_Str
),"Address %s != %s\n", pdst
, addr3_Str
);
896 /* Test the IPv6 address contains the IPv4 address in IPv4 notation */
897 memcpy(in6
.s6_addr
, addr4_Num
, sizeof(addr4_Num
));
898 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, sizeof(dst6
));
899 ok(pdst
!= NULL
, "InetNtop failed %s\n", dst6
);
900 ok(!strcmp(pdst
, addr4_Str
),"Address %s != %s\n", pdst
, addr4_Str
);
902 /* Test invalid parm conditions */
903 memcpy(in6
.u
.Byte
, addr2_Num
, sizeof(addr2_Num
));
905 /* Test Null destination */
907 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, NULL
, sizeof(dst6
));
908 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
909 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
910 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
912 /* Test zero length passed */
915 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, 0);
916 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
917 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
918 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
920 /* Test length one shorter than the address length */
923 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, 16);
924 ok(pdst
== NULL
, "The pointer should not be returned (%p)\n", pdst
);
925 ok(WSAGetLastError() == STATUS_INVALID_PARAMETER
|| WSAGetLastError() == WSAEINVAL
/* Win7 */,
926 "Should be STATUS_INVALID_PARAMETER or WSAEINVAL not 0x%x\n", WSAGetLastError());
928 /* Test longer length is ok */
931 pdst
= p_inet_ntop(AF_INET6
, &in6
.s6_addr
, dst6
, 18);
932 ok(pdst
!= NULL
, "The pointer should be returned (%p)\n", pdst
);
935 static void test_WSAAddressToString(void)
946 { 0xffffffff, 0, "255.255.255.255" },
947 { 0, 0xffff, "0.0.0.0:65535" },
948 { 0xffffffff, 0xffff, "255.255.255.255:65535" },
959 { { 0, 0, 0, 0, 0, 0, 0, 0x100 }, 0, 0, "::1" },
960 { { 0xab20, 0, 0, 0, 0, 0, 0, 0x100 }, 0, 0, "20ab::1" },
961 { { 0xab20, 0, 0, 0, 0, 0, 0, 0x120 }, 0, 0xfa81, "[20ab::2001]:33274" },
962 { { 0xab20, 0, 0, 0, 0, 0, 0, 0x120 }, 0x1234, 0xfa81, "[20ab::2001%4660]:33274" },
963 { { 0xab20, 0, 0, 0, 0, 0, 0, 0x120 }, 0x1234, 0, "20ab::2001%4660" },
965 SOCKADDR_IN sockaddr
;
966 SOCKADDR_IN6 sockaddr6
;
968 WCHAR outputW
[64], expected_outputW
[64];
975 sockaddr
.sin_family
= AF_INET
;
976 sockaddr
.sin_addr
.s_addr
= 0;
977 sockaddr
.sin_port
= 0;
978 WSASetLastError( 0xdeadbeef );
979 ret
= WSAAddressToStringA( (SOCKADDR
*)&sockaddr
, sizeof(sockaddr
), NULL
, output
, &len
);
980 ok( ret
== SOCKET_ERROR
, "WSAAddressToStringA() returned %d, expected SOCKET_ERROR\n", ret
);
981 ok( WSAGetLastError() == WSAEFAULT
, "WSAAddressToStringA() gave error %d, expected WSAEFAULT\n", WSAGetLastError() );
982 ok( len
== 8, "WSAAddressToStringA() gave length %d, expected 8\n", len
);
985 sockaddr
.sin_family
= AF_INET
;
986 sockaddr
.sin_addr
.s_addr
= 0;
987 sockaddr
.sin_port
= 0;
988 WSASetLastError( 0xdeadbeef );
989 ret
= WSAAddressToStringW( (SOCKADDR
*)&sockaddr
, sizeof(sockaddr
), NULL
, NULL
, &len
);
990 ok( ret
== SOCKET_ERROR
, "got %d\n", ret
);
991 ok( WSAGetLastError() == WSAEFAULT
, "got %08x\n", WSAGetLastError() );
992 ok( len
== 8, "got %u\n", len
);
994 len
= ARRAY_SIZE(outputW
);
995 memset( outputW
, 0, sizeof(outputW
) );
996 ret
= WSAAddressToStringW( (SOCKADDR
*)&sockaddr
, sizeof(sockaddr
), NULL
, outputW
, &len
);
997 ok( !ret
, "WSAAddressToStringW() returned %d\n", ret
);
998 ok( len
== 8, "got %u\n", len
);
999 ok( !wcscmp(outputW
, L
"0.0.0.0"), "got %s\n", wine_dbgstr_w(outputW
) );
1001 for (i
= 0; i
< 2; i
++)
1003 for (j
= 0; j
< ARRAY_SIZE(ipv4_tests
); j
++)
1005 sockaddr
.sin_family
= AF_INET
;
1006 sockaddr
.sin_addr
.s_addr
= ipv4_tests
[j
].address
;
1007 sockaddr
.sin_port
= ipv4_tests
[j
].port
;
1011 len
= sizeof(output
);
1012 memset(output
, 0, len
);
1013 ret
= WSAAddressToStringA( (SOCKADDR
*)&sockaddr
, sizeof(sockaddr
), NULL
, output
, &len
);
1014 ok( !ret
, "ipv4_tests[%d] failed unexpectedly: %d\n", j
, WSAGetLastError() );
1015 ok( !strcmp( output
, ipv4_tests
[j
].output
),
1016 "ipv4_tests[%d]: got address %s, expected %s\n",
1017 j
, wine_dbgstr_a(output
), wine_dbgstr_a(ipv4_tests
[j
].output
) );
1018 ok( len
== strlen(ipv4_tests
[j
].output
) + 1,
1019 "ipv4_tests[%d]: got length %d, expected %d\n",
1020 j
, len
, strlen(ipv4_tests
[j
].output
) + 1 );
1024 len
= sizeof(outputW
);
1025 memset(outputW
, 0, len
);
1026 ret
= WSAAddressToStringW( (SOCKADDR
*)&sockaddr
, sizeof(sockaddr
), NULL
, outputW
, &len
);
1027 MultiByteToWideChar( CP_ACP
, 0, ipv4_tests
[j
].output
, -1,
1028 expected_outputW
, ARRAY_SIZE(expected_outputW
) );
1029 ok( !ret
, "ipv4_tests[%d] failed unexpectedly: %d\n", j
, WSAGetLastError() );
1030 ok( !wcscmp( outputW
, expected_outputW
),
1031 "ipv4_tests[%d]: got address %s, expected %s\n",
1032 j
, wine_dbgstr_w(outputW
), wine_dbgstr_w(expected_outputW
) );
1033 ok( len
== wcslen(expected_outputW
) + 1,
1034 "ipv4_tests[%d]: got length %d, expected %d\n",
1035 j
, len
, wcslen(expected_outputW
) + 1 );
1039 /* check to see if IPv6 is available */
1040 v6
= socket(AF_INET6
, SOCK_STREAM
, IPPROTO_TCP
);
1041 if (v6
== INVALID_SOCKET
) {
1042 skip("Could not create IPv6 socket (LastError: %d; %d expected if IPv6 not available).\n",
1043 WSAGetLastError(), WSAEAFNOSUPPORT
);
1048 for (j
= 0; j
< ARRAY_SIZE(ipv6_tests
); j
++)
1050 sockaddr6
.sin6_family
= AF_INET6
;
1051 sockaddr6
.sin6_scope_id
= ipv6_tests
[j
].scope
;
1052 sockaddr6
.sin6_port
= ipv6_tests
[j
].port
;
1053 memcpy( sockaddr6
.sin6_addr
.s6_addr
, ipv6_tests
[j
].address
, sizeof(ipv6_tests
[j
].address
) );
1057 len
= sizeof(output
);
1058 ret
= WSAAddressToStringA( (SOCKADDR
*)&sockaddr6
, sizeof(sockaddr6
), NULL
, output
, &len
);
1059 ok( !ret
, "ipv6_tests[%d] failed unexpectedly: %d\n", j
, WSAGetLastError() );
1060 ok( !strcmp( output
, ipv6_tests
[j
].output
),
1061 "ipv6_tests[%d]: gave address %s, expected %s\n",
1062 j
, wine_dbgstr_a(output
), wine_dbgstr_a(ipv6_tests
[j
].output
) );
1063 ok( len
== strlen(ipv6_tests
[j
].output
) + 1,
1064 "ipv6_tests[%d]: got length %d, expected %d\n",
1065 j
, len
, strlen(ipv6_tests
[j
].output
) + 1 );
1069 len
= sizeof(outputW
);
1070 ret
= WSAAddressToStringW( (SOCKADDR
*)&sockaddr6
, sizeof(sockaddr6
), NULL
, outputW
, &len
);
1071 MultiByteToWideChar( CP_ACP
, 0, ipv6_tests
[j
].output
, -1,
1072 expected_outputW
, ARRAY_SIZE(expected_outputW
) );
1073 ok( !ret
, "ipv6_tests[%d] failed unexpectedly: %d\n", j
, WSAGetLastError() );
1074 ok( !wcscmp( outputW
, expected_outputW
),
1075 "ipv6_tests[%d]: got address %s, expected %s\n",
1076 j
, wine_dbgstr_w(outputW
), wine_dbgstr_w(expected_outputW
) );
1077 ok( len
== wcslen(expected_outputW
) + 1,
1078 "ipv6_tests[%d]: got length %d, expected %d\n",
1079 j
, len
, wcslen(expected_outputW
) + 1 );
1085 static void test_WSAStringToAddress(void)
1097 { "127.127.127.127", 0x7f7f7f7f },
1098 { "255.255.255.255", 0xffffffff },
1099 { "127.127.127.127:65535", 0x7f7f7f7f, 65535 },
1100 { "255.255.255.255:65535", 0xffffffff, 65535 },
1101 { "2001::1", 0xd1070000, 0, WSAEINVAL
},
1102 { "1.2.3.", 0, 0, WSAEINVAL
},
1103 { "", 0, 0, WSAEINVAL
},
1114 { "::1", { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1115 { "[::1]", { 0, 0, 0, 0, 0, 0, 0, 0x100 } },
1116 { "[::1]:65535", { 0, 0, 0, 0, 0, 0, 0, 0x100 }, 0xffff },
1117 { "2001::1", { 0x120, 0, 0, 0, 0, 0, 0, 0x100 } },
1118 { "::1]:65535", { 0, 0, 0, 0, 0, 0, 0, 0x100 }, 0, WSAEINVAL
},
1119 { "001::1", { 0x100, 0, 0, 0, 0, 0, 0, 0x100 } },
1120 { "::1:2:3:4:5:6:7", { 0, 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600 }, 0, WSAEINVAL
}, /* Windows bug */
1121 { "1.2.3.4", { 0x201, 0x3, 0, 0, 0, 0, 0, 0 }, 0, WSAEINVAL
},
1122 { "1:2:3:", { 0x100, 0x200, 0x300, 0, 0, 0, 0 }, 0, WSAEINVAL
},
1123 { "", { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, WSAEINVAL
},
1127 INT len
, ret
, expected_len
, expected_ret
;
1128 short expected_family
;
1129 SOCKADDR_IN sockaddr
;
1130 SOCKADDR_IN6 sockaddr6
;
1134 WSASetLastError( 0 );
1135 ret
= WSAStringToAddressA( ipv4_tests
[0].input
, AF_INET
, NULL
, (SOCKADDR
*)&sockaddr
, &len
);
1136 ok( ret
== SOCKET_ERROR
, "WSAStringToAddressA() returned %d, expected SOCKET_ERROR\n", ret
);
1137 ok( WSAGetLastError() == WSAEFAULT
, "WSAStringToAddress() gave error %d, expected WSAEFAULT\n", WSAGetLastError() );
1138 ok( len
>= sizeof(sockaddr
) || broken(len
== 0) /* xp */,
1139 "WSAStringToAddress() gave length %d, expected at least %d\n", len
, sizeof(sockaddr
) );
1141 for (i
= 0; i
< 2; i
++)
1143 for (j
= 0; j
< ARRAY_SIZE(ipv4_tests
); j
++)
1145 len
= sizeof(sockaddr
) + 10;
1146 expected_len
= ipv4_tests
[j
].error
? len
: sizeof(sockaddr
);
1147 memset( &sockaddr
, 0xab, sizeof(sockaddr
) );
1149 WSASetLastError( 0 );
1152 ret
= WSAStringToAddressA( ipv4_tests
[j
].input
, AF_INET
, NULL
, (SOCKADDR
*)&sockaddr
, &len
);
1156 MultiByteToWideChar( CP_ACP
, 0, ipv4_tests
[j
].input
, -1, inputW
, ARRAY_SIZE(inputW
) );
1157 ret
= WSAStringToAddressW( inputW
, AF_INET
, NULL
, (SOCKADDR
*)&sockaddr
, &len
);
1159 expected_ret
= ipv4_tests
[j
].error
? SOCKET_ERROR
: 0;
1160 expected_family
= ipv4_tests
[j
].error
? 0 : AF_INET
;
1161 ok( ret
== expected_ret
,
1162 "WSAStringToAddress(%s) returned %d, expected %d\n",
1163 wine_dbgstr_a( ipv4_tests
[j
].input
), ret
, expected_ret
);
1164 ok( WSAGetLastError() == ipv4_tests
[j
].error
,
1165 "WSAStringToAddress(%s) gave error %d, expected %d\n",
1166 wine_dbgstr_a( ipv4_tests
[j
].input
), WSAGetLastError(), ipv4_tests
[j
].error
);
1167 ok( sockaddr
.sin_family
== expected_family
,
1168 "WSAStringToAddress(%s) gave family %d, expected %d\n",
1169 wine_dbgstr_a( ipv4_tests
[j
].input
), sockaddr
.sin_family
, expected_family
);
1170 ok( sockaddr
.sin_addr
.s_addr
== ipv4_tests
[j
].address
,
1171 "WSAStringToAddress(%s) gave address %08x, expected %08x\n",
1172 wine_dbgstr_a( ipv4_tests
[j
].input
), sockaddr
.sin_addr
.s_addr
, ipv4_tests
[j
].address
);
1173 ok( sockaddr
.sin_port
== ipv4_tests
[j
].port
,
1174 "WSAStringToAddress(%s) gave port %04x, expected %04x\n",
1175 wine_dbgstr_a( ipv4_tests
[j
].input
), sockaddr
.sin_port
, ipv4_tests
[j
].port
);
1176 ok( len
== expected_len
,
1177 "WSAStringToAddress(%s) gave length %d, expected %d\n",
1178 wine_dbgstr_a( ipv4_tests
[j
].input
), len
, expected_len
);
1181 for (j
= 0; j
< ARRAY_SIZE(ipv6_tests
); j
++)
1183 len
= sizeof(sockaddr6
) + 10;
1184 expected_len
= ipv6_tests
[j
].error
? len
: sizeof(sockaddr6
);
1185 memset( &sockaddr6
, 0xab, sizeof(sockaddr6
) );
1187 WSASetLastError( 0 );
1190 ret
= WSAStringToAddressA( ipv6_tests
[j
].input
, AF_INET6
, NULL
, (SOCKADDR
*)&sockaddr6
, &len
);
1194 MultiByteToWideChar( CP_ACP
, 0, ipv6_tests
[j
].input
, -1, inputW
, ARRAY_SIZE(inputW
) );
1195 ret
= WSAStringToAddressW( inputW
, AF_INET6
, NULL
, (SOCKADDR
*)&sockaddr6
, &len
);
1197 if (j
== 0 && ret
== SOCKET_ERROR
)
1199 win_skip("IPv6 not supported\n");
1202 expected_ret
= ipv6_tests
[j
].error
? SOCKET_ERROR
: 0;
1203 expected_family
= ipv6_tests
[j
].error
? 0 : AF_INET6
;
1204 ok( ret
== expected_ret
,
1205 "WSAStringToAddress(%s) returned %d, expected %d\n",
1206 wine_dbgstr_a( ipv6_tests
[j
].input
), ret
, expected_ret
);
1207 ok( WSAGetLastError() == ipv6_tests
[j
].error
,
1208 "WSAStringToAddress(%s) gave error %d, expected %d\n",
1209 wine_dbgstr_a( ipv6_tests
[j
].input
), WSAGetLastError(), ipv6_tests
[j
].error
);
1210 ok( sockaddr6
.sin6_family
== expected_family
,
1211 "WSAStringToAddress(%s) gave family %d, expected %d\n",
1212 wine_dbgstr_a( ipv4_tests
[j
].input
), sockaddr6
.sin6_family
, expected_family
);
1213 ok( memcmp(&sockaddr6
.sin6_addr
, ipv6_tests
[j
].address
, sizeof(sockaddr6
.sin6_addr
)) == 0,
1214 "WSAStringToAddress(%s) gave address %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n",
1215 wine_dbgstr_a( ipv6_tests
[j
].input
),
1216 sockaddr6
.sin6_addr
.s6_words
[0], sockaddr6
.sin6_addr
.s6_words
[1],
1217 sockaddr6
.sin6_addr
.s6_words
[2], sockaddr6
.sin6_addr
.s6_words
[3],
1218 sockaddr6
.sin6_addr
.s6_words
[4], sockaddr6
.sin6_addr
.s6_words
[5],
1219 sockaddr6
.sin6_addr
.s6_words
[6], sockaddr6
.sin6_addr
.s6_words
[7],
1220 ipv6_tests
[j
].address
[0], ipv6_tests
[j
].address
[1],
1221 ipv6_tests
[j
].address
[2], ipv6_tests
[j
].address
[3],
1222 ipv6_tests
[j
].address
[4], ipv6_tests
[j
].address
[5],
1223 ipv6_tests
[j
].address
[6], ipv6_tests
[j
].address
[7] );
1224 ok( sockaddr6
.sin6_scope_id
== 0,
1225 "WSAStringToAddress(%s) gave scope %d, expected 0\n",
1226 wine_dbgstr_a( ipv6_tests
[j
].input
), sockaddr6
.sin6_scope_id
);
1227 ok( sockaddr6
.sin6_port
== ipv6_tests
[j
].port
,
1228 "WSAStringToAddress(%s) gave port %04x, expected %04x\n",
1229 wine_dbgstr_a( ipv6_tests
[j
].input
), sockaddr6
.sin6_port
, ipv6_tests
[j
].port
);
1230 ok( sockaddr6
.sin6_flowinfo
== 0,
1231 "WSAStringToAddress(%s) gave flowinfo %d, expected 0\n",
1232 wine_dbgstr_a( ipv6_tests
[j
].input
), sockaddr6
.sin6_flowinfo
);
1233 ok( len
== expected_len
,
1234 "WSAStringToAddress(%s) gave length %d, expected %d\n",
1235 wine_dbgstr_a( ipv6_tests
[j
].input
), len
, expected_len
);
1240 static void test_inet_addr(void)
1244 addr
= inet_addr(NULL
);
1245 ok(addr
== INADDR_NONE
, "inet_addr succeeded unexpectedly\n");
1248 /* Tests used in both getaddrinfo and GetAddrInfoW */
1249 static const struct addr_hint_tests
1251 int family
, socktype
, protocol
;
1256 {AF_UNSPEC
, SOCK_STREAM
, IPPROTO_TCP
, 0},
1257 {AF_UNSPEC
, SOCK_STREAM
, IPPROTO_UDP
, 0},
1258 {AF_UNSPEC
, SOCK_STREAM
, IPPROTO_IPV6
,0},
1259 {AF_UNSPEC
, SOCK_DGRAM
, IPPROTO_TCP
, 0},
1260 {AF_UNSPEC
, SOCK_DGRAM
, IPPROTO_UDP
, 0},
1261 {AF_UNSPEC
, SOCK_DGRAM
, IPPROTO_IPV6
,0},
1262 {AF_INET
, SOCK_STREAM
, IPPROTO_TCP
, 0},
1263 {AF_INET
, SOCK_STREAM
, IPPROTO_UDP
, 0},
1264 {AF_INET
, SOCK_STREAM
, IPPROTO_IPV6
,0},
1265 {AF_INET
, SOCK_DGRAM
, IPPROTO_TCP
, 0},
1266 {AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, 0},
1267 {AF_INET
, SOCK_DGRAM
, IPPROTO_IPV6
,0},
1268 {AF_UNSPEC
, 0, IPPROTO_TCP
, 0},
1269 {AF_UNSPEC
, 0, IPPROTO_UDP
, 0},
1270 {AF_UNSPEC
, 0, IPPROTO_IPV6
,0},
1271 {AF_UNSPEC
, SOCK_STREAM
, 0, 0},
1272 {AF_UNSPEC
, SOCK_DGRAM
, 0, 0},
1273 {AF_INET
, 0, IPPROTO_TCP
, 0},
1274 {AF_INET
, 0, IPPROTO_UDP
, 0},
1275 {AF_INET
, 0, IPPROTO_IPV6
,0},
1276 {AF_INET
, SOCK_STREAM
, 0, 0},
1277 {AF_INET
, SOCK_DGRAM
, 0, 0},
1278 {AF_UNSPEC
, 999, IPPROTO_TCP
, WSAESOCKTNOSUPPORT
},
1279 {AF_UNSPEC
, 999, IPPROTO_UDP
, WSAESOCKTNOSUPPORT
},
1280 {AF_UNSPEC
, 999, IPPROTO_IPV6
,WSAESOCKTNOSUPPORT
},
1281 {AF_INET
, 999, IPPROTO_TCP
, WSAESOCKTNOSUPPORT
},
1282 {AF_INET
, 999, IPPROTO_UDP
, WSAESOCKTNOSUPPORT
},
1283 {AF_INET
, 999, IPPROTO_IPV6
,WSAESOCKTNOSUPPORT
},
1284 {AF_UNSPEC
, SOCK_STREAM
, 999, 0},
1285 {AF_UNSPEC
, SOCK_STREAM
, 999, 0},
1286 {AF_INET
, SOCK_DGRAM
, 999, 0},
1287 {AF_INET
, SOCK_DGRAM
, 999, 0},
1290 static void compare_addrinfow(ADDRINFOW
*a
, ADDRINFOW
*b
)
1292 for (; a
&& b
; a
= a
->ai_next
, b
= b
->ai_next
)
1294 ok(a
->ai_flags
== b
->ai_flags
,
1295 "Wrong flags %d != %d\n", a
->ai_flags
, b
->ai_flags
);
1296 ok(a
->ai_family
== b
->ai_family
,
1297 "Wrong family %d != %d\n", a
->ai_family
, b
->ai_family
);
1298 ok(a
->ai_socktype
== b
->ai_socktype
,
1299 "Wrong socktype %d != %d\n", a
->ai_socktype
, b
->ai_socktype
);
1300 ok(a
->ai_protocol
== b
->ai_protocol
,
1301 "Wrong protocol %d != %d\n", a
->ai_protocol
, b
->ai_protocol
);
1302 ok(a
->ai_addrlen
== b
->ai_addrlen
,
1303 "Wrong addrlen %lu != %lu\n", a
->ai_addrlen
, b
->ai_addrlen
);
1304 ok(!memcmp(a
->ai_addr
, b
->ai_addr
, min(a
->ai_addrlen
, b
->ai_addrlen
)),
1305 "Wrong address data\n");
1306 if (a
->ai_canonname
&& b
->ai_canonname
)
1308 ok(!lstrcmpW(a
->ai_canonname
, b
->ai_canonname
), "Wrong canonical name '%s' != '%s'\n",
1309 wine_dbgstr_w(a
->ai_canonname
), wine_dbgstr_w(b
->ai_canonname
));
1312 ok(!a
->ai_canonname
&& !b
->ai_canonname
, "Expected both names absent (%p != %p)\n",
1313 a
->ai_canonname
, b
->ai_canonname
);
1315 ok(!a
&& !b
, "Expected both addresses null (%p != %p)\n", a
, b
);
1318 static void test_GetAddrInfoW(void)
1320 static const WCHAR port
[] = {'8','0',0};
1321 static const WCHAR empty
[] = {0};
1322 static const WCHAR localhost
[] = {'l','o','c','a','l','h','o','s','t',0};
1323 static const WCHAR nxdomain
[] =
1324 {'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
1325 static const WCHAR zero
[] = {'0',0};
1327 ADDRINFOW
*result
, *result2
, *p
, hint
;
1329 DWORD size
= ARRAY_SIZE(name
);
1330 /* te su to.winehq.org written in katakana */
1331 static const WCHAR idn_domain
[] =
1332 {0x30C6,0x30B9,0x30C8,'.','w','i','n','e','h','q','.','o','r','g',0};
1333 static const WCHAR idn_punycode
[] =
1334 {'x','n','-','-','z','c','k','z','a','h','.','w','i','n','e','h','q','.','o','r','g',0};
1336 memset(&hint
, 0, sizeof(ADDRINFOW
));
1338 GetComputerNameExW( ComputerNamePhysicalDnsHostname
, name
, &size
);
1340 result
= (ADDRINFOW
*)0xdeadbeef;
1341 WSASetLastError(0xdeadbeef);
1342 ret
= GetAddrInfoW(NULL
, NULL
, NULL
, &result
);
1343 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1344 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1345 ok(result
== NULL
, "got %p\n", result
);
1348 WSASetLastError(0xdeadbeef);
1349 ret
= GetAddrInfoW(empty
, NULL
, NULL
, &result
);
1350 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1351 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1352 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1353 FreeAddrInfoW(result
);
1356 ret
= GetAddrInfoW(NULL
, zero
, NULL
, &result
);
1357 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1358 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1361 ret
= GetAddrInfoW(NULL
, empty
, NULL
, &result2
);
1362 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1363 ok(result2
!= NULL
, "GetAddrInfoW failed\n");
1364 compare_addrinfow(result
, result2
);
1365 FreeAddrInfoW(result
);
1366 FreeAddrInfoW(result2
);
1369 ret
= GetAddrInfoW(empty
, zero
, NULL
, &result
);
1370 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1371 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1372 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1375 ret
= GetAddrInfoW(empty
, empty
, NULL
, &result2
);
1376 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1377 ok(result2
!= NULL
, "GetAddrInfoW failed\n");
1378 compare_addrinfow(result
, result2
);
1379 FreeAddrInfoW(result
);
1380 FreeAddrInfoW(result2
);
1383 ret
= GetAddrInfoW(localhost
, NULL
, NULL
, &result
);
1384 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1385 FreeAddrInfoW(result
);
1388 ret
= GetAddrInfoW(localhost
, empty
, NULL
, &result
);
1389 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1390 FreeAddrInfoW(result
);
1393 ret
= GetAddrInfoW(localhost
, zero
, NULL
, &result
);
1394 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1395 FreeAddrInfoW(result
);
1398 ret
= GetAddrInfoW(localhost
, port
, NULL
, &result
);
1399 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1400 FreeAddrInfoW(result
);
1403 ret
= GetAddrInfoW(localhost
, NULL
, &hint
, &result
);
1404 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1405 FreeAddrInfoW(result
);
1408 SetLastError(0xdeadbeef);
1409 ret
= GetAddrInfoW(localhost
, port
, &hint
, &result
);
1410 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1411 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1412 FreeAddrInfoW(result
);
1414 /* try to get information from the computer name, result is the same
1415 * as if requesting with an empty host name. */
1416 ret
= GetAddrInfoW(name
, NULL
, NULL
, &result
);
1417 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1418 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1420 ret
= GetAddrInfoW(empty
, NULL
, NULL
, &result2
);
1421 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1422 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1423 compare_addrinfow(result
, result2
);
1424 FreeAddrInfoW(result
);
1425 FreeAddrInfoW(result2
);
1427 ret
= GetAddrInfoW(name
, empty
, NULL
, &result
);
1428 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1429 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1431 ret
= GetAddrInfoW(empty
, empty
, NULL
, &result2
);
1432 ok(!ret
, "GetAddrInfoW failed with %d\n", WSAGetLastError());
1433 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1434 compare_addrinfow(result
, result2
);
1435 FreeAddrInfoW(result
);
1436 FreeAddrInfoW(result2
);
1438 result
= (ADDRINFOW
*)0xdeadbeef;
1439 WSASetLastError(0xdeadbeef);
1440 ret
= GetAddrInfoW(NULL
, NULL
, NULL
, &result
);
1443 skip("nxdomain returned success. Broken ISP redirects?\n");
1446 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1447 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1448 ok(result
== NULL
, "got %p\n", result
);
1450 result
= (ADDRINFOW
*)0xdeadbeef;
1451 WSASetLastError(0xdeadbeef);
1452 ret
= GetAddrInfoW(nxdomain
, NULL
, NULL
, &result
);
1455 skip("nxdomain returned success. Broken ISP redirects?\n");
1458 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1459 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1460 ok(result
== NULL
, "got %p\n", result
);
1462 for (i
= 0; i
< ARRAY_SIZE(hinttests
); i
++)
1464 hint
.ai_family
= hinttests
[i
].family
;
1465 hint
.ai_socktype
= hinttests
[i
].socktype
;
1466 hint
.ai_protocol
= hinttests
[i
].protocol
;
1469 SetLastError(0xdeadbeef);
1470 ret
= GetAddrInfoW(localhost
, NULL
, &hint
, &result
);
1471 todo_wine_if (hinttests
[i
].error
) ok(ret
== hinttests
[i
].error
, "test %d: wrong ret %d\n", i
, ret
);
1474 for (p
= result
; p
; p
= p
->ai_next
)
1476 /* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
1477 if (hinttests
[i
].family
== AF_UNSPEC
)
1478 ok(p
->ai_family
== AF_INET
|| p
->ai_family
== AF_INET6
,
1479 "test %d: expected AF_INET or AF_INET6, got %d\n",
1482 ok(p
->ai_family
== hinttests
[i
].family
,
1483 "test %d: expected family %d, got %d\n",
1484 i
, hinttests
[i
].family
, p
->ai_family
);
1486 ok(p
->ai_socktype
== hinttests
[i
].socktype
,
1487 "test %d: expected type %d, got %d\n",
1488 i
, hinttests
[i
].socktype
, p
->ai_socktype
);
1489 ok(p
->ai_protocol
== hinttests
[i
].protocol
,
1490 "test %d: expected protocol %d, got %d\n",
1491 i
, hinttests
[i
].protocol
, p
->ai_protocol
);
1493 FreeAddrInfoW(result
);
1497 ok(WSAGetLastError() == hinttests
[i
].error
, "test %d: wrong error %d\n", i
, WSAGetLastError());
1501 /* Test IDN resolution (Internationalized Domain Names) present since Windows 8 */
1503 ret
= GetAddrInfoW(idn_punycode
, NULL
, NULL
, &result
);
1504 ok(!ret
, "got %d expected success\n", ret
);
1505 ok(result
!= NULL
, "got %p\n", result
);
1506 FreeAddrInfoW(result
);
1508 hint
.ai_family
= AF_INET
;
1509 hint
.ai_socktype
= 0;
1510 hint
.ai_protocol
= 0;
1514 ret
= GetAddrInfoW(idn_punycode
, NULL
, &hint
, &result
);
1515 ok(!ret
, "got %d expected success\n", ret
);
1516 ok(result
!= NULL
, "got %p\n", result
);
1519 ret
= GetAddrInfoW(idn_domain
, NULL
, NULL
, &result2
);
1520 if (broken(ret
== WSAHOST_NOT_FOUND
))
1522 FreeAddrInfoW(result
);
1523 win_skip("IDN resolution not supported in Win <= 7\n");
1527 ok(!ret
, "got %d expected success\n", ret
);
1528 ok(result2
!= NULL
, "got %p\n", result2
);
1529 FreeAddrInfoW(result2
);
1531 hint
.ai_family
= AF_INET
;
1532 hint
.ai_socktype
= 0;
1533 hint
.ai_protocol
= 0;
1537 ret
= GetAddrInfoW(idn_domain
, NULL
, &hint
, &result2
);
1538 ok(!ret
, "got %d expected success\n", ret
);
1539 ok(result2
!= NULL
, "got %p\n", result2
);
1541 /* ensure manually resolved punycode and unicode hosts result in same data */
1542 compare_addrinfow(result
, result2
);
1544 FreeAddrInfoW(result
);
1545 FreeAddrInfoW(result2
);
1547 hint
.ai_family
= AF_INET
;
1548 hint
.ai_socktype
= 0;
1549 hint
.ai_protocol
= 0;
1553 ret
= GetAddrInfoW(idn_domain
, NULL
, &hint
, &result2
);
1554 ok(!ret
, "got %d expected success\n", ret
);
1555 ok(result2
!= NULL
, "got %p\n", result2
);
1556 FreeAddrInfoW(result2
);
1558 /* Disable IDN resolution and test again*/
1559 hint
.ai_family
= AF_INET
;
1560 hint
.ai_socktype
= 0;
1561 hint
.ai_protocol
= 0;
1562 hint
.ai_flags
= AI_DISABLE_IDN_ENCODING
;
1564 SetLastError(0xdeadbeef);
1566 ret
= GetAddrInfoW(idn_domain
, NULL
, &hint
, &result2
);
1567 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1568 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1569 ok(result2
== NULL
, "got %p\n", result2
);
1572 static struct completion_routine_test
1574 WSAOVERLAPPED
*overlapped
;
1576 ADDRINFOEXW
**result
;
1579 } completion_routine_test
;
1581 static void CALLBACK
completion_routine(DWORD error
, DWORD byte_count
, WSAOVERLAPPED
*overlapped
)
1583 struct completion_routine_test
*test
= &completion_routine_test
;
1585 ok(error
== test
->error
, "got %u\n", error
);
1586 ok(!byte_count
, "got %u\n", byte_count
);
1587 ok(overlapped
== test
->overlapped
, "got %p\n", overlapped
);
1588 ok(overlapped
->Internal
== test
->error
, "got %lu\n", overlapped
->Internal
);
1589 ok(overlapped
->Pointer
== test
->result
, "got %p\n", overlapped
->Pointer
);
1590 ok(overlapped
->hEvent
== NULL
, "got %p\n", overlapped
->hEvent
);
1593 SetEvent(test
->event
);
1596 static void test_GetAddrInfoExW(void)
1598 static const WCHAR empty
[] = {0};
1599 static const WCHAR localhost
[] = {'l','o','c','a','l','h','o','s','t',0};
1600 static const WCHAR winehq
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
1601 static const WCHAR nxdomain
[] = {'n','x','d','o','m','a','i','n','.','w','i','n','e','h','q','.','o','r','g',0};
1602 ADDRINFOEXW
*result
;
1603 OVERLAPPED overlapped
;
1607 if (!pGetAddrInfoExW
|| !pGetAddrInfoExOverlappedResult
)
1609 win_skip("GetAddrInfoExW and/or GetAddrInfoExOverlappedResult not present\n");
1613 event
= WSACreateEvent();
1615 result
= (ADDRINFOEXW
*)0xdeadbeef;
1616 WSASetLastError(0xdeadbeef);
1617 ret
= pGetAddrInfoExW(NULL
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, NULL
, NULL
, NULL
);
1618 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1619 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1620 ok(result
== NULL
, "got %p\n", result
);
1623 WSASetLastError(0xdeadbeef);
1624 ret
= pGetAddrInfoExW(empty
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, NULL
, NULL
, NULL
);
1625 ok(!ret
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1626 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1627 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1628 pFreeAddrInfoExW(result
);
1631 ret
= pGetAddrInfoExW(localhost
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, NULL
, NULL
, NULL
);
1632 ok(!ret
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1633 pFreeAddrInfoExW(result
);
1635 result
= (void *)0xdeadbeef;
1636 memset(&overlapped
, 0xcc, sizeof(overlapped
));
1637 overlapped
.hEvent
= event
;
1639 ret
= pGetAddrInfoExW(localhost
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, NULL
, NULL
);
1640 ok(ret
== ERROR_IO_PENDING
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1641 ok(!result
, "result != NULL\n");
1642 ok(WaitForSingleObject(event
, 1000) == WAIT_OBJECT_0
, "wait failed\n");
1643 ret
= pGetAddrInfoExOverlappedResult(&overlapped
);
1644 ok(!ret
, "overlapped result is %d\n", ret
);
1645 pFreeAddrInfoExW(result
);
1647 result
= (void *)0xdeadbeef;
1648 memset(&overlapped
, 0xcc, sizeof(overlapped
));
1650 overlapped
.hEvent
= event
;
1651 WSASetLastError(0xdeadbeef);
1652 ret
= pGetAddrInfoExW(winehq
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, NULL
, NULL
);
1653 ok(ret
== ERROR_IO_PENDING
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1654 ok(WSAGetLastError() == ERROR_IO_PENDING
, "expected 11001, got %d\n", WSAGetLastError());
1655 ret
= overlapped
.Internal
;
1656 ok(ret
== WSAEINPROGRESS
|| ret
== ERROR_SUCCESS
, "overlapped.Internal = %u\n", ret
);
1657 ok(WaitForSingleObject(event
, 1000) == WAIT_OBJECT_0
, "wait failed\n");
1658 ret
= pGetAddrInfoExOverlappedResult(&overlapped
);
1659 ok(!ret
, "overlapped result is %d\n", ret
);
1660 ok(overlapped
.hEvent
== event
, "hEvent changed %p\n", overlapped
.hEvent
);
1661 ok(overlapped
.Internal
== ERROR_SUCCESS
, "overlapped.Internal = %lx\n", overlapped
.Internal
);
1662 ok(overlapped
.Pointer
== &result
, "overlapped.Pointer != &result\n");
1663 ok(result
!= NULL
, "result == NULL\n");
1664 ok(!result
->ai_blob
, "ai_blob != NULL\n");
1665 ok(!result
->ai_bloblen
, "ai_bloblen != 0\n");
1666 ok(!result
->ai_provider
, "ai_provider = %s\n", wine_dbgstr_guid(result
->ai_provider
));
1667 pFreeAddrInfoExW(result
);
1669 result
= (void *)0xdeadbeef;
1670 memset(&overlapped
, 0xcc, sizeof(overlapped
));
1672 overlapped
.hEvent
= event
;
1673 ret
= pGetAddrInfoExW(NULL
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, NULL
, NULL
);
1675 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1677 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1678 ok(result
== NULL
, "got %p\n", result
);
1679 ret
= WaitForSingleObject(event
, 0);
1680 todo_wine_if(ret
!= WAIT_TIMEOUT
) /* Remove when abowe todo_wines are fixed */
1681 ok(ret
== WAIT_TIMEOUT
, "wait failed\n");
1683 /* event + completion routine */
1684 result
= (void *)0xdeadbeef;
1685 memset(&overlapped
, 0xcc, sizeof(overlapped
));
1686 overlapped
.hEvent
= event
;
1688 ret
= pGetAddrInfoExW(localhost
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, completion_routine
, NULL
);
1689 ok(ret
== WSAEINVAL
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1691 /* completion routine, existing domain */
1692 result
= (void *)0xdeadbeef;
1693 overlapped
.hEvent
= NULL
;
1694 completion_routine_test
.overlapped
= &overlapped
;
1695 completion_routine_test
.error
= ERROR_SUCCESS
;
1696 completion_routine_test
.result
= &result
;
1697 completion_routine_test
.event
= event
;
1698 completion_routine_test
.called
= 0;
1700 ret
= pGetAddrInfoExW(winehq
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, completion_routine
, NULL
);
1701 ok(ret
== ERROR_IO_PENDING
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1702 ok(!result
, "result != NULL\n");
1703 ok(WaitForSingleObject(event
, 1000) == WAIT_OBJECT_0
, "wait failed\n");
1704 ret
= pGetAddrInfoExOverlappedResult(&overlapped
);
1705 ok(!ret
, "overlapped result is %d\n", ret
);
1706 ok(overlapped
.hEvent
== NULL
, "hEvent changed %p\n", overlapped
.hEvent
);
1707 ok(overlapped
.Internal
== ERROR_SUCCESS
, "overlapped.Internal = %lx\n", overlapped
.Internal
);
1708 ok(overlapped
.Pointer
== &result
, "overlapped.Pointer != &result\n");
1709 ok(completion_routine_test
.called
== 1, "got %u\n", completion_routine_test
.called
);
1710 pFreeAddrInfoExW(result
);
1712 /* completion routine, non-existing domain */
1713 result
= (void *)0xdeadbeef;
1714 completion_routine_test
.overlapped
= &overlapped
;
1715 completion_routine_test
.error
= WSAHOST_NOT_FOUND
;
1716 completion_routine_test
.called
= 0;
1718 ret
= pGetAddrInfoExW(nxdomain
, NULL
, NS_DNS
, NULL
, NULL
, &result
, NULL
, &overlapped
, completion_routine
, NULL
);
1719 ok(ret
== ERROR_IO_PENDING
, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
1720 ok(!result
, "result != NULL\n");
1721 ok(WaitForSingleObject(event
, 1000) == WAIT_OBJECT_0
, "wait failed\n");
1722 ret
= pGetAddrInfoExOverlappedResult(&overlapped
);
1723 ok(ret
== WSAHOST_NOT_FOUND
, "overlapped result is %d\n", ret
);
1724 ok(overlapped
.hEvent
== NULL
, "hEvent changed %p\n", overlapped
.hEvent
);
1725 ok(overlapped
.Internal
== WSAHOST_NOT_FOUND
, "overlapped.Internal = %lx\n", overlapped
.Internal
);
1726 ok(overlapped
.Pointer
== &result
, "overlapped.Pointer != &result\n");
1727 ok(completion_routine_test
.called
== 1, "got %u\n", completion_routine_test
.called
);
1728 ok(result
== NULL
, "got %p\n", result
);
1730 WSACloseEvent(event
);
1733 static void verify_ipv6_addrinfo(ADDRINFOA
*result
, const char *expect
)
1735 SOCKADDR_IN6
*sockaddr6
;
1739 ok(result
->ai_family
== AF_INET6
, "ai_family == %d\n", result
->ai_family
);
1740 ok(result
->ai_addrlen
>= sizeof(struct sockaddr_in6
), "ai_addrlen == %d\n", (int)result
->ai_addrlen
);
1741 ok(result
->ai_addr
!= NULL
, "ai_addr == NULL\n");
1743 sockaddr6
= (SOCKADDR_IN6
*)result
->ai_addr
;
1744 ok(sockaddr6
->sin6_family
== AF_INET6
, "ai_addr->sin6_family == %d\n", sockaddr6
->sin6_family
);
1745 ok(sockaddr6
->sin6_port
== 0, "ai_addr->sin6_port == %d\n", sockaddr6
->sin6_port
);
1747 memset(buffer
, 0, sizeof(buffer
));
1748 ret
= p_inet_ntop(AF_INET6
, &sockaddr6
->sin6_addr
, buffer
, sizeof(buffer
));
1749 ok(ret
!= NULL
, "inet_ntop failed (%d)\n", WSAGetLastError());
1750 ok(!strcmp(buffer
, expect
), "ai_addr->sin6_addr == '%s' (expected '%s')\n", buffer
, expect
);
1753 static void compare_addrinfo(ADDRINFO
*a
, ADDRINFO
*b
)
1755 for (; a
&& b
; a
= a
->ai_next
, b
= b
->ai_next
)
1757 ok(a
->ai_flags
== b
->ai_flags
,
1758 "Wrong flags %d != %d\n", a
->ai_flags
, b
->ai_flags
);
1759 ok(a
->ai_family
== b
->ai_family
,
1760 "Wrong family %d != %d\n", a
->ai_family
, b
->ai_family
);
1761 ok(a
->ai_socktype
== b
->ai_socktype
,
1762 "Wrong socktype %d != %d\n", a
->ai_socktype
, b
->ai_socktype
);
1763 ok(a
->ai_protocol
== b
->ai_protocol
,
1764 "Wrong protocol %d != %d\n", a
->ai_protocol
, b
->ai_protocol
);
1765 ok(a
->ai_addrlen
== b
->ai_addrlen
,
1766 "Wrong addrlen %lu != %lu\n", a
->ai_addrlen
, b
->ai_addrlen
);
1767 ok(!memcmp(a
->ai_addr
, b
->ai_addr
, min(a
->ai_addrlen
, b
->ai_addrlen
)),
1768 "Wrong address data\n");
1769 if (a
->ai_canonname
&& b
->ai_canonname
)
1771 ok(!strcmp(a
->ai_canonname
, b
->ai_canonname
), "Wrong canonical name '%s' != '%s'\n",
1772 a
->ai_canonname
, b
->ai_canonname
);
1775 ok(!a
->ai_canonname
&& !b
->ai_canonname
, "Expected both names absent (%p != %p)\n",
1776 a
->ai_canonname
, b
->ai_canonname
);
1778 ok(!a
&& !b
, "Expected both addresses null (%p != %p)\n", a
, b
);
1781 static void test_getaddrinfo(void)
1784 ADDRINFOA
*result
, *result2
, *p
, hint
;
1785 SOCKADDR_IN
*sockaddr
;
1786 CHAR name
[256], *ip
;
1787 DWORD size
= sizeof(name
);
1789 memset(&hint
, 0, sizeof(ADDRINFOA
));
1790 GetComputerNameExA( ComputerNamePhysicalDnsHostname
, name
, &size
);
1792 result
= (ADDRINFOA
*)0xdeadbeef;
1793 WSASetLastError(0xdeadbeef);
1794 ret
= getaddrinfo(NULL
, NULL
, NULL
, &result
);
1795 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1796 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1797 ok(result
== NULL
, "got %p\n", result
);
1800 WSASetLastError(0xdeadbeef);
1801 ret
= getaddrinfo("", NULL
, NULL
, &result
);
1802 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1803 ok(result
!= NULL
, "getaddrinfo failed\n");
1804 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1805 freeaddrinfo(result
);
1808 ret
= getaddrinfo(NULL
, "0", NULL
, &result
);
1809 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1810 ok(result
!= NULL
, "getaddrinfo failed\n");
1813 ret
= getaddrinfo(NULL
, "", NULL
, &result2
);
1814 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1815 ok(result2
!= NULL
, "getaddrinfo failed\n");
1816 compare_addrinfo(result
, result2
);
1817 freeaddrinfo(result
);
1818 freeaddrinfo(result2
);
1821 WSASetLastError(0xdeadbeef);
1822 ret
= getaddrinfo("", "0", NULL
, &result
);
1823 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1824 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1825 ok(result
!= NULL
, "getaddrinfo failed\n");
1828 ret
= getaddrinfo("", "", NULL
, &result2
);
1829 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1830 ok(result2
!= NULL
, "getaddrinfo failed\n");
1831 compare_addrinfo(result
, result2
);
1832 freeaddrinfo(result
);
1833 freeaddrinfo(result2
);
1836 ret
= getaddrinfo("localhost", NULL
, NULL
, &result
);
1837 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1838 freeaddrinfo(result
);
1841 ret
= getaddrinfo("localhost", "", NULL
, &result
);
1842 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1843 freeaddrinfo(result
);
1846 ret
= getaddrinfo("localhost", "0", NULL
, &result
);
1847 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1848 freeaddrinfo(result
);
1851 ret
= getaddrinfo("localhost", "80", NULL
, &result
);
1852 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1853 freeaddrinfo(result
);
1856 ret
= getaddrinfo("localhost", NULL
, &hint
, &result
);
1857 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1858 freeaddrinfo(result
);
1861 WSASetLastError(0xdeadbeef);
1862 ret
= getaddrinfo("localhost", "80", &hint
, &result
);
1863 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1864 ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
1865 freeaddrinfo(result
);
1867 hint
.ai_flags
= AI_NUMERICHOST
;
1868 result
= (void *)0xdeadbeef;
1869 ret
= getaddrinfo("localhost", "80", &hint
, &result
);
1870 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo failed with %d\n", WSAGetLastError());
1871 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected WSAHOST_NOT_FOUND, got %d\n", WSAGetLastError());
1872 ok(!result
, "result = %p\n", result
);
1875 /* try to get information from the computer name, result is the same
1876 * as if requesting with an empty host name. */
1877 ret
= getaddrinfo(name
, NULL
, NULL
, &result
);
1878 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1879 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1881 ret
= getaddrinfo("", NULL
, NULL
, &result2
);
1882 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1883 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1884 compare_addrinfo(result
, result2
);
1885 freeaddrinfo(result
);
1886 freeaddrinfo(result2
);
1888 ret
= getaddrinfo(name
, "", NULL
, &result
);
1889 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1890 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1892 ret
= getaddrinfo("", "", NULL
, &result2
);
1893 ok(!ret
, "getaddrinfo failed with %d\n", WSAGetLastError());
1894 ok(result
!= NULL
, "GetAddrInfoW failed\n");
1895 compare_addrinfo(result
, result2
);
1896 freeaddrinfo(result
);
1897 freeaddrinfo(result2
);
1899 result
= (ADDRINFOA
*)0xdeadbeef;
1900 WSASetLastError(0xdeadbeef);
1901 ret
= getaddrinfo("nxdomain.codeweavers.com", NULL
, NULL
, &result
);
1904 skip("nxdomain returned success. Broken ISP redirects?\n");
1907 ok(ret
== WSAHOST_NOT_FOUND
, "got %d expected WSAHOST_NOT_FOUND\n", ret
);
1908 ok(WSAGetLastError() == WSAHOST_NOT_FOUND
, "expected 11001, got %d\n", WSAGetLastError());
1909 ok(result
== NULL
, "got %p\n", result
);
1911 /* Test IPv4 address conversion */
1913 ret
= getaddrinfo("192.168.1.253", NULL
, NULL
, &result
);
1914 ok(!ret
, "getaddrinfo failed with %d\n", ret
);
1915 ok(result
->ai_family
== AF_INET
, "ai_family == %d\n", result
->ai_family
);
1916 ok(result
->ai_addrlen
>= sizeof(struct sockaddr_in
), "ai_addrlen == %d\n", (int)result
->ai_addrlen
);
1917 ok(result
->ai_addr
!= NULL
, "ai_addr == NULL\n");
1918 sockaddr
= (SOCKADDR_IN
*)result
->ai_addr
;
1919 ok(sockaddr
->sin_family
== AF_INET
, "ai_addr->sin_family == %d\n", sockaddr
->sin_family
);
1920 ok(sockaddr
->sin_port
== 0, "ai_addr->sin_port == %d\n", sockaddr
->sin_port
);
1922 ip
= inet_ntoa(sockaddr
->sin_addr
);
1923 ok(strcmp(ip
, "192.168.1.253") == 0, "sockaddr->ai_addr == '%s'\n", ip
);
1924 freeaddrinfo(result
);
1926 /* Test IPv4 address conversion with port */
1928 hint
.ai_flags
= AI_NUMERICHOST
;
1929 ret
= getaddrinfo("192.168.1.253:1024", NULL
, &hint
, &result
);
1931 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo returned unexpected result: %d\n", ret
);
1932 ok(result
== NULL
, "expected NULL, got %p\n", result
);
1934 /* Test IPv6 address conversion */
1936 SetLastError(0xdeadbeef);
1937 ret
= getaddrinfo("2a00:2039:dead:beef:cafe::6666", NULL
, NULL
, &result
);
1941 ok(!ret
, "getaddrinfo failed with %d\n", ret
);
1942 verify_ipv6_addrinfo(result
, "2a00:2039:dead:beef:cafe::6666");
1943 freeaddrinfo(result
);
1945 /* Test IPv6 address conversion with brackets */
1947 ret
= getaddrinfo("[beef::cafe]", NULL
, NULL
, &result
);
1948 ok(!ret
, "getaddrinfo failed with %d\n", ret
);
1949 verify_ipv6_addrinfo(result
, "beef::cafe");
1950 freeaddrinfo(result
);
1952 /* Test IPv6 address conversion with brackets and hints */
1953 memset(&hint
, 0, sizeof(ADDRINFOA
));
1954 hint
.ai_flags
= AI_NUMERICHOST
;
1955 hint
.ai_family
= AF_INET6
;
1957 ret
= getaddrinfo("[beef::cafe]", NULL
, &hint
, &result
);
1958 ok(!ret
, "getaddrinfo failed with %d\n", ret
);
1959 verify_ipv6_addrinfo(result
, "beef::cafe");
1960 freeaddrinfo(result
);
1962 memset(&hint
, 0, sizeof(ADDRINFOA
));
1963 hint
.ai_flags
= AI_NUMERICHOST
;
1964 hint
.ai_family
= AF_INET
;
1966 ret
= getaddrinfo("[beef::cafe]", NULL
, &hint
, &result
);
1967 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo failed with %d\n", ret
);
1969 /* Test IPv6 address conversion with brackets and port */
1971 ret
= getaddrinfo("[beef::cafe]:10239", NULL
, NULL
, &result
);
1972 ok(!ret
, "getaddrinfo failed with %d\n", ret
);
1973 verify_ipv6_addrinfo(result
, "beef::cafe");
1974 freeaddrinfo(result
);
1976 /* Test IPv6 address conversion with unmatched brackets */
1978 hint
.ai_flags
= AI_NUMERICHOST
;
1979 ret
= getaddrinfo("[beef::cafe", NULL
, &hint
, &result
);
1980 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo failed with %d\n", ret
);
1982 ret
= getaddrinfo("beef::cafe]", NULL
, &hint
, &result
);
1983 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo failed with %d\n", ret
);
1987 ok(ret
== WSAHOST_NOT_FOUND
, "getaddrinfo failed with %d\n", ret
);
1988 win_skip("getaddrinfo does not support IPV6\n");
1993 for (i
= 0; i
< ARRAY_SIZE(hinttests
); i
++)
1995 hint
.ai_family
= hinttests
[i
].family
;
1996 hint
.ai_socktype
= hinttests
[i
].socktype
;
1997 hint
.ai_protocol
= hinttests
[i
].protocol
;
2000 SetLastError(0xdeadbeef);
2001 ret
= getaddrinfo("localhost", NULL
, &hint
, &result
);
2002 todo_wine_if (hinttests
[i
].error
) ok(ret
== hinttests
[i
].error
, "test %d: wrong ret %d\n", i
, ret
);
2005 for (p
= result
; p
; p
= p
->ai_next
)
2007 /* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
2008 if (hinttests
[i
].family
== AF_UNSPEC
)
2009 ok(p
->ai_family
== AF_INET
|| p
->ai_family
== AF_INET6
,
2010 "test %d: expected AF_INET or AF_INET6, got %d\n",
2013 ok(p
->ai_family
== hinttests
[i
].family
,
2014 "test %d: expected family %d, got %d\n",
2015 i
, hinttests
[i
].family
, p
->ai_family
);
2017 ok(p
->ai_socktype
== hinttests
[i
].socktype
,
2018 "test %d: expected type %d, got %d\n",
2019 i
, hinttests
[i
].socktype
, p
->ai_socktype
);
2020 ok(p
->ai_protocol
== hinttests
[i
].protocol
,
2021 "test %d: expected protocol %d, got %d\n",
2022 i
, hinttests
[i
].protocol
, p
->ai_protocol
);
2024 freeaddrinfo(result
);
2028 ok(WSAGetLastError() == hinttests
[i
].error
, "test %d: wrong error %d\n", i
, WSAGetLastError());
2032 memset(&hint
, 0, sizeof(hint
));
2033 ret
= getaddrinfo(NULL
, "nonexistentservice", &hint
, &result
);
2034 ok(ret
== WSATYPE_NOT_FOUND
, "got %d\n", ret
);
2037 static void test_dns(void)
2048 h
= gethostbyname("");
2049 ok(h
!= NULL
, "gethostbyname(\"\") failed with %d\n", h_errno
);
2051 /* Use an address with valid alias names if possible */
2052 h
= gethostbyname("source.winehq.org");
2055 skip("Can't test the hostent structure because gethostbyname failed\n");
2059 /* The returned struct must be allocated in a very strict way. First we need to
2060 * count how many aliases there are because they must be located right after
2061 * the struct hostent size. Knowing the amount of aliases we know the exact
2062 * location of the first IP returned. Rule valid for >= XP, for older OS's
2063 * it's somewhat the opposite. */
2065 if (h
->h_addr_list
== addr
.mem
) /* <= W2K */
2067 win_skip("Skipping hostent tests since this OS is unsupported\n");
2071 ok(h
->h_aliases
== addr
.mem
,
2072 "hostent->h_aliases should be in %p, it is in %p\n", addr
.mem
, h
->h_aliases
);
2074 for (ptr
= h
->h_aliases
, count
= 1; *ptr
; ptr
++) count
++;
2075 addr
.chr
+= sizeof(*ptr
) * count
;
2076 ok(h
->h_addr_list
== addr
.mem
,
2077 "hostent->h_addr_list should be in %p, it is in %p\n", addr
.mem
, h
->h_addr_list
);
2079 for (ptr
= h
->h_addr_list
, count
= 1; *ptr
; ptr
++) count
++;
2081 addr
.chr
+= sizeof(*ptr
) * count
;
2082 ok(h
->h_addr_list
[0] == addr
.mem
,
2083 "hostent->h_addr_list[0] should be in %p, it is in %p\n", addr
.mem
, h
->h_addr_list
[0]);
2086 static void test_gethostbyname(void)
2089 struct in_addr
**addr_list
;
2090 char name
[256], first_ip
[16];
2092 MIB_IPFORWARDTABLE
*routes
= NULL
;
2093 IP_ADAPTER_INFO
*adapters
= NULL
, *k
;
2094 DWORD adap_size
= 0, route_size
= 0;
2095 BOOL found_default
= FALSE
;
2096 BOOL local_ip
= FALSE
;
2098 ret
= gethostname(name
, sizeof(name
));
2099 ok(ret
== 0, "gethostname() call failed: %d\n", WSAGetLastError());
2101 he
= gethostbyname(name
);
2102 ok(he
!= NULL
, "gethostbyname(\"%s\") failed: %d\n", name
, WSAGetLastError());
2103 addr_list
= (struct in_addr
**)he
->h_addr_list
;
2104 strcpy(first_ip
, inet_ntoa(*addr_list
[0]));
2106 if (winetest_debug
> 1) trace("List of local IPs:\n");
2107 for (count
= 0; addr_list
[count
] != NULL
; count
++)
2109 char *ip
= inet_ntoa(*addr_list
[count
]);
2110 if (!strcmp(ip
, "127.0.0.1"))
2112 if (winetest_debug
> 1) trace("%s\n", ip
);
2117 ok(count
== 1, "expected 127.0.0.1 to be the only IP returned\n");
2118 skip("Only the loopback address is present, skipping tests\n");
2122 ret
= GetAdaptersInfo(NULL
, &adap_size
);
2123 ok(ret
== ERROR_BUFFER_OVERFLOW
, "GetAdaptersInfo failed with a different error: %d\n", ret
);
2124 ret
= GetIpForwardTable(NULL
, &route_size
, FALSE
);
2125 ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "GetIpForwardTable failed with a different error: %d\n", ret
);
2127 adapters
= HeapAlloc(GetProcessHeap(), 0, adap_size
);
2128 routes
= HeapAlloc(GetProcessHeap(), 0, route_size
);
2130 ret
= GetAdaptersInfo(adapters
, &adap_size
);
2131 ok(ret
== NO_ERROR
, "GetAdaptersInfo failed, error: %d\n", ret
);
2132 ret
= GetIpForwardTable(routes
, &route_size
, FALSE
);
2133 ok(ret
== NO_ERROR
, "GetIpForwardTable failed, error: %d\n", ret
);
2135 /* This test only has meaning if there is more than one IP configured */
2136 if (adapters
->Next
== NULL
&& count
== 1)
2138 skip("Only one IP is present, skipping tests\n");
2142 for (i
= 0; !found_default
&& i
< routes
->dwNumEntries
; i
++)
2144 /* default route (ip 0.0.0.0) ? */
2145 if (routes
->table
[i
].dwForwardDest
) continue;
2147 for (k
= adapters
; k
!= NULL
; k
= k
->Next
)
2151 if (k
->Index
!= routes
->table
[i
].dwForwardIfIndex
) continue;
2153 /* the first IP returned from gethostbyname must be a default route */
2154 ip
= k
->IpAddressList
.IpAddress
.String
;
2155 if (!strcmp(first_ip
, ip
))
2157 found_default
= TRUE
;
2162 ok(found_default
, "failed to find the first IP from gethostbyname!\n");
2165 HeapFree(GetProcessHeap(), 0, adapters
);
2166 HeapFree(GetProcessHeap(), 0, routes
);
2169 static void test_gethostbyname_hack(void)
2173 static BYTE loopback
[] = {127, 0, 0, 1};
2174 static BYTE magic_loopback
[] = {127, 12, 34, 56};
2177 ret
= gethostname(name
, 256);
2178 ok(ret
== 0, "gethostname() call failed: %d\n", WSAGetLastError());
2180 he
= gethostbyname("localhost");
2181 ok(he
!= NULL
, "gethostbyname(\"localhost\") failed: %d\n", h_errno
);
2182 if (he
->h_length
!= 4)
2184 skip("h_length is %d, not IPv4, skipping test.\n", he
->h_length
);
2187 ok(!memcmp(he
->h_addr_list
[0], loopback
, he
->h_length
),
2188 "gethostbyname(\"localhost\") returned %u.%u.%u.%u\n",
2189 he
->h_addr_list
[0][0], he
->h_addr_list
[0][1], he
->h_addr_list
[0][2],
2190 he
->h_addr_list
[0][3]);
2192 if (!strcmp(name
, "localhost"))
2194 skip("hostname seems to be \"localhost\", skipping test.\n");
2198 he
= gethostbyname(name
);
2199 ok(he
!= NULL
, "gethostbyname(\"%s\") failed: %d\n", name
, h_errno
);
2200 if (he
->h_length
!= 4)
2202 skip("h_length is %d, not IPv4, skipping test.\n", he
->h_length
);
2206 if (he
->h_addr_list
[0][0] == 127)
2208 ok(memcmp(he
->h_addr_list
[0], magic_loopback
, he
->h_length
) == 0,
2209 "gethostbyname(\"%s\") returned %u.%u.%u.%u not 127.12.34.56\n",
2210 name
, he
->h_addr_list
[0][0], he
->h_addr_list
[0][1],
2211 he
->h_addr_list
[0][2], he
->h_addr_list
[0][3]);
2214 gethostbyname("nonexistent.winehq.org");
2215 /* Don't check for the return value, as some braindead ISPs will kindly
2216 * resolve nonexistent host names to addresses of the ISP's spam pages. */
2219 static void test_gethostname(void)
2225 WSASetLastError(0xdeadbeef);
2226 ret
= gethostname(NULL
, 256);
2227 ok(ret
== -1, "gethostname() returned %d\n", ret
);
2228 ok(WSAGetLastError() == WSAEFAULT
, "gethostname with null buffer "
2229 "failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT
);
2231 ret
= gethostname(name
, sizeof(name
));
2232 ok(ret
== 0, "gethostname() call failed: %d\n", WSAGetLastError());
2233 he
= gethostbyname(name
);
2234 ok(he
!= NULL
, "gethostbyname(\"%s\") failed: %d\n", name
, WSAGetLastError());
2237 WSASetLastError(0xdeadbeef);
2238 strcpy(name
, "deadbeef");
2239 ret
= gethostname(name
, len
);
2240 ok(ret
== -1, "gethostname() returned %d\n", ret
);
2241 ok(!strcmp(name
, "deadbeef"), "name changed unexpected!\n");
2242 ok(WSAGetLastError() == WSAEFAULT
, "gethostname with insufficient length "
2243 "failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT
);
2246 ret
= gethostname(name
, len
);
2247 ok(ret
== 0, "gethostname() call failed: %d\n", WSAGetLastError());
2248 he
= gethostbyname(name
);
2249 ok(he
!= NULL
, "gethostbyname(\"%s\") failed: %d\n", name
, WSAGetLastError());
2252 static void test_GetHostNameW(void)
2259 win_skip("GetHostNameW() not present\n");
2263 WSASetLastError(0xdeadbeef);
2264 ret
= pGetHostNameW(NULL
, 256);
2265 ok(ret
== -1, "GetHostNameW() returned %d\n", ret
);
2266 ok(WSAGetLastError() == WSAEFAULT
, "GetHostNameW with null buffer "
2267 "failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT
);
2269 ret
= pGetHostNameW(name
, sizeof(name
));
2270 ok(ret
== 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
2273 WSASetLastError(0xdeadbeef);
2274 wcscpy(name
, L
"deadbeef");
2275 ret
= pGetHostNameW(name
, len
);
2276 ok(ret
== -1, "GetHostNameW() returned %d\n", ret
);
2277 ok(!wcscmp(name
, L
"deadbeef"), "name changed unexpected!\n");
2278 ok(WSAGetLastError() == WSAEFAULT
, "GetHostNameW with insufficient length "
2279 "failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT
);
2282 ret
= pGetHostNameW(name
, len
);
2283 ok(ret
== 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
2286 static void test_WSAEnumNameSpaceProvidersA(void)
2288 WSANAMESPACE_INFOA
*name
= NULL
;
2289 DWORD ret
, error
, len
= 0;
2291 SetLastError(0xdeadbeef);
2292 ret
= WSAEnumNameSpaceProvidersA(&len
, name
);
2293 error
= WSAGetLastError();
2295 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2297 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2299 /* Invalid parameter tests */
2300 SetLastError(0xdeadbeef);
2301 ret
= WSAEnumNameSpaceProvidersA(NULL
, name
);
2302 error
= WSAGetLastError();
2304 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2306 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2308 SetLastError(0xdeadbeef);
2309 ret
= WSAEnumNameSpaceProvidersA(NULL
, NULL
);
2310 error
= WSAGetLastError();
2312 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2314 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2316 SetLastError(0xdeadbeef);
2317 ret
= WSAEnumNameSpaceProvidersA(&len
, NULL
);
2318 error
= WSAGetLastError();
2320 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2322 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2324 name
= HeapAlloc(GetProcessHeap(), 0, len
);
2326 ret
= WSAEnumNameSpaceProvidersA(&len
, name
);
2328 ok(ret
> 0, "Expected more than zero name space providers\n");
2330 HeapFree(GetProcessHeap(), 0, name
);
2333 static void test_WSAEnumNameSpaceProvidersW(void)
2335 WSANAMESPACE_INFOW
*name
= NULL
;
2336 DWORD ret
, error
, len
= 0, i
;
2338 SetLastError(0xdeadbeef);
2339 ret
= WSAEnumNameSpaceProvidersW(&len
, name
);
2340 error
= WSAGetLastError();
2342 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2344 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2346 /* Invalid parameter tests */
2347 SetLastError(0xdeadbeef);
2348 ret
= WSAEnumNameSpaceProvidersW(NULL
, name
);
2349 error
= WSAGetLastError();
2351 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2353 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2355 SetLastError(0xdeadbeef);
2356 ret
= WSAEnumNameSpaceProvidersW(NULL
, NULL
);
2357 error
= WSAGetLastError();
2359 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2361 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2363 SetLastError(0xdeadbeef);
2364 ret
= WSAEnumNameSpaceProvidersW(&len
, NULL
);
2365 error
= WSAGetLastError();
2367 ok(ret
== SOCKET_ERROR
, "Expected failure, got %u\n", ret
);
2369 ok(error
== WSAEFAULT
, "Expected 10014, got %u\n", error
);
2371 name
= HeapAlloc(GetProcessHeap(), 0, len
);
2373 ret
= WSAEnumNameSpaceProvidersW(&len
, name
);
2375 ok(ret
> 0, "Expected more than zero name space providers\n");
2377 if (winetest_debug
> 1)
2379 for (i
= 0; i
< ret
; i
++)
2381 trace("Name space Identifier (%p): %s\n", name
[i
].lpszIdentifier
,
2382 wine_dbgstr_w(name
[i
].lpszIdentifier
));
2383 switch (name
[i
].dwNameSpace
)
2386 trace("\tName space ID: NS_DNS (%u)\n", name
[i
].dwNameSpace
);
2389 trace("\tName space ID: NS_NLA (%u)\n", name
[i
].dwNameSpace
);
2392 trace("\tName space ID: Unknown (%u)\n", name
[i
].dwNameSpace
);
2395 trace("\tActive: %d\n", name
[i
].fActive
);
2396 trace("\tVersion: %d\n", name
[i
].dwVersion
);
2400 HeapFree(GetProcessHeap(), 0, name
);
2403 static void test_WSCGetProviderInfo(void)
2407 GUID provider
= {0};
2411 if (!pWSCGetProviderInfo
)
2413 skip("WSCGetProviderInfo is not available.\n");
2417 ret
= pWSCGetProviderInfo(NULL
, -1, NULL
, NULL
, 0, NULL
);
2418 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2420 errcode
= 0xdeadbeef;
2421 ret
= pWSCGetProviderInfo(NULL
, ProviderInfoLspCategories
, info
, &len
, 0, &errcode
);
2422 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2423 ok(errcode
== WSAEFAULT
, "got %d, expected WSAEFAULT\n", errcode
);
2425 errcode
= 0xdeadbeef;
2426 ret
= pWSCGetProviderInfo(&provider
, -1, info
, &len
, 0, &errcode
);
2427 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2428 ok(errcode
== WSANO_RECOVERY
, "got %d, expected WSANO_RECOVERY\n", errcode
);
2430 errcode
= 0xdeadbeef;
2431 ret
= pWSCGetProviderInfo(&provider
, ProviderInfoLspCategories
, NULL
, &len
, 0, &errcode
);
2432 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2433 ok(errcode
== WSANO_RECOVERY
, "got %d, expected WSANO_RECOVERY\n", errcode
);
2435 errcode
= 0xdeadbeef;
2436 ret
= pWSCGetProviderInfo(&provider
, ProviderInfoLspCategories
, info
, NULL
, 0, &errcode
);
2437 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2438 ok(errcode
== WSANO_RECOVERY
, "got %d, expected WSANO_RECOVERY\n", errcode
);
2440 errcode
= 0xdeadbeef;
2441 ret
= pWSCGetProviderInfo(&provider
, ProviderInfoLspCategories
, info
, &len
, 0, &errcode
);
2442 ok(ret
== SOCKET_ERROR
, "got %d, expected SOCKET_ERROR\n", ret
);
2443 ok(errcode
== WSANO_RECOVERY
, "got %d, expected WSANO_RECOVERY\n", errcode
);
2446 static void test_WSCGetProviderPath(void)
2448 GUID provider
= {0};
2452 ret
= WSCGetProviderPath(NULL
, NULL
, NULL
, NULL
);
2453 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2455 ret
= WSCGetProviderPath(&provider
, NULL
, NULL
, NULL
);
2456 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2458 ret
= WSCGetProviderPath(NULL
, buffer
, NULL
, NULL
);
2459 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2462 ret
= WSCGetProviderPath(NULL
, NULL
, &len
, NULL
);
2463 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2464 ok(len
== -1, "Got unexpected len %d.\n", len
);
2467 ret
= WSCGetProviderPath(NULL
, NULL
, NULL
, &err
);
2468 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2469 ok(err
== WSAEFAULT
, "Got unexpected error %d.\n", err
);
2472 ret
= WSCGetProviderPath(&provider
, NULL
, NULL
, &err
);
2473 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2474 ok(err
== WSAEFAULT
, "Got unexpected error %d.\n", err
);
2478 ret
= WSCGetProviderPath(&provider
, NULL
, &len
, &err
);
2479 ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2480 ok(err
== WSAEINVAL
, "Got unexpected error %d.\n", err
);
2481 ok(len
== -1, "Got unexpected len %d.\n", len
);
2485 ret
= WSCGetProviderPath(&provider
, NULL
, &len
, &err
);
2486 todo_wine
ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2487 todo_wine
ok(err
== WSAEINVAL
, "Got unexpected error %d.\n", err
);
2488 ok(len
== 256, "Got unexpected len %d.\n", len
);
2490 /* Valid pointers and length but invalid GUID */
2493 ret
= WSCGetProviderPath(&provider
, buffer
, &len
, &err
);
2494 todo_wine
ok(ret
== SOCKET_ERROR
, "Got unexpected ret %d.\n", ret
);
2495 todo_wine
ok(err
== WSAEINVAL
, "Got unexpected error %d.\n", err
);
2496 ok(len
== 256, "Got unexpected len %d.\n", len
);
2499 START_TEST( protocol
)
2502 WORD version
= MAKEWORD( 2, 2 );
2504 pFreeAddrInfoExW
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "FreeAddrInfoExW");
2505 pGetAddrInfoExOverlappedResult
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetAddrInfoExOverlappedResult");
2506 pGetAddrInfoExW
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetAddrInfoExW");
2507 pGetHostNameW
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetHostNameW");
2508 p_inet_ntop
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "inet_ntop");
2509 pInetNtopW
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "InetNtopW");
2510 p_inet_pton
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "inet_pton");
2511 pInetPtonW
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "InetPtonW");
2512 pWSCGetProviderInfo
= (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "WSCGetProviderInfo");
2514 if (WSAStartup( version
, &data
)) return;
2516 test_WSAEnumProtocolsA();
2517 test_WSAEnumProtocolsW();
2518 test_getprotobyname();
2519 test_getprotobynumber();
2521 test_getservbyname();
2522 test_WSALookupService();
2523 test_WSAAsyncGetServByPort();
2524 test_WSAAsyncGetServByName();
2528 test_addr_to_print();
2529 test_WSAAddressToString();
2530 test_WSAStringToAddress();
2533 test_GetAddrInfoW();
2534 test_GetAddrInfoExW();
2538 test_gethostbyname();
2539 test_gethostbyname_hack();
2541 test_GetHostNameW();
2543 test_WSAEnumNameSpaceProvidersA();
2544 test_WSAEnumNameSpaceProvidersW();
2545 test_WSCGetProviderInfo();
2546 test_WSCGetProviderPath();