ws2_32/tests: Move address lookup tests to protocol.c.

sock.c is huge. This doesn't bother some people, but I find that it can be
harder to navigate and slower to compile. Splitting it is tricky, but I think
there's a pretty natural divide between functions that operate on sockets
(e.g. bind, listen, recv, getsockname) and functions that don't (e.g.
get*info, inet_*, get*by*, WSC*).

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-04-28 16:26:30 -05:00 committed by Alexandre Julliard
parent 02e3327f06
commit edd9ef9c27
2 changed files with 808 additions and 806 deletions

View File

@ -23,9 +23,18 @@
#include <windef.h>
#include <winbase.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include "wine/test.h"
static void (WINAPI *pFreeAddrInfoExW)(ADDRINFOEXW *ai);
static int (WINAPI *pGetAddrInfoExW)(const WCHAR *name, const WCHAR *servname, DWORD namespace,
GUID *namespace_id, const ADDRINFOEXW *hints, ADDRINFOEXW **result,
struct timeval *timeout, OVERLAPPED *overlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine, HANDLE *handle);
static int (WINAPI *pGetAddrInfoExOverlappedResult)(OVERLAPPED *overlapped);
static const char *(WINAPI *p_inet_ntop)(int family, void *addr, char *string, ULONG size);
/* TCP and UDP over IP fixed set of service flags */
#define TCPIP_SERVICE_FLAGS (XP1_GUARANTEED_DELIVERY \
| XP1_GUARANTEED_ORDER \
@ -290,15 +299,813 @@ static void test_getprotobynumber(void)
}
}
/* Tests used in both getaddrinfo and GetAddrInfoW */
static const struct addr_hint_tests
{
int family, socktype, protocol;
DWORD error;
}
hinttests[] =
{
{AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0},
{AF_UNSPEC, SOCK_STREAM, IPPROTO_UDP, 0},
{AF_UNSPEC, SOCK_STREAM, IPPROTO_IPV6,0},
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_TCP, 0},
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, 0},
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_IPV6,0},
{AF_INET, SOCK_STREAM, IPPROTO_TCP, 0},
{AF_INET, SOCK_STREAM, IPPROTO_UDP, 0},
{AF_INET, SOCK_STREAM, IPPROTO_IPV6,0},
{AF_INET, SOCK_DGRAM, IPPROTO_TCP, 0},
{AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0},
{AF_INET, SOCK_DGRAM, IPPROTO_IPV6,0},
{AF_UNSPEC, 0, IPPROTO_TCP, 0},
{AF_UNSPEC, 0, IPPROTO_UDP, 0},
{AF_UNSPEC, 0, IPPROTO_IPV6,0},
{AF_UNSPEC, SOCK_STREAM, 0, 0},
{AF_UNSPEC, SOCK_DGRAM, 0, 0},
{AF_INET, 0, IPPROTO_TCP, 0},
{AF_INET, 0, IPPROTO_UDP, 0},
{AF_INET, 0, IPPROTO_IPV6,0},
{AF_INET, SOCK_STREAM, 0, 0},
{AF_INET, SOCK_DGRAM, 0, 0},
{AF_UNSPEC, 999, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
{AF_UNSPEC, 999, IPPROTO_UDP, WSAESOCKTNOSUPPORT},
{AF_UNSPEC, 999, IPPROTO_IPV6,WSAESOCKTNOSUPPORT},
{AF_INET, 999, IPPROTO_TCP, WSAESOCKTNOSUPPORT},
{AF_INET, 999, IPPROTO_UDP, WSAESOCKTNOSUPPORT},
{AF_INET, 999, IPPROTO_IPV6,WSAESOCKTNOSUPPORT},
{AF_UNSPEC, SOCK_STREAM, 999, 0},
{AF_UNSPEC, SOCK_STREAM, 999, 0},
{AF_INET, SOCK_DGRAM, 999, 0},
{AF_INET, SOCK_DGRAM, 999, 0},
};
static void compare_addrinfow(ADDRINFOW *a, ADDRINFOW *b)
{
for (; a && b; a = a->ai_next, b = b->ai_next)
{
ok(a->ai_flags == b->ai_flags,
"Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
ok(a->ai_family == b->ai_family,
"Wrong family %d != %d\n", a->ai_family, b->ai_family);
ok(a->ai_socktype == b->ai_socktype,
"Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
ok(a->ai_protocol == b->ai_protocol,
"Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
ok(a->ai_addrlen == b->ai_addrlen,
"Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
"Wrong address data\n");
if (a->ai_canonname && b->ai_canonname)
{
ok(!lstrcmpW(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
wine_dbgstr_w(a->ai_canonname), wine_dbgstr_w(b->ai_canonname));
}
else
ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
a->ai_canonname, b->ai_canonname);
}
ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
}
static void test_GetAddrInfoW(void)
{
static const WCHAR port[] = {'8','0',0};
static const WCHAR empty[] = {0};
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR nxdomain[] =
{'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
static const WCHAR zero[] = {'0',0};
int i, ret;
ADDRINFOW *result, *result2, *p, hint;
WCHAR name[256];
DWORD size = ARRAY_SIZE(name);
/* te su to.winehq.org written in katakana */
static const WCHAR idn_domain[] =
{0x30C6,0x30B9,0x30C8,'.','w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR idn_punycode[] =
{'x','n','-','-','z','c','k','z','a','h','.','w','i','n','e','h','q','.','o','r','g',0};
memset(&hint, 0, sizeof(ADDRINFOW));
name[0] = 0;
GetComputerNameExW( ComputerNamePhysicalDnsHostname, name, &size );
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(empty, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(NULL, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
result2 = NULL;
ret = GetAddrInfoW(NULL, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = NULL;
ret = GetAddrInfoW(empty, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
result2 = NULL;
ret = GetAddrInfoW(empty, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = NULL;
ret = GetAddrInfoW(localhost, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, empty, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, port, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, NULL, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
SetLastError(0xdeadbeef);
ret = GetAddrInfoW(localhost, port, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
FreeAddrInfoW(result);
/* try to get information from the computer name, result is the same
* as if requesting with an empty host name. */
ret = GetAddrInfoW(name, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = GetAddrInfoW(empty, NULL, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
ret = GetAddrInfoW(name, empty, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = GetAddrInfoW(empty, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(NULL, NULL, NULL, &result);
if (ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(nxdomain, NULL, NULL, &result);
if (ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
for (i = 0; i < ARRAY_SIZE(hinttests); i++)
{
hint.ai_family = hinttests[i].family;
hint.ai_socktype = hinttests[i].socktype;
hint.ai_protocol = hinttests[i].protocol;
result = NULL;
SetLastError(0xdeadbeef);
ret = GetAddrInfoW(localhost, NULL, &hint, &result);
todo_wine_if (hinttests[i].error) ok(ret == hinttests[i].error, "test %d: wrong ret %d\n", i, ret);
if (!ret)
{
for (p = result; p; p = p->ai_next)
{
/* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
if (hinttests[i].family == AF_UNSPEC)
ok(p->ai_family == AF_INET || p->ai_family == AF_INET6,
"test %d: expected AF_INET or AF_INET6, got %d\n",
i, p->ai_family);
else
ok(p->ai_family == hinttests[i].family,
"test %d: expected family %d, got %d\n",
i, hinttests[i].family, p->ai_family);
ok(p->ai_socktype == hinttests[i].socktype,
"test %d: expected type %d, got %d\n",
i, hinttests[i].socktype, p->ai_socktype);
ok(p->ai_protocol == hinttests[i].protocol,
"test %d: expected protocol %d, got %d\n",
i, hinttests[i].protocol, p->ai_protocol);
}
FreeAddrInfoW(result);
}
else
{
ok(WSAGetLastError() == hinttests[i].error, "test %d: wrong error %d\n", i, WSAGetLastError());
}
}
/* Test IDN resolution (Internationalized Domain Names) present since Windows 8 */
result = NULL;
ret = GetAddrInfoW(idn_punycode, NULL, NULL, &result);
ok(!ret, "got %d expected success\n", ret);
ok(result != NULL, "got %p\n", result);
FreeAddrInfoW(result);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result = NULL;
ret = GetAddrInfoW(idn_punycode, NULL, &hint, &result);
ok(!ret, "got %d expected success\n", ret);
ok(result != NULL, "got %p\n", result);
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, NULL, &result2);
if (broken(ret == WSAHOST_NOT_FOUND))
{
FreeAddrInfoW(result);
win_skip("IDN resolution not supported in Win <= 7\n");
return;
}
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
FreeAddrInfoW(result2);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
/* ensure manually resolved punycode and unicode hosts result in same data */
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
FreeAddrInfoW(result2);
/* Disable IDN resolution and test again*/
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = AI_DISABLE_IDN_ENCODING;
SetLastError(0xdeadbeef);
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result2 == NULL, "got %p\n", result2);
}
static struct completion_routine_test
{
WSAOVERLAPPED *overlapped;
DWORD error;
ADDRINFOEXW **result;
HANDLE event;
DWORD called;
} completion_routine_test;
static void CALLBACK completion_routine(DWORD error, DWORD byte_count, WSAOVERLAPPED *overlapped)
{
struct completion_routine_test *test = &completion_routine_test;
ok(error == test->error, "got %u\n", error);
ok(!byte_count, "got %u\n", byte_count);
ok(overlapped == test->overlapped, "got %p\n", overlapped);
ok(overlapped->Internal == test->error, "got %lu\n", overlapped->Internal);
ok(overlapped->Pointer == test->result, "got %p\n", overlapped->Pointer);
ok(overlapped->hEvent == NULL, "got %p\n", overlapped->hEvent);
test->called++;
SetEvent(test->event);
}
static void test_GetAddrInfoExW(void)
{
static const WCHAR empty[] = {0};
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR winehq[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR nxdomain[] = {'n','x','d','o','m','a','i','n','.','w','i','n','e','h','q','.','o','r','g',0};
ADDRINFOEXW *result;
OVERLAPPED overlapped;
HANDLE event;
int ret;
if (!pGetAddrInfoExW || !pGetAddrInfoExOverlappedResult)
{
win_skip("GetAddrInfoExW and/or GetAddrInfoExOverlappedResult not present\n");
return;
}
event = WSACreateEvent();
result = (ADDRINFOEXW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(NULL, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(empty, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(!ret, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pFreeAddrInfoExW(result);
result = NULL;
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(!ret, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
pFreeAddrInfoExW(result);
result = (void *)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
overlapped.hEvent = event;
ResetEvent(event);
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
pFreeAddrInfoExW(result);
result = (void *)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
ResetEvent(event);
overlapped.hEvent = event;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(winehq, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == ERROR_IO_PENDING, "expected 11001, got %d\n", WSAGetLastError());
ret = overlapped.Internal;
ok(ret == WSAEINPROGRESS || ret == ERROR_SUCCESS, "overlapped.Internal = %u\n", ret);
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == event, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == ERROR_SUCCESS, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(result != NULL, "result == NULL\n");
ok(!result->ai_blob, "ai_blob != NULL\n");
ok(!result->ai_bloblen, "ai_bloblen != 0\n");
ok(!result->ai_provider, "ai_provider = %s\n", wine_dbgstr_guid(result->ai_provider));
pFreeAddrInfoExW(result);
result = (void *)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
ResetEvent(event);
overlapped.hEvent = event;
ret = pGetAddrInfoExW(NULL, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
todo_wine
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
todo_wine
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
ret = WaitForSingleObject(event, 0);
todo_wine_if(ret != WAIT_TIMEOUT) /* Remove when abowe todo_wines are fixed */
ok(ret == WAIT_TIMEOUT, "wait failed\n");
/* event + completion routine */
result = (void *)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
overlapped.hEvent = event;
ResetEvent(event);
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == WSAEINVAL, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
/* completion routine, existing domain */
result = (void *)0xdeadbeef;
overlapped.hEvent = NULL;
completion_routine_test.overlapped = &overlapped;
completion_routine_test.error = ERROR_SUCCESS;
completion_routine_test.result = &result;
completion_routine_test.event = event;
completion_routine_test.called = 0;
ResetEvent(event);
ret = pGetAddrInfoExW(winehq, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == NULL, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == ERROR_SUCCESS, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(completion_routine_test.called == 1, "got %u\n", completion_routine_test.called);
pFreeAddrInfoExW(result);
/* completion routine, non-existing domain */
result = (void *)0xdeadbeef;
completion_routine_test.overlapped = &overlapped;
completion_routine_test.error = WSAHOST_NOT_FOUND;
completion_routine_test.called = 0;
ResetEvent(event);
ret = pGetAddrInfoExW(nxdomain, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(ret == WSAHOST_NOT_FOUND, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == NULL, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == WSAHOST_NOT_FOUND, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(completion_routine_test.called == 1, "got %u\n", completion_routine_test.called);
ok(result == NULL, "got %p\n", result);
WSACloseEvent(event);
}
static void verify_ipv6_addrinfo(ADDRINFOA *result, const char *expect)
{
SOCKADDR_IN6 *sockaddr6;
char buffer[256];
const char *ret;
ok(result->ai_family == AF_INET6, "ai_family == %d\n", result->ai_family);
ok(result->ai_addrlen >= sizeof(struct sockaddr_in6), "ai_addrlen == %d\n", (int)result->ai_addrlen);
ok(result->ai_addr != NULL, "ai_addr == NULL\n");
sockaddr6 = (SOCKADDR_IN6 *)result->ai_addr;
ok(sockaddr6->sin6_family == AF_INET6, "ai_addr->sin6_family == %d\n", sockaddr6->sin6_family);
ok(sockaddr6->sin6_port == 0, "ai_addr->sin6_port == %d\n", sockaddr6->sin6_port);
memset(buffer, 0, sizeof(buffer));
ret = p_inet_ntop(AF_INET6, &sockaddr6->sin6_addr, buffer, sizeof(buffer));
ok(ret != NULL, "inet_ntop failed (%d)\n", WSAGetLastError());
ok(!strcmp(buffer, expect), "ai_addr->sin6_addr == '%s' (expected '%s')\n", buffer, expect);
}
static void compare_addrinfo(ADDRINFO *a, ADDRINFO *b)
{
for (; a && b ; a = a->ai_next, b = b->ai_next)
{
ok(a->ai_flags == b->ai_flags,
"Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
ok(a->ai_family == b->ai_family,
"Wrong family %d != %d\n", a->ai_family, b->ai_family);
ok(a->ai_socktype == b->ai_socktype,
"Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
ok(a->ai_protocol == b->ai_protocol,
"Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
ok(a->ai_addrlen == b->ai_addrlen,
"Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
"Wrong address data\n");
if (a->ai_canonname && b->ai_canonname)
{
ok(!strcmp(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
a->ai_canonname, b->ai_canonname);
}
else
ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
a->ai_canonname, b->ai_canonname);
}
ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
}
static void test_getaddrinfo(void)
{
int i, ret;
ADDRINFOA *result, *result2, *p, hint;
SOCKADDR_IN *sockaddr;
CHAR name[256], *ip;
DWORD size = sizeof(name);
memset(&hint, 0, sizeof(ADDRINFOA));
GetComputerNameExA( ComputerNamePhysicalDnsHostname, name, &size );
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo(NULL, "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
result2 = NULL;
ret = getaddrinfo(NULL, "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "getaddrinfo failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("", "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
result2 = NULL;
ret = getaddrinfo("", "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "getaddrinfo failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = NULL;
ret = getaddrinfo("localhost", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "80", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", NULL, &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("localhost", "80", &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
freeaddrinfo(result);
hint.ai_flags = AI_NUMERICHOST;
result = (void *)0xdeadbeef;
ret = getaddrinfo("localhost", "80", &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected WSAHOST_NOT_FOUND, got %d\n", WSAGetLastError());
ok(!result, "result = %p\n", result);
hint.ai_flags = 0;
/* try to get information from the computer name, result is the same
* as if requesting with an empty host name. */
ret = getaddrinfo(name, NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = getaddrinfo("", NULL, NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
ret = getaddrinfo(name, "", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = getaddrinfo("", "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("nxdomain.codeweavers.com", NULL, NULL, &result);
if (ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
/* Test IPv4 address conversion */
result = NULL;
ret = getaddrinfo("192.168.1.253", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
ok(result->ai_family == AF_INET, "ai_family == %d\n", result->ai_family);
ok(result->ai_addrlen >= sizeof(struct sockaddr_in), "ai_addrlen == %d\n", (int)result->ai_addrlen);
ok(result->ai_addr != NULL, "ai_addr == NULL\n");
sockaddr = (SOCKADDR_IN *)result->ai_addr;
ok(sockaddr->sin_family == AF_INET, "ai_addr->sin_family == %d\n", sockaddr->sin_family);
ok(sockaddr->sin_port == 0, "ai_addr->sin_port == %d\n", sockaddr->sin_port);
ip = inet_ntoa(sockaddr->sin_addr);
ok(strcmp(ip, "192.168.1.253") == 0, "sockaddr->ai_addr == '%s'\n", ip);
freeaddrinfo(result);
/* Test IPv4 address conversion with port */
result = NULL;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo("192.168.1.253:1024", NULL, &hint, &result);
hint.ai_flags = 0;
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo returned unexpected result: %d\n", ret);
ok(result == NULL, "expected NULL, got %p\n", result);
/* Test IPv6 address conversion */
result = NULL;
SetLastError(0xdeadbeef);
ret = getaddrinfo("2a00:2039:dead:beef:cafe::6666", NULL, NULL, &result);
if (result != NULL)
{
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "2a00:2039:dead:beef:cafe::6666");
freeaddrinfo(result);
/* Test IPv6 address conversion with brackets */
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
/* Test IPv6 address conversion with brackets and hints */
memset(&hint, 0, sizeof(ADDRINFOA));
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET6;
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
memset(&hint, 0, sizeof(ADDRINFOA));
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET;
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
/* Test IPv6 address conversion with brackets and port */
result = NULL;
ret = getaddrinfo("[beef::cafe]:10239", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
/* Test IPv6 address conversion with unmatched brackets */
result = NULL;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo("[beef::cafe", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
ret = getaddrinfo("beef::cafe]", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
}
else
{
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
win_skip("getaddrinfo does not support IPV6\n");
}
hint.ai_flags = 0;
for (i = 0; i < ARRAY_SIZE(hinttests); i++)
{
hint.ai_family = hinttests[i].family;
hint.ai_socktype = hinttests[i].socktype;
hint.ai_protocol = hinttests[i].protocol;
result = NULL;
SetLastError(0xdeadbeef);
ret = getaddrinfo("localhost", NULL, &hint, &result);
todo_wine_if (hinttests[i].error) ok(ret == hinttests[i].error, "test %d: wrong ret %d\n", i, ret);
if (!ret)
{
for (p = result; p; p = p->ai_next)
{
/* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
if (hinttests[i].family == AF_UNSPEC)
ok(p->ai_family == AF_INET || p->ai_family == AF_INET6,
"test %d: expected AF_INET or AF_INET6, got %d\n",
i, p->ai_family);
else
ok(p->ai_family == hinttests[i].family,
"test %d: expected family %d, got %d\n",
i, hinttests[i].family, p->ai_family);
ok(p->ai_socktype == hinttests[i].socktype,
"test %d: expected type %d, got %d\n",
i, hinttests[i].socktype, p->ai_socktype);
ok(p->ai_protocol == hinttests[i].protocol,
"test %d: expected protocol %d, got %d\n",
i, hinttests[i].protocol, p->ai_protocol);
}
freeaddrinfo(result);
}
else
{
ok(WSAGetLastError() == hinttests[i].error, "test %d: wrong error %d\n", i, WSAGetLastError());
}
}
memset(&hint, 0, sizeof(hint));
ret = getaddrinfo(NULL, "nonexistentservice", &hint, &result);
ok(ret == WSATYPE_NOT_FOUND, "got %d\n", ret);
}
START_TEST( protocol )
{
WSADATA data;
WORD version = MAKEWORD( 2, 2 );
pFreeAddrInfoExW = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "FreeAddrInfoExW");
pGetAddrInfoExOverlappedResult = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetAddrInfoExOverlappedResult");
pGetAddrInfoExW = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "GetAddrInfoExW");
p_inet_ntop = (void *)GetProcAddress(GetModuleHandleA("ws2_32"), "inet_ntop");
if (WSAStartup( version, &data )) return;
test_WSAEnumProtocolsA();
test_WSAEnumProtocolsW();
test_getprotobyname();
test_getprotobynumber();
test_GetAddrInfoW();
test_GetAddrInfoExW();
test_getaddrinfo();
}

View File

@ -65,12 +65,6 @@
k.keepaliveinterval = interval;
/* Function pointers */
static void (WINAPI *pFreeAddrInfoExW)(ADDRINFOEXW *ai);
static int (WINAPI *pGetAddrInfoExW)(const WCHAR *name, const WCHAR *servname, DWORD namespace,
GUID *namespace_id, const ADDRINFOEXW *hints, ADDRINFOEXW **result,
struct timeval *timeout, OVERLAPPED *overlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE completion_routine, HANDLE *handle);
static int (WINAPI *pGetAddrInfoExOverlappedResult)(OVERLAPPED *overlapped);
static int (WINAPI *pGetHostNameW)(WCHAR *, int);
static PCSTR (WINAPI *pInetNtop)(INT,LPVOID,LPSTR,ULONG);
static PCWSTR(WINAPI *pInetNtopW)(INT,LPVOID,LPWSTR,ULONG);
@ -163,46 +157,6 @@ typedef struct select_thread_params
BOOL ReadKilled;
} select_thread_params;
/* Tests used in both getaddrinfo and GetAddrInfoW */
static const struct addr_hint_tests
{
int family, socktype, protocol;
DWORD error;
} hinttests[] = {
{AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0 },
{AF_UNSPEC, SOCK_STREAM, IPPROTO_UDP, 0 },
{AF_UNSPEC, SOCK_STREAM, IPPROTO_IPV6,0 },
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_TCP, 0 },
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, 0 },
{AF_UNSPEC, SOCK_DGRAM, IPPROTO_IPV6,0 },
{AF_INET, SOCK_STREAM, IPPROTO_TCP, 0 },
{AF_INET, SOCK_STREAM, IPPROTO_UDP, 0 },
{AF_INET, SOCK_STREAM, IPPROTO_IPV6,0 },
{AF_INET, SOCK_DGRAM, IPPROTO_TCP, 0 },
{AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0 },
{AF_INET, SOCK_DGRAM, IPPROTO_IPV6,0 },
{AF_UNSPEC, 0, IPPROTO_TCP, 0 },
{AF_UNSPEC, 0, IPPROTO_UDP, 0 },
{AF_UNSPEC, 0, IPPROTO_IPV6,0 },
{AF_UNSPEC, SOCK_STREAM, 0, 0 },
{AF_UNSPEC, SOCK_DGRAM, 0, 0 },
{AF_INET, 0, IPPROTO_TCP, 0 },
{AF_INET, 0, IPPROTO_UDP, 0 },
{AF_INET, 0, IPPROTO_IPV6,0 },
{AF_INET, SOCK_STREAM, 0, 0 },
{AF_INET, SOCK_DGRAM, 0, 0 },
{AF_UNSPEC, 999, IPPROTO_TCP, WSAESOCKTNOSUPPORT },
{AF_UNSPEC, 999, IPPROTO_UDP, WSAESOCKTNOSUPPORT },
{AF_UNSPEC, 999, IPPROTO_IPV6,WSAESOCKTNOSUPPORT },
{AF_INET, 999, IPPROTO_TCP, WSAESOCKTNOSUPPORT },
{AF_INET, 999, IPPROTO_UDP, WSAESOCKTNOSUPPORT },
{AF_INET, 999, IPPROTO_IPV6,WSAESOCKTNOSUPPORT },
{AF_UNSPEC, SOCK_STREAM, 999, 0 },
{AF_UNSPEC, SOCK_STREAM, 999, 0 },
{AF_INET, SOCK_DGRAM, 999, 0 },
{AF_INET, SOCK_DGRAM, 999, 0 },
};
/**************** Static variables ***************/
static DWORD tls; /* Thread local storage index */
@ -390,62 +344,6 @@ static void check_so_opentype (void)
ok ( tmp == 0, "check_so_opentype: wrong startup value of SO_OPENTYPE: %d\n", tmp );
}
static void compare_addrinfo (ADDRINFO *a, ADDRINFO *b)
{
for (; a && b ; a = a->ai_next, b = b->ai_next)
{
ok(a->ai_flags == b->ai_flags,
"Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
ok(a->ai_family == b->ai_family,
"Wrong family %d != %d\n", a->ai_family, b->ai_family);
ok(a->ai_socktype == b->ai_socktype,
"Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
ok(a->ai_protocol == b->ai_protocol,
"Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
ok(a->ai_addrlen == b->ai_addrlen,
"Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
"Wrong address data\n");
if (a->ai_canonname && b->ai_canonname)
{
ok(!strcmp(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
a->ai_canonname, b->ai_canonname);
}
else
ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
a->ai_canonname, b->ai_canonname);
}
ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
}
static void compare_addrinfow (ADDRINFOW *a, ADDRINFOW *b)
{
for (; a && b ; a = a->ai_next, b = b->ai_next)
{
ok(a->ai_flags == b->ai_flags,
"Wrong flags %d != %d\n", a->ai_flags, b->ai_flags);
ok(a->ai_family == b->ai_family,
"Wrong family %d != %d\n", a->ai_family, b->ai_family);
ok(a->ai_socktype == b->ai_socktype,
"Wrong socktype %d != %d\n", a->ai_socktype, b->ai_socktype);
ok(a->ai_protocol == b->ai_protocol,
"Wrong protocol %d != %d\n", a->ai_protocol, b->ai_protocol);
ok(a->ai_addrlen == b->ai_addrlen,
"Wrong addrlen %lu != %lu\n", a->ai_addrlen, b->ai_addrlen);
ok(!memcmp(a->ai_addr, b->ai_addr, min(a->ai_addrlen, b->ai_addrlen)),
"Wrong address data\n");
if (a->ai_canonname && b->ai_canonname)
{
ok(!lstrcmpW(a->ai_canonname, b->ai_canonname), "Wrong canonical name '%s' != '%s'\n",
wine_dbgstr_w(a->ai_canonname), wine_dbgstr_w(b->ai_canonname));
}
else
ok(!a->ai_canonname && !b->ai_canonname, "Expected both names absent (%p != %p)\n",
a->ai_canonname, b->ai_canonname);
}
ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
}
/**************** Server utility functions ***************/
/*
@ -1201,9 +1099,6 @@ static void Init (void)
WSADATA data;
HMODULE hws2_32 = GetModuleHandleA("ws2_32.dll"), ntdll;
pFreeAddrInfoExW = (void *)GetProcAddress(hws2_32, "FreeAddrInfoExW");
pGetAddrInfoExW = (void *)GetProcAddress(hws2_32, "GetAddrInfoExW");
pGetAddrInfoExOverlappedResult = (void *)GetProcAddress(hws2_32, "GetAddrInfoExOverlappedResult");
pGetHostNameW = (void *)GetProcAddress(hws2_32, "GetHostNameW");
pInetNtop = (void *)GetProcAddress(hws2_32, "inet_ntop");
pInetNtopW = (void *)GetProcAddress(hws2_32, "InetNtopW");
@ -6537,703 +6432,6 @@ todo_wine
#undef POLL_ISSET
#undef POLL_CLEAR
static void test_GetAddrInfoW(void)
{
static const WCHAR port[] = {'8','0',0};
static const WCHAR empty[] = {0};
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR nxdomain[] =
{'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
static const WCHAR zero[] = {'0',0};
int i, ret;
ADDRINFOW *result, *result2, *p, hint;
WCHAR name[256];
DWORD size = ARRAY_SIZE(name);
/* te su to.winehq.org written in katakana */
static const WCHAR idn_domain[] =
{0x30C6,0x30B9,0x30C8,'.','w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR idn_punycode[] =
{'x','n','-','-','z','c','k','z','a','h','.','w','i','n','e','h','q','.','o','r','g',0};
memset(&hint, 0, sizeof(ADDRINFOW));
name[0] = 0;
GetComputerNameExW( ComputerNamePhysicalDnsHostname, name, &size );
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(empty, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(NULL, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
result2 = NULL;
ret = GetAddrInfoW(NULL, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = NULL;
ret = GetAddrInfoW(empty, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
result2 = NULL;
ret = GetAddrInfoW(empty, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = NULL;
ret = GetAddrInfoW(localhost, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, empty, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, port, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
ret = GetAddrInfoW(localhost, NULL, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
FreeAddrInfoW(result);
result = NULL;
SetLastError(0xdeadbeef);
ret = GetAddrInfoW(localhost, port, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
FreeAddrInfoW(result);
/* try to get information from the computer name, result is the same
* as if requesting with an empty host name. */
ret = GetAddrInfoW(name, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = GetAddrInfoW(empty, NULL, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
ret = GetAddrInfoW(name, empty, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = GetAddrInfoW(empty, empty, NULL, &result2);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(NULL, NULL, NULL, &result);
if(ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = GetAddrInfoW(nxdomain, NULL, NULL, &result);
if(ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
for (i = 0;i < (ARRAY_SIZE(hinttests));i++)
{
hint.ai_family = hinttests[i].family;
hint.ai_socktype = hinttests[i].socktype;
hint.ai_protocol = hinttests[i].protocol;
result = NULL;
SetLastError(0xdeadbeef);
ret = GetAddrInfoW(localhost, NULL, &hint, &result);
todo_wine_if(hinttests[i].error) ok(ret == hinttests[i].error, "test %d: wrong ret %d\n", i, ret);
if(!ret)
{
for (p = result; p; p = p->ai_next)
{
/* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
if (hinttests[i].family == AF_UNSPEC)
ok(p->ai_family == AF_INET || p->ai_family == AF_INET6,
"test %d: expected AF_INET or AF_INET6, got %d\n",
i, p->ai_family);
else
ok(p->ai_family == hinttests[i].family,
"test %d: expected family %d, got %d\n",
i, hinttests[i].family, p->ai_family);
ok(p->ai_socktype == hinttests[i].socktype,
"test %d: expected type %d, got %d\n",
i, hinttests[i].socktype, p->ai_socktype);
ok(p->ai_protocol == hinttests[i].protocol,
"test %d: expected protocol %d, got %d\n",
i, hinttests[i].protocol, p->ai_protocol);
}
FreeAddrInfoW(result);
}
else
{
ok(WSAGetLastError() == hinttests[i].error, "test %d: wrong error %d\n", i, WSAGetLastError());
}
}
/* Test IDN resolution (Internationalized Domain Names) present since Windows 8 */
result = NULL;
ret = GetAddrInfoW(idn_punycode, NULL, NULL, &result);
ok(!ret, "got %d expected success\n", ret);
ok(result != NULL, "got %p\n", result);
FreeAddrInfoW(result);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result = NULL;
ret = GetAddrInfoW(idn_punycode, NULL, &hint, &result);
ok(!ret, "got %d expected success\n", ret);
ok(result != NULL, "got %p\n", result);
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, NULL, &result2);
if (broken(ret == WSAHOST_NOT_FOUND))
{
FreeAddrInfoW(result);
win_skip("IDN resolution not supported in Win <= 7\n");
return;
}
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
FreeAddrInfoW(result2);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
/* ensure manually resolved punycode and unicode hosts result in same data */
compare_addrinfow(result, result2);
FreeAddrInfoW(result);
FreeAddrInfoW(result2);
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = 0;
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(!ret, "got %d expected success\n", ret);
ok(result2 != NULL, "got %p\n", result2);
FreeAddrInfoW(result2);
/* Disable IDN resolution and test again*/
hint.ai_family = AF_INET;
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_flags = AI_DISABLE_IDN_ENCODING;
SetLastError(0xdeadbeef);
result2 = NULL;
ret = GetAddrInfoW(idn_domain, NULL, &hint, &result2);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result2 == NULL, "got %p\n", result2);
}
static struct completion_routine_test
{
WSAOVERLAPPED *overlapped;
DWORD error;
ADDRINFOEXW **result;
HANDLE event;
DWORD called;
} completion_routine_test;
static void CALLBACK completion_routine(DWORD error, DWORD byte_count, WSAOVERLAPPED *overlapped)
{
struct completion_routine_test *test = &completion_routine_test;
ok(error == test->error, "got %u\n", error);
ok(!byte_count, "got %u\n", byte_count);
ok(overlapped == test->overlapped, "got %p\n", overlapped);
ok(overlapped->Internal == test->error, "got %lu\n", overlapped->Internal);
ok(overlapped->Pointer == test->result, "got %p\n", overlapped->Pointer);
ok(overlapped->hEvent == NULL, "got %p\n", overlapped->hEvent);
test->called++;
SetEvent(test->event);
}
static void test_GetAddrInfoExW(void)
{
static const WCHAR empty[] = {0};
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR winehq[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR nxdomain[] = {'n','x','d','o','m','a','i','n','.','w','i','n','e','h','q','.','o','r','g',0};
ADDRINFOEXW *result;
OVERLAPPED overlapped;
HANDLE event;
int ret;
if (!pGetAddrInfoExW || !pGetAddrInfoExOverlappedResult)
{
win_skip("GetAddrInfoExW and/or GetAddrInfoExOverlappedResult not present\n");
return;
}
event = WSACreateEvent();
result = (ADDRINFOEXW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(NULL, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(empty, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(!ret, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pFreeAddrInfoExW(result);
result = NULL;
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, NULL, NULL, NULL);
ok(!ret, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
pFreeAddrInfoExW(result);
result = (void*)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
overlapped.hEvent = event;
ResetEvent(event);
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
pFreeAddrInfoExW(result);
result = (void*)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
ResetEvent(event);
overlapped.hEvent = event;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoExW(winehq, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == ERROR_IO_PENDING, "expected 11001, got %d\n", WSAGetLastError());
ret = overlapped.Internal;
ok(ret == WSAEINPROGRESS || ret == ERROR_SUCCESS, "overlapped.Internal = %u\n", ret);
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == event, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == ERROR_SUCCESS, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(result != NULL, "result == NULL\n");
if (result != NULL)
{
ok(!result->ai_blob, "ai_blob != NULL\n");
ok(!result->ai_bloblen, "ai_bloblen != 0\n");
ok(!result->ai_provider, "ai_provider = %s\n", wine_dbgstr_guid(result->ai_provider));
pFreeAddrInfoExW(result);
}
result = (void*)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
ResetEvent(event);
overlapped.hEvent = event;
ret = pGetAddrInfoExW(NULL, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, NULL, NULL);
todo_wine
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
todo_wine
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
ret = WaitForSingleObject(event, 0);
todo_wine_if(ret != WAIT_TIMEOUT) /* Remove when abowe todo_wines are fixed */
ok(ret == WAIT_TIMEOUT, "wait failed\n");
/* event + completion routine */
result = (void*)0xdeadbeef;
memset(&overlapped, 0xcc, sizeof(overlapped));
overlapped.hEvent = event;
ResetEvent(event);
ret = pGetAddrInfoExW(localhost, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == WSAEINVAL, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
/* completion routine, existing domain */
result = (void *)0xdeadbeef;
overlapped.hEvent = NULL;
completion_routine_test.overlapped = &overlapped;
completion_routine_test.error = ERROR_SUCCESS;
completion_routine_test.result = &result;
completion_routine_test.event = event;
completion_routine_test.called = 0;
ResetEvent(event);
ret = pGetAddrInfoExW(winehq, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(!ret, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == NULL, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == ERROR_SUCCESS, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(completion_routine_test.called == 1, "got %u\n", completion_routine_test.called);
pFreeAddrInfoExW(result);
/* completion routine, non-existing domain */
result = (void *)0xdeadbeef;
completion_routine_test.overlapped = &overlapped;
completion_routine_test.error = WSAHOST_NOT_FOUND;
completion_routine_test.called = 0;
ResetEvent(event);
ret = pGetAddrInfoExW(nxdomain, NULL, NS_DNS, NULL, NULL, &result, NULL, &overlapped, completion_routine, NULL);
ok(ret == ERROR_IO_PENDING, "GetAddrInfoExW failed with %d\n", WSAGetLastError());
ok(!result, "result != NULL\n");
ok(WaitForSingleObject(event, 1000) == WAIT_OBJECT_0, "wait failed\n");
ret = pGetAddrInfoExOverlappedResult(&overlapped);
ok(ret == WSAHOST_NOT_FOUND, "overlapped result is %d\n", ret);
ok(overlapped.hEvent == NULL, "hEvent changed %p\n", overlapped.hEvent);
ok(overlapped.Internal == WSAHOST_NOT_FOUND, "overlapped.Internal = %lx\n", overlapped.Internal);
ok(overlapped.Pointer == &result, "overlapped.Pointer != &result\n");
ok(completion_routine_test.called == 1, "got %u\n", completion_routine_test.called);
ok(result == NULL, "got %p\n", result);
WSACloseEvent(event);
}
static void verify_ipv6_addrinfo(ADDRINFOA *result, const char *expectedIp)
{
SOCKADDR_IN6 *sockaddr6;
char ipBuffer[256];
const char *ret;
ok(result->ai_family == AF_INET6, "ai_family == %d\n", result->ai_family);
ok(result->ai_addrlen >= sizeof(struct sockaddr_in6), "ai_addrlen == %d\n", (int)result->ai_addrlen);
ok(result->ai_addr != NULL, "ai_addr == NULL\n");
if (result->ai_addr != NULL)
{
sockaddr6 = (SOCKADDR_IN6 *)result->ai_addr;
ok(sockaddr6->sin6_family == AF_INET6, "ai_addr->sin6_family == %d\n", sockaddr6->sin6_family);
ok(sockaddr6->sin6_port == 0, "ai_addr->sin6_port == %d\n", sockaddr6->sin6_port);
ZeroMemory(ipBuffer, sizeof(ipBuffer));
ret = pInetNtop(AF_INET6, &sockaddr6->sin6_addr, ipBuffer, sizeof(ipBuffer));
ok(ret != NULL, "inet_ntop failed (%d)\n", WSAGetLastError());
ok(strcmp(ipBuffer, expectedIp) == 0, "ai_addr->sin6_addr == '%s' (expected '%s')\n", ipBuffer, expectedIp);
}
}
static void test_getaddrinfo(void)
{
int i, ret;
ADDRINFOA *result, *result2, *p, hint;
SOCKADDR_IN *sockaddr;
CHAR name[256], *ip;
DWORD size = sizeof(name);
memset(&hint, 0, sizeof(ADDRINFOA));
GetComputerNameExA( ComputerNamePhysicalDnsHostname, name, &size );
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo(NULL, "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
result2 = NULL;
ret = getaddrinfo(NULL, "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "getaddrinfo failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("", "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
result2 = NULL;
ret = getaddrinfo("", "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result2 != NULL, "getaddrinfo failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = NULL;
ret = getaddrinfo("localhost", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", "80", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
ret = getaddrinfo("localhost", NULL, &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
freeaddrinfo(result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("localhost", "80", &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
freeaddrinfo(result);
hint.ai_flags = AI_NUMERICHOST;
result = (void*)0xdeadbeef;
ret = getaddrinfo("localhost", "80", &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected WSAHOST_NOT_FOUND, got %d\n", WSAGetLastError());
ok(!result, "result = %p\n", result);
hint.ai_flags = 0;
/* try to get information from the computer name, result is the same
* as if requesting with an empty host name. */
ret = getaddrinfo(name, NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = getaddrinfo("", NULL, NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
ret = getaddrinfo(name, "", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ret = getaddrinfo("", "", NULL, &result2);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
compare_addrinfo(result, result2);
freeaddrinfo(result);
freeaddrinfo(result2);
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = getaddrinfo("nxdomain.codeweavers.com", NULL, NULL, &result);
if(ret == 0)
{
skip("nxdomain returned success. Broken ISP redirects?\n");
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
/* Test IPv4 address conversion */
result = NULL;
ret = getaddrinfo("192.168.1.253", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
ok(result->ai_family == AF_INET, "ai_family == %d\n", result->ai_family);
ok(result->ai_addrlen >= sizeof(struct sockaddr_in), "ai_addrlen == %d\n", (int)result->ai_addrlen);
ok(result->ai_addr != NULL, "ai_addr == NULL\n");
sockaddr = (SOCKADDR_IN *)result->ai_addr;
ok(sockaddr->sin_family == AF_INET, "ai_addr->sin_family == %d\n", sockaddr->sin_family);
ok(sockaddr->sin_port == 0, "ai_addr->sin_port == %d\n", sockaddr->sin_port);
ip = inet_ntoa(sockaddr->sin_addr);
ok(strcmp(ip, "192.168.1.253") == 0, "sockaddr->ai_addr == '%s'\n", ip);
freeaddrinfo(result);
/* Test IPv4 address conversion with port */
result = NULL;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo("192.168.1.253:1024", NULL, &hint, &result);
hint.ai_flags = 0;
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo returned unexpected result: %d\n", ret);
ok(result == NULL, "expected NULL, got %p\n", result);
/* Test IPv6 address conversion */
result = NULL;
SetLastError(0xdeadbeef);
ret = getaddrinfo("2a00:2039:dead:beef:cafe::6666", NULL, NULL, &result);
if (result != NULL)
{
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "2a00:2039:dead:beef:cafe::6666");
freeaddrinfo(result);
/* Test IPv6 address conversion with brackets */
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
/* Test IPv6 address conversion with brackets and hints */
memset(&hint, 0, sizeof(ADDRINFOA));
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET6;
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
memset(&hint, 0, sizeof(ADDRINFOA));
hint.ai_flags = AI_NUMERICHOST;
hint.ai_family = AF_INET;
result = NULL;
ret = getaddrinfo("[beef::cafe]", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
/* Test IPv6 address conversion with brackets and port */
result = NULL;
ret = getaddrinfo("[beef::cafe]:10239", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", ret);
verify_ipv6_addrinfo(result, "beef::cafe");
freeaddrinfo(result);
/* Test IPv6 address conversion with unmatched brackets */
result = NULL;
hint.ai_flags = AI_NUMERICHOST;
ret = getaddrinfo("[beef::cafe", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
ret = getaddrinfo("beef::cafe]", NULL, &hint, &result);
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
}
else
{
ok(ret == WSAHOST_NOT_FOUND, "getaddrinfo failed with %d\n", ret);
win_skip("getaddrinfo does not support IPV6\n");
}
hint.ai_flags = 0;
for (i = 0;i < (ARRAY_SIZE(hinttests));i++)
{
hint.ai_family = hinttests[i].family;
hint.ai_socktype = hinttests[i].socktype;
hint.ai_protocol = hinttests[i].protocol;
result = NULL;
SetLastError(0xdeadbeef);
ret = getaddrinfo("localhost", NULL, &hint, &result);
todo_wine_if(hinttests[i].error) ok(ret == hinttests[i].error, "test %d: wrong ret %d\n", i, ret);
if(!ret)
{
for (p = result; p; p = p->ai_next)
{
/* when AF_UNSPEC is used the return will be either AF_INET or AF_INET6 */
if (hinttests[i].family == AF_UNSPEC)
ok(p->ai_family == AF_INET || p->ai_family == AF_INET6,
"test %d: expected AF_INET or AF_INET6, got %d\n",
i, p->ai_family);
else
ok(p->ai_family == hinttests[i].family,
"test %d: expected family %d, got %d\n",
i, hinttests[i].family, p->ai_family);
ok(p->ai_socktype == hinttests[i].socktype,
"test %d: expected type %d, got %d\n",
i, hinttests[i].socktype, p->ai_socktype);
ok(p->ai_protocol == hinttests[i].protocol,
"test %d: expected protocol %d, got %d\n",
i, hinttests[i].protocol, p->ai_protocol);
}
freeaddrinfo(result);
}
else
{
ok(WSAGetLastError() == hinttests[i].error, "test %d: wrong error %d\n", i, WSAGetLastError());
}
}
memset(&hint, 0, sizeof(hint));
ret = getaddrinfo(NULL, "nonexistentservice", &hint, &result);
ok(ret == WSATYPE_NOT_FOUND, "got %d\n", ret);
}
static void test_ConnectEx(void)
{
SOCKET listener = INVALID_SOCKET;
@ -10680,9 +9878,6 @@ START_TEST( sock )
test_ipv6only();
test_TransmitFile();
test_GetAddrInfoW();
test_GetAddrInfoExW();
test_getaddrinfo();
test_AcceptEx();
test_ConnectEx();
test_DisconnectEx();