From: "Erich E. Hoover" Subject: [PATCH 5/5] ws2_32: Add an interactive test for interface change notifications (resend 3). Message-Id: Date: Wed, 20 Aug 2014 23:47:41 -0600 This patch is a simple test case for SIO_ADDRESS_LIST_CHANGE, though it requires interactive mode to work (../../../tools/runtest -P wine -p ws2_32_test.exe.so -i sock). When interactive mode is enabled the user must disconnect and reconnect a network interface within the timeout window (10 seconds) to trigger the event notification. From 8c203081a5caad3e7f647b7b267ad60ec026be43 Mon Sep 17 00:00:00 2001 From: "Erich E. Hoover" Date: Thu, 3 Apr 2014 09:26:45 -0600 Subject: ws2_32: Add an interactive test for interface change notifications. --- dlls/ws2_32/tests/sock.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 8a9cbba..385e1c7 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -6644,6 +6644,73 @@ static void test_sioRoutingInterfaceQuery(void) closesocket(sock); } +static void test_sioAddressListChange(void) +{ + struct sockaddr_in bindAddress; + struct in_addr net_address; + WSAOVERLAPPED overlapped; + struct hostent *h; + DWORD num_bytes; + SOCKET sock; + int acount; + int ret; + + if (!winetest_interactive) + { + skip("Cannot test SIO_ADDRESS_LIST_CHANGE, interactive tests must be enabled\n"); + return; + } + + /* Use gethostbyname to find the list of local network interfaces */ + h = gethostbyname(""); + if (!h) + { + skip("Cannot test SIO_ADDRESS_LIST_CHANGE, gethostbyname failed with %u\n", + WSAGetLastError()); + return; + } + for (acount = 0; h->h_addr_list[acount]; acount++); + if (acount == 0) + { + skip("Cannot test SIO_ADDRESS_LIST_CHANGE, test requires a network card.\n"); + return; + } + net_address.s_addr = *(ULONG *) h->h_addr_list[0]; + + /* Bind an overlapped socket to the first found network interface */ + sock = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); + ok(sock != INVALID_SOCKET, "Expected socket to return a valid socket\n"); + if (sock == INVALID_SOCKET) + { + skip("Cannot test SIO_ADDRESS_LIST_CHANGE, socket creation failed with %u\n", + WSAGetLastError()); + return; + } + memset(&bindAddress, 0, sizeof(bindAddress)); + bindAddress.sin_family = AF_INET; + bindAddress.sin_addr.s_addr = net_address.s_addr; + ret = bind(sock, (struct sockaddr*)&bindAddress, sizeof(bindAddress)); + if (ret != 0) + { + skip("Cannot test SIO_ADDRESS_LIST_CHANGE, failed to bind, error %u\n", WSAGetLastError()); + goto end; + } + + /* Wait for address changes, request that the user connect/disconnect an interface */ + memset(&overlapped, 0, sizeof(overlapped)); + overlapped.hEvent = CreateEventA(NULL, FALSE, FALSE, NULL); + ret = WSAIoctl(sock, SIO_ADDRESS_LIST_CHANGE, NULL, 0, NULL, 0, &num_bytes, &overlapped, NULL); + ok(ret == SOCKET_ERROR, "WSAIoctl succeeded unexpectedly\n"); + ok(WSAGetLastError() == WSA_IO_PENDING, "Expected pending last error %d\n", WSAGetLastError()); + trace("Testing socket-based ipv4 address list change notification. Please connect/disconnect or" + " change the ipv4 address of any of the local network interfaces (10 second timeout).\n"); + ret = WaitForSingleObject(overlapped.hEvent, 10000); + ok(ret == WAIT_OBJECT_0, "failed to get overlapped event %u\n", ret); + +end: + closesocket(sock); +} + static void test_synchronous_WSAIoctl(void) { HANDLE previous_port, io_port; @@ -7732,6 +7799,7 @@ START_TEST( sock ) test_ConnectEx(); test_sioRoutingInterfaceQuery(); + test_sioAddressListChange(); test_WSALookupService(); -- 1.7.9.5