Instead of trying to retrieve the fd.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 61 +++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 41 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index f7996410db1..40e4ecb9325 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -396,7 +396,7 @@ static BOOL socket_list_find( SOCKET socket ) }
-static void socket_list_remove(SOCKET socket) +static BOOL socket_list_remove( SOCKET socket ) { unsigned int i;
@@ -406,10 +406,12 @@ static void socket_list_remove(SOCKET socket) if (socket_list[i] == socket) { socket_list[i] = 0; - break; + LeaveCriticalSection( &cs_socket_list ); + return TRUE; } } LeaveCriticalSection(&cs_socket_list); + return FALSE; }
#define WS_MAX_SOCKETS_PER_PROCESS 128 /* reasonable guess */ @@ -584,29 +586,6 @@ static DWORD NtStatusToWSAError( NTSTATUS status ) return NT_SUCCESS(status) ? RtlNtStatusToDosErrorNoTeb(status) : WSAEINVAL; }
-/* set last error code from NT status without mapping WSA errors */ -static inline unsigned int set_error( unsigned int err ) -{ - if (err) - { - err = NtStatusToWSAError( err ); - SetLastError( err ); - } - return err; -} - -static inline int get_sock_fd( SOCKET s, DWORD access, unsigned int *options ) -{ - int fd; - if (set_error( wine_server_handle_to_fd( SOCKET2HANDLE(s), access, &fd, options ) )) - return -1; - return fd; -} - -static inline void release_sock_fd( SOCKET s, int fd ) -{ - close( fd ); -}
struct per_thread_data *get_per_thread_data(void) { @@ -1514,26 +1493,26 @@ int WINAPI WS_bind( SOCKET s, const struct WS_sockaddr *addr, int len )
/*********************************************************************** - * closesocket (WS2_32.3) + * closesocket (ws2_32.3) */ -int WINAPI WS_closesocket(SOCKET s) +int WINAPI WS_closesocket( SOCKET s ) { - int res = SOCKET_ERROR, fd; - if (num_startup) + TRACE( "%#lx\n", s ); + + if (!num_startup) { - fd = get_sock_fd(s, FILE_READ_DATA, NULL); - if (fd >= 0) - { - release_sock_fd(s, fd); - socket_list_remove(s); - if (CloseHandle(SOCKET2HANDLE(s))) - res = 0; - } + SetLastError( WSANOTINITIALISED ); + return -1; } - else - SetLastError(WSANOTINITIALISED); - TRACE("(socket %04lx) -> %d\n", s, res); - return res; + + if (!socket_list_remove( s )) + { + SetLastError( WSAENOTSOCK ); + return -1; + } + + CloseHandle( (HANDLE)s ); + return 0; }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/socket.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 40e4ecb9325..315b211b22c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -733,15 +733,9 @@ static inline BOOL supported_pf(int pf) { case WS_AF_INET: case WS_AF_INET6: - return TRUE; -#ifdef HAS_IPX case WS_AF_IPX: - return TRUE; -#endif -#ifdef HAS_IRDA case WS_AF_IRDA: return TRUE; -#endif default: return FALSE; }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=94857
Your paranoid android.
=== debiant2 (64 bit WoW report) ===
ws2_32: sock.c:1134: Test failed: wait failed, error 258
Zebediah Figura zfigura@codeweavers.com writes:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/ws2_32/socket.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 40e4ecb9325..315b211b22c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -733,15 +733,9 @@ static inline BOOL supported_pf(int pf) { case WS_AF_INET: case WS_AF_INET6:
return TRUE;
-#ifdef HAS_IPX case WS_AF_IPX:
return TRUE;
-#endif -#ifdef HAS_IRDA case WS_AF_IRDA: return TRUE; -#endif default: return FALSE; }
I'm not sure how that would make a difference, since supported_pf() is not used anywhere.
On 8/3/21 4:49 PM, Alexandre Julliard wrote:
Zebediah Figura zfigura@codeweavers.com writes:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/ws2_32/socket.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 40e4ecb9325..315b211b22c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -733,15 +733,9 @@ static inline BOOL supported_pf(int pf) { case WS_AF_INET: case WS_AF_INET6:
return TRUE;
-#ifdef HAS_IPX case WS_AF_IPX:
return TRUE;
-#endif -#ifdef HAS_IRDA case WS_AF_IRDA: return TRUE; -#endif default: return FALSE; }
I'm not sure how that would make a difference, since supported_pf() is not used anywhere.
Oops, you're right. I removed the last user in cd34be062c057f24771c48ce59a6c54a2f2e31b2, which was written after this patch. I'll send a patch to remove the function.
Adapted from RtlIpv4StringToAddress() tests.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/tests/protocol.c | 101 ++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 12 deletions(-)
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index 27ef6ff92aa..b2a933d4f51 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -1093,14 +1093,91 @@ static void test_WSAStringToAddress(void) } ipv4_tests[] = { - { "0.0.0.0", 0 }, - { "127.127.127.127", 0x7f7f7f7f }, - { "255.255.255.255", 0xffffffff }, - { "127.127.127.127:65535", 0x7f7f7f7f, 65535 }, - { "255.255.255.255:65535", 0xffffffff, 65535 }, - { "2001::1", 0xd1070000, 0, WSAEINVAL }, - { "1.2.3.", 0, 0, WSAEINVAL }, - { "", 0, 0, WSAEINVAL }, + { "", 0, 0, WSAEINVAL }, + { " ", 0, 0, WSAEINVAL }, + { "1.1.1.1", 0x01010101 }, + { "0.0.0.0", 0 }, + { "127.127.127.127", 0x7f7f7f7f }, + { "127.127.127.127:", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:123", 0x7f7f7f7f, 123 }, + { "127.127.127.127:65535", 0x7f7f7f7f, 65535 }, + { "127.127.127.127:65537", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127::1", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0xAbCd", 0x7f7f7f7f, 43981 }, + { "127.127.127.127:0XaBcD", 0x7f7f7f7f, 43981 }, + { "127.127.127.127:0x", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0x10000",0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:010", 0x7f7f7f7f, 8 }, + { "127.127.127.127:007", 0x7f7f7f7f, 7 }, + { "127.127.127.127:08", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:008", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0a", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0o10", 0x7f7f7f7f, 0, WSAEINVAL }, + { "127.127.127.127:0b10", 0x7f7f7f7f, 0, WSAEINVAL }, + { "255.255.255.255", 0xffffffff }, + { "255.255.255.255:123", 0xffffffff, 123 }, + { "255.255.255.255:65535", 0xffffffff, 65535 }, + { "255.255.255.256", 0, 0, WSAEINVAL }, + { "a", 0, 0, WSAEINVAL }, + { "1.1.1.0xaA", 0x010101aa }, + { "1.1.1.0XaA", 0x010101aa }, + { "1.1.1.0x", 0, 0, WSAEINVAL }, + { "1.1.1.0xff", 0x010101ff }, + { "1.1.1.0x100", 0, 0, WSAEINVAL }, + { "1.1.1.010", 0x01010108 }, + { "1.1.1.00", 0x01010100 }, + { "1.1.1.007", 0x01010107 }, + { "1.1.1.08", 0, 0, WSAEINVAL }, + { "1.1.1.008", 0x01010100, 0, WSAEINVAL }, + { "1.1.1.0a", 0x01010100, 0, WSAEINVAL }, + { "1.1.1.0o10", 0x01010100, 0, WSAEINVAL }, + { "1.1.1.0b10", 0x01010100, 0, WSAEINVAL }, + { "1.1.1.-2", 0, 0, WSAEINVAL }, + { "1", 0x00000001 }, + { "-1", 0, 0, WSAEINVAL }, + { "1:1", 0x00000001, 1 }, + { "1.2", 0x01000002 }, + { "1.2:1", 0x01000002, 1 }, + { "1000.2000", 0, 0, WSAEINVAL }, + { "1.2.", 0, 0, WSAEINVAL }, + { "1..2", 0, 0, WSAEINVAL }, + { "1...2", 0, 0, WSAEINVAL }, + { "1.2.3", 0x01020003 }, + { "1.2.3.", 0, 0, WSAEINVAL }, + { "1.2.3:1", 0x01020003, 1 }, + { "203569230", 0x0c22384e }, + { "203569230:123", 0x0c22384e, 123 }, + { "2001::1", 0x000007d1, 0, WSAEINVAL }, + { "1.223756", 0x01036a0c }, + { "3.4.756", 0x030402f4 }, + { "756.3.4", 0, 0, WSAEINVAL }, + { "3.756.4", 0, 0, WSAEINVAL }, + { "3.4.756.1", 0, 0, WSAEINVAL }, + { "3.4.65536", 0, 0, WSAEINVAL }, + { "3.4.5.6.7", 0, 0, WSAEINVAL }, + { "3.4.5.+6", 0, 0, WSAEINVAL }, + { " 3.4.5.6", 0, 0, WSAEINVAL }, + { "\t3.4.5.6", 0, 0, WSAEINVAL }, + { "3.4.5.6 ", 0x03040506, 0, WSAEINVAL }, + { "3.4.5.6:7 ", 0x03040506, 0, WSAEINVAL }, + { "3.4.5.6: 7", 0x03040506, 0, WSAEINVAL }, + { "3. 4.5.6", 0, 0, WSAEINVAL }, + { ".", 0, 0, WSAEINVAL }, + { "[0.1.2.3]", 0, 0, WSAEINVAL }, + { "0x00010203", 0x00010203 }, + { "0X00010203", 0x00010203 }, + { "0x00010203:10", 0x00010203, 10 }, + { "0x1234", 0x00001234 }, + { "0x123456789", 0x23456789 }, + { "0x00010Q03", 0x00000010, 0, WSAEINVAL }, + { "x00010203", 0, 0, WSAEINVAL }, + { "1234BEEF", 0x000004d2, 0, WSAEINVAL }, + { "017700000001", 0x7f000001 }, + { "0777", 0x000001ff }, + { "0777:10", 0x000001ff, 10 }, + { "::1", 0, 0, WSAEINVAL }, + { ":1", 0, 0, WSAEINVAL }, }; static struct { @@ -1167,12 +1244,12 @@ static void test_WSAStringToAddress(void) ok( sockaddr.sin_family == expected_family, "WSAStringToAddress(%s) gave family %d, expected %d\n", wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_family, expected_family ); - ok( sockaddr.sin_addr.s_addr == ipv4_tests[j].address, + ok( sockaddr.sin_addr.s_addr == htonl( ipv4_tests[j].address ), "WSAStringToAddress(%s) gave address %08x, expected %08x\n", - wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_addr.s_addr, ipv4_tests[j].address ); - ok( sockaddr.sin_port == ipv4_tests[j].port, + wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_addr.s_addr, htonl( ipv4_tests[j].address) ); + ok( sockaddr.sin_port == htons( ipv4_tests[j].port ), "WSAStringToAddress(%s) gave port %04x, expected %04x\n", - wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_port, ipv4_tests[j].port ); + wine_dbgstr_a( ipv4_tests[j].input ), sockaddr.sin_port, htons( ipv4_tests[j].port ) ); ok( len == expected_len, "WSAStringToAddress(%s) gave length %d, expected %d\n", wine_dbgstr_a( ipv4_tests[j].input ), len, expected_len );
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/tests/protocol.c | 393 ++++++++++++++++++++++++++--------- 1 file changed, 292 insertions(+), 101 deletions(-)
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index b2a933d4f51..e14f5c60762 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -678,64 +678,232 @@ static void test_inet_pton(void) { static const struct { - int family, ret; - DWORD err; - const char *printable, *collapsed, *raw_data; + char input[32]; + int ret; + DWORD addr; } - tests[] = + ipv4_tests[] = { - /* 0 */ - {AF_UNSPEC, -1, WSAEFAULT, NULL, NULL, NULL}, - {AF_INET, -1, WSAEFAULT, NULL, NULL, NULL}, - {AF_INET6, -1, WSAEFAULT, NULL, NULL, NULL}, - {AF_UNSPEC, -1, WSAEAFNOSUPPORT, "127.0.0.1", NULL, NULL}, - {AF_INET, 1, 0, "127.0.0.1", "127.0.0.1", "\x7f\x00\x00\x01"}, - {AF_INET6, 0, 0, "127.0.0.1", "127.0.0.1", NULL}, - {AF_INET, 0, 0, "::1/128", NULL, NULL}, - {AF_INET6, 0, 0, "::1/128", NULL, NULL}, - {AF_UNSPEC, -1, WSAEAFNOSUPPORT, "broken", NULL, NULL}, - {AF_INET, 0, 0, "broken", NULL, NULL}, - /* 10 */ - {AF_INET6, 0, 0, "broken", NULL, NULL}, - {AF_UNSPEC, -1, WSAEAFNOSUPPORT, "177.32.45.20", NULL, NULL}, - {AF_INET, 1, 0, "177.32.45.20", "177.32.45.20", "\xb1\x20\x2d\x14"}, - {AF_INET6, 0, 0, "177.32.45.20", NULL, NULL}, - {AF_INET, 0, 0, "2607:f0d0:1002:51::4", NULL, NULL}, - {AF_INET6, 1, 0, "2607:f0d0:1002:51::4", "2607:f0d0:1002:51::4", - "\x26\x07\xf0\xd0\x10\x02\x00\x51\x00\x00\x00\x00\x00\x00\x00\x04"}, - {AF_INET, 0, 0, "::177.32.45.20", NULL, NULL}, - {AF_INET6, 1, 0, "::177.32.45.20", "::177.32.45.20", - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb1\x20\x2d\x14"}, - {AF_INET, 0, 0, "fe80::0202:b3ff:fe1e:8329", NULL, NULL}, - {AF_INET6, 1, 0, "fe80::0202:b3ff:fe1e:8329", "fe80::202:b3ff:fe1e:8329", - "\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"}, - /* 20 */ - {AF_INET6, 1, 0, "fe80::202:b3ff:fe1e:8329", "fe80::202:b3ff:fe1e:8329", - "\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"}, - {AF_INET, 0, 0, "a", NULL, NULL}, - {AF_INET, 0, 0, "a.b", NULL, NULL}, - {AF_INET, 0, 0, "a.b.c", NULL, NULL}, - {AF_INET, 0, 0, "a.b.c.d", NULL, NULL}, - {AF_INET6, 1, 0, "2001:cdba:0000:0000:0000:0000:3257:9652", "2001:cdba::3257:9652", - "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"}, - {AF_INET6, 1, 0, "2001:cdba::3257:9652", "2001:cdba::3257:9652", - "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"}, - {AF_INET6, 1, 0, "2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652", - "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"}, - {AF_INET, 0, 0, "0x12345678", NULL, NULL}, - {AF_INET6, 0, 0, "::1:2:3:4:5:6:7", NULL, NULL}, /* windows bug */ - /* 30 */ - {AF_INET6, 1, 0, "::5efe:1.2.3.4", "::5efe:1.2.3.4", - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5e\xfe\x01\x02\x03\x04"}, - {AF_INET6, 1, 0, "::ffff:0:1.2.3.4", "::ffff:0:1.2.3.4", - "\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x01\x02\x03\x04"}, + {"", 0, 0xdeadbeef}, + {" ", 0, 0xdeadbeef}, + {"1.1.1.1", 1, 0x01010101}, + {"0.0.0.0", 1, 0x00000000}, + {"127.127.127.255", 1, 0xff7f7f7f}, + {"127.127.127.255:123", 0, 0xff7f7f7f}, + {"127.127.127.256", 0, 0xdeadbeef}, + {"a", 0, 0xdeadbeef}, + {"1.1.1.0xaA", 0, 0xdeadbeef}, + {"1.1.1.0x", 0, 0xdeadbeef}, + {"1.1.1.010", 0, 0xdeadbeef}, + {"1.1.1.00", 0, 0xdeadbeef}, + {"1.1.1.0a", 0, 0x00010101}, + {"1.1.1.0o10", 0, 0x00010101}, + {"1.1.1.0b10", 0, 0x00010101}, + {"1.1.1.-2", 0, 0xdeadbeef}, + {"1", 0, 0xdeadbeef}, + {"1.2", 0, 0xdeadbeef}, + {"1.2.3", 0, 0xdeadbeef}, + {"203569230", 0, 0xdeadbeef}, + {"3.4.5.6.7", 0, 0xdeadbeef}, + {" 3.4.5.6", 0, 0xdeadbeef}, + {"\t3.4.5.6", 0, 0xdeadbeef}, + {"3.4.5.6 ", 0, 0x06050403}, + {"3. 4.5.6", 0, 0xdeadbeef}, + {"[0.1.2.3]", 0, 0xdeadbeef}, + {"0x00010203", 0, 0xdeadbeef}, + {"0x2134", 0, 0xdeadbeef}, + {"1234BEEF", 0, 0xdeadbeef}, + {"017700000001", 0, 0xdeadbeef}, + {"0777", 0, 0xdeadbeef}, + {"2607:f0d0:1002:51::4", 0, 0xdeadbeef}, + {"::177.32.45.20", 0, 0xdeadbeef}, + {"::1/128", 0, 0xdeadbeef}, + {"::1", 0, 0xdeadbeef}, + {":1", 0, 0xdeadbeef}, }; + + static const struct + { + char input[64]; + int ret; + unsigned short addr[8]; + } + ipv6_tests[] = + { + {"0000:0000:0000:0000:0000:0000:0000:0000", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0000:0000:0000:0000:0000:0000:0000:0001", 1, {0, 0, 0, 0, 0, 0, 0, 0x100}}, + {"0:0:0:0:0:0:0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0:0:0:0:0:0:0:1", 1, {0, 0, 0, 0, 0, 0, 0, 0x100}}, + {"0:0:0:0:0:0:0::", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0:0:0:0:0:0:13.1.68.3", 1, {0, 0, 0, 0, 0, 0, 0x10d, 0x344}}, + {"0:0:0:0:0:0::", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0:0:0:0:0::", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0:0:0:0:0:FFFF:129.144.52.38", 1, {0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634}}, + {"0::", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"0:1:2:3:4:5:6:7", 1, {0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700}}, + {"1080:0:0:0:8:800:200c:417a", 1, {0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41}}, + {"0:a:b:c:d:e:f::", 1, {0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xf00, 0}}, + {"1111:2222:3333:4444:5555:6666:123.123.123.123", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b}}, + {"1111:2222:3333:4444:5555:6666:7777:8888", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111:2222:3333:4444:0x5555:6666:7777:8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:x555:6666:7777:8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:0r5555:6666:7777:8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:r5555:6666:7777:8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555:6666:7777::", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0}}, + {"1111:2222:3333:4444:5555:6666::", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0}}, + {"1111:2222:3333:4444:5555:6666::8888", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888}}, + {"1111:2222:3333:4444:5555:6666::7777:8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x7777}}, + {"1111:2222:3333:4444:5555:6666:7777::8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0}}, + {"1111:2222:3333:4444:5555::", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0}}, + {"1111:2222:3333:4444:5555::123.123.123.123", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b}}, + {"1111:2222:3333:4444:5555::0x1.123.123.123", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x100}}, + {"1111:2222:3333:4444:5555::0x88", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800}}, + {"1111:2222:3333:4444:5555::0X88", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800}}, + {"1111:2222:3333:4444:5555::0X", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0}}, + {"1111:2222:3333:4444:5555::0X88:7777", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8800}}, + {"1111:2222:3333:4444:5555::0x8888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888}}, + {"1111:2222:3333:4444:5555::0x80000000", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0xffff}}, + {"1111:2222:3333:4444::5555:0x012345678", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0, 0, 0x5555, 0x7856}}, + {"1111:2222:3333:4444::5555:0x123456789", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0, 0, 0x5555, 0xffff}}, + {"1111:2222:3333:4444:5555:6666:0x12345678", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555:6666:7777:0x80000000", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xffff}}, + {"1111:2222:3333:4444:5555:6666:7777:0x012345678", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x7856}}, + {"1111:2222:3333:4444:5555:6666:7777:0x123456789", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xffff}}, + {"111:222:333:444:555:666:777:0x123456789abcdef0", 0, {0x1101, 0x2202, 0x3303, 0x4404, 0x5505, 0x6606, 0x7707, 0xffff}}, + {"1111:2222:3333:4444:5555::08888", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555::08888::", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555:6666:7777:fffff:", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0xabab}}, + {"1111:2222:3333:4444:5555:6666::fffff:", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555::fffff", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444::fffff", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333::fffff", 0, {0x1111, 0x2222, 0x3333, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555::7777:8888", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888}}, + {"1111:2222:3333:4444:5555::8888", 1, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888}}, + {"1111::", 1, {0x1111, 0, 0, 0, 0, 0, 0, 0}}, + {"1111::123.123.123.123", 1, {0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b}}, + {"1111::3333:4444:5555:6666:123.123.123.123", 1, {0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b}}, + {"1111::3333:4444:5555:6666:7777:8888", 1, {0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111::4444:5555:6666:123.123.123.123", 1, {0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b}}, + {"1111::4444:5555:6666:7777:8888", 1, {0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111::5555:6666:123.123.123.123", 1, {0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b}}, + {"1111::5555:6666:7777:8888", 1, {0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111::6666:123.123.123.123", 1, {0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b}}, + {"1111::6666:7777:8888", 1, {0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888}}, + {"1111::7777:8888", 1, {0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888}}, + {"1111::8888", 1, {0x1111, 0, 0, 0, 0, 0, 0, 0x8888}}, + {"1:2:3:4:5:6:1.2.3.4", 1, {0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403}}, + {"1:2:3:4:5:6:7:8", 1, {0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800}}, + {"1:2:3:4:5:6::", 1, {0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0}}, + {"1:2:3:4:5:6::8", 1, {0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800}}, + {"2001:0000:1234:0000:0000:C1C0:ABCD:0876", 1, {0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608}}, + {"2001:0000:4136:e378:8000:63bf:3fff:fdd2", 1, {0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd}}, + {"2001:0db8:0:0:0:0:1428:57ab", 1, {0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57}}, + {"2001:0db8:1234:ffff:ffff:ffff:ffff:ffff", 1, {0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}}, + {"2001::CE49:7601:2CAD:DFFF:7C94:FFFE", 1, {0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff}}, + {"2001:db8:85a3::8a2e:370:7334", 1, {0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473}}, + {"3ffe:0b00:0000:0000:0001:0000:0000:000a", 1, {0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00}}, + {"::", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::%16", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::/16", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::01234", 0, {0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"::0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:0:0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:0:0:0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:0:0:0:0:0", 1, {0, 0, 0, 0, 0, 0, 0, 0}}, + /* this one and the next one are incorrectly parsed by windows, + it adds one zero too many in front, cutting off the last digit. */ + {"::0:0:0:0:0:0:0", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::0:a:b:c:d:e:f", 0, {0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00}}, + {"::123.123.123.123", 1, {0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b}}, + {"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 1, {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}}, + {"':10.0.0.1", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"-1", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"02001:0000:1234:0000:0000:C1C0:ABCD:0876", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"2001:00000:1234:0000:0000:C1C0:ABCD:0876", 0, {0x120, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"2001:0000:01234:0000:0000:C1C0:ABCD:0876", 0, {0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"2001:0000::01234.0", 0, {0x120, 0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"2001:0::b.0", 0, {0x120, 0, 0, 0, 0, 0, 0, 0xb00}}, + {"2001::0:b.0", 0, {0x120, 0, 0, 0, 0, 0, 0, 0xb00}}, + {"1.2.3.4", 0, {0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1.2.3.4:1111::5555", 0, {0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1.2.3.4::5555", 0, {0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"11112222:3333:4444:5555:6666:1.2.3.4", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"11112222:3333:4444:5555:6666:7777:8888", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"0x1111", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:22223333:4444:5555:6666:1.2.3.4", 0, {0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:22223333:4444:5555:6666:7777:8888", 0, {0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:123456789:4444:5555:6666:7777:8888", 0, {0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:1234567890abcdef0:4444:5555:6666:7777:888", 0, {0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:", 0, {0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:1.2.3.4", 0, {0x1111, 0x2222, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333", 0, {0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111:2222:3333:4444:5555:6666::1.2.3.4", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x100}}, + {"1111:2222:3333:4444:5555:6666:7777:1.2.3.4", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100}}, + {"1111:2222:3333:4444:5555:6666:7777:8888:", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111:2222:3333:4444:5555:6666:7777:8888:9999", 0, {0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888}}, + {"1111:2222:::", 0, {0x1111, 0x2222, 0, 0, 0, 0, 0, 0}}, + {"1111::5555:", 0, {0x1111, 0x5555, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1111::3333:4444:5555:6666:7777::", 0, {0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777}}, + {"1111:2222:::4444:5555:6666:1.2.3.4", 0, {0x1111, 0x2222, 0, 0, 0, 0, 0, 0}}, + {"1111::3333::5555:6666:1.2.3.4", 0, {0x1111, 0, 0, 0, 0, 0, 0, 0x3333}}, + {"12345::6:7:8", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::001.2.3.4", 1, {0x100, 0, 0, 0, 0, 0, 0x201, 0x403}}, + {"1::1.002.3.4", 1, {0x100, 0, 0, 0, 0, 0, 0x201, 0x403}}, + {"1::0001.2.3.4", 0, {0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.0002.3.4", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.256.4", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.4294967296.4", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.18446744073709551616.4", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.256", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.4294967296", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.18446744073709551616", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.300", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.300.", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2::1", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.4::1", 0, {0x100, 0, 0, 0, 0, 0, 0x201, 0x403}}, + {"1::1.", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.3.4", 1, {0x100, 0, 0, 0, 0, 0, 0x201, 0x403}}, + {"1::1.2.3.900", 0, {0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2.300.4", 0, {0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.256.3.4", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.256:3.4", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1.2a.3.4", 0, {0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::256.2.3.4", 0, {0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"1::1a.2.3.4", 0, {0x100, 0, 0, 0, 0, 0, 0, 0x1a00}}, + {"1::2::3", 0, {0x100, 0, 0, 0, 0, 0, 0, 0x200}}, + {"2001:0000:1234: 0000:0000:C1C0:ABCD:0876", 0, {0x120, 0, 0x3412, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", 0, {0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608}}, + {"2001:1:1:1:1:1:255Z255X255Y255", 0, {0x120, 0x100, 0x100, 0x100, 0x100, 0x100, 0xabab, 0xabab}}, + {"2001::FFD3::57ab", 0, {0x120, 0, 0, 0, 0, 0, 0, 0xd3ff}}, + {":", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {":1111:2222:3333:4444:5555:6666:1.2.3.4", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {":1111:2222:3333:4444:5555:6666:7777:8888", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {":1111::", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"::-1", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::12345678", 0, {0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"::123456789", 0, {0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"::1234567890abcdef0", 0, {0, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"::0x80000000", 0, {0, 0, 0, 0, 0, 0, 0, 0xffff}}, + {"::0x012345678", 0, {0, 0, 0, 0, 0, 0, 0, 0x7856}}, + {"::0x123456789", 0, {0, 0, 0, 0, 0, 0, 0, 0xffff}}, + {"::0x1234567890abcdef0", 0, {0, 0, 0, 0, 0, 0, 0, 0xffff}}, + {"::.", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::..", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"::...", 0, {0, 0, 0, 0, 0, 0, 0, 0}}, + {"XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + {"[::]", 0, {0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab}}, + }; + + BYTE buffer[32]; int i, ret; - DWORD err; - char buffer[64],str[64]; - WCHAR printableW[64], collapsedW[64]; - const char *ptr; - const WCHAR *ptrW;
/* inet_ntop and inet_pton became available in Vista and Win2008 */ if (!p_inet_ntop) @@ -744,59 +912,82 @@ static void test_inet_pton(void) return; }
- for (i = 0; i < ARRAY_SIZE(tests); i++) + WSASetLastError(0xdeadbeef); + ret = p_inet_pton(AF_UNSPEC, NULL, buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + + WSASetLastError(0xdeadbeef); + ret = p_inet_pton(AF_INET, NULL, buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + + WSASetLastError(0xdeadbeef); + ret = pInetPtonW(AF_UNSPEC, NULL, buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + + WSASetLastError(0xdeadbeef); + ret = pInetPtonW(AF_INET, NULL, buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + + WSASetLastError(0xdeadbeef); + ret = p_inet_pton(AF_UNSPEC, "127.0.0.1", buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEAFNOSUPPORT, "got error %u\n", WSAGetLastError()); + + WSASetLastError(0xdeadbeef); + ret = p_inet_pton(AF_UNSPEC, "2607:f0d0:1002:51::4", buffer); + ok(ret == -1, "got %d\n", ret); + ok(WSAGetLastError() == WSAEAFNOSUPPORT, "got error %u\n", WSAGetLastError()); + + for (i = 0; i < ARRAY_SIZE(ipv4_tests); ++i) { + WCHAR inputW[32]; + DWORD addr; + WSASetLastError(0xdeadbeef); - ret = p_inet_pton(tests[i].family, tests[i].printable, buffer); - ok(ret == tests[i].ret, "Test [%d]: Expected %d, got %d\n", i, tests[i].ret, ret); - err = WSAGetLastError(); - if (tests[i].ret == -1) - ok(tests[i].err == err, "Test [%d]: Expected 0x%x, got 0x%x\n", i, tests[i].err, err); - else - ok(err == 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i, err); - if (tests[i].ret != 1) continue; - ok(memcmp(buffer, tests[i].raw_data, - tests[i].family == AF_INET ? sizeof(struct in_addr) : sizeof(struct in6_addr)) == 0, - "Test [%d]: Expected binary data differs\n", i); - - /* Test the result from Pton with Ntop */ - strcpy (str, "deadbeef"); - ptr = p_inet_ntop(tests[i].family, buffer, str, sizeof(str)); - ok(ptr != NULL, "Test [%d]: Failed with NULL\n", i); - ok(ptr == str, "Test [%d]: Pointers differ (%p != %p)\n", i, ptr, str); - ok(strcmp(ptr, tests[i].collapsed) == 0, "Test [%d]: Expected '%s', got '%s'\n", - i, tests[i].collapsed, ptr); + addr = 0xdeadbeef; + ret = p_inet_pton(AF_INET, ipv4_tests[i].input, &addr); + ok(ret == ipv4_tests[i].ret, "%s: got %d\n", debugstr_a(ipv4_tests[i].input), ret); + ok(WSAGetLastError() == 0xdeadbeef, "%s: got error %u\n", + debugstr_a(ipv4_tests[i].input), WSAGetLastError()); + ok(addr == ipv4_tests[i].addr, "%s: got addr %#08x\n", debugstr_a(ipv4_tests[i].input), addr); + + MultiByteToWideChar(CP_ACP, 0, ipv4_tests[i].input, -1, inputW, ARRAY_SIZE(inputW)); + WSASetLastError(0xdeadbeef); + addr = 0xdeadbeef; + ret = pInetPtonW(AF_INET, inputW, &addr); + ok(ret == ipv4_tests[i].ret, "%s: got %d\n", debugstr_a(ipv4_tests[i].input), ret); + ok(WSAGetLastError() == (ret ? 0xdeadbeef : WSAEINVAL), "%s: got error %u\n", + debugstr_a(ipv4_tests[i].input), WSAGetLastError()); + ok(addr == ipv4_tests[i].addr, "%s: got addr %#08x\n", debugstr_a(ipv4_tests[i].input), addr); }
- for (i = 0; i < ARRAY_SIZE(tests); i++) + for (i = 0; i < ARRAY_SIZE(ipv6_tests); ++i) { - if (tests[i].printable) - MultiByteToWideChar(CP_ACP, 0, tests[i].printable, -1, printableW, ARRAY_SIZE(printableW)); + unsigned short addr[8]; + WCHAR inputW[64]; + WSASetLastError(0xdeadbeef); - ret = pInetPtonW(tests[i].family, tests[i].printable ? printableW : NULL, buffer); - ok(ret == tests[i].ret, "Test [%d]: Expected %d, got %d\n", i, tests[i].ret, ret); - err = WSAGetLastError(); - if (tests[i].ret == -1) - ok(tests[i].err == err, "Test [%d]: Expected 0x%x, got 0x%x\n", i, tests[i].err, err); - else if (tests[i].ret == 0) - ok(err == WSAEINVAL || broken(err == 0xdeadbeef) /* win2008 */, - "Test [%d]: Expected WSAEINVAL, got 0x%x\n", i, err); - else - ok(err == 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i, err); - if (tests[i].ret != 1) continue; - ok(memcmp(buffer, tests[i].raw_data, - tests[i].family == AF_INET ? sizeof(struct in_addr) : sizeof(struct in6_addr)) == 0, - "Test [%d]: Expected binary data differs\n", i); - - /* Test the result from Pton with Ntop */ - printableW[0] = 0xdead; - ptrW = pInetNtopW(tests[i].family, buffer, printableW, ARRAY_SIZE(printableW)); - ok(ptrW != NULL, "Test [%d]: Failed with NULL\n", i); - ok(ptrW == printableW, "Test [%d]: Pointers differ (%p != %p)\n", i, ptrW, printableW); - - MultiByteToWideChar(CP_ACP, 0, tests[i].collapsed, -1, collapsedW, ARRAY_SIZE(collapsedW)); - ok(!wcscmp(ptrW, collapsedW), "Test [%d]: Expected '%s', got '%s'\n", - i, tests[i].collapsed, wine_dbgstr_w(ptrW)); + memset(addr, 0xab, sizeof(addr)); + ret = p_inet_pton(AF_INET6, ipv6_tests[i].input, addr); + ok(ret == ipv6_tests[i].ret, "%s: got %d\n", debugstr_a(ipv6_tests[i].input), ret); + ok(WSAGetLastError() == 0xdeadbeef, "%s: got error %u\n", + debugstr_a(ipv6_tests[i].input), WSAGetLastError()); + ok(!memcmp(addr, ipv6_tests[i].addr, sizeof(addr)), + "%s: address didn't match\n", debugstr_a(ipv6_tests[i].input)); + + MultiByteToWideChar(CP_ACP, 0, ipv6_tests[i].input, -1, inputW, ARRAY_SIZE(inputW)); + WSASetLastError(0xdeadbeef); + memset(addr, 0xab, sizeof(addr)); + ret = pInetPtonW(AF_INET6, inputW, addr); + ok(ret == ipv6_tests[i].ret, "%s: got %d\n", debugstr_a(ipv6_tests[i].input), ret); + ok(WSAGetLastError() == (ret ? 0xdeadbeef : WSAEINVAL), "%s: got error %u\n", + debugstr_a(ipv6_tests[i].input), WSAGetLastError()); + ok(!memcmp(addr, ipv6_tests[i].addr, sizeof(addr)), + "%s: address didn't match\n", debugstr_a(ipv6_tests[i].input)); } }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/tests/protocol.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index e14f5c60762..0a2e42721af 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -942,6 +942,11 @@ static void test_inet_pton(void) ok(ret == -1, "got %d\n", ret); ok(WSAGetLastError() == WSAEAFNOSUPPORT, "got error %u\n", WSAGetLastError());
+ WSASetLastError(0xdeadbeef); + ret = inet_addr(NULL); + ok(ret == INADDR_NONE, "got %#x\n", ret); + todo_wine ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + for (i = 0; i < ARRAY_SIZE(ipv4_tests); ++i) { WCHAR inputW[32]; @@ -963,6 +968,13 @@ static void test_inet_pton(void) ok(WSAGetLastError() == (ret ? 0xdeadbeef : WSAEINVAL), "%s: got error %u\n", debugstr_a(ipv4_tests[i].input), WSAGetLastError()); ok(addr == ipv4_tests[i].addr, "%s: got addr %#08x\n", debugstr_a(ipv4_tests[i].input), addr); + + WSASetLastError(0xdeadbeef); + addr = inet_addr(ipv4_tests[i].input); + ok(addr == ipv4_tests[i].ret ? ipv4_tests[i].addr : INADDR_NONE, + "%s: got addr %#08x\n", debugstr_a(ipv4_tests[i].input), addr); + ok(WSAGetLastError() == 0xdeadbeef, "%s: got error %u\n", + debugstr_a(ipv4_tests[i].input), WSAGetLastError()); }
for (i = 0; i < ARRAY_SIZE(ipv6_tests); ++i) @@ -1505,14 +1517,6 @@ static void test_WSAStringToAddress(void) } }
-static void test_inet_addr(void) -{ - u_long addr; - - addr = inet_addr(NULL); - ok(addr == INADDR_NONE, "inet_addr succeeded unexpectedly\n"); -} - /* Tests used in both getaddrinfo and GetAddrInfoW */ static const struct addr_hint_tests { @@ -2818,7 +2822,6 @@ START_TEST( protocol ) test_addr_to_print(); test_WSAAddressToString(); test_WSAStringToAddress(); - test_inet_addr();
test_GetAddrInfoW(); test_GetAddrInfoExW();
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/protocol.c | 9 ++++++--- dlls/ws2_32/tests/protocol.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index 15616fdaf34..944f26912e6 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -2025,10 +2025,13 @@ int WINAPI WSAAddressToStringW( struct WS_sockaddr *addr, DWORD addr_len, /*********************************************************************** * inet_addr (ws2_32.11) */ -WS_u_long WINAPI WS_inet_addr( const char *cp ) +WS_u_long WINAPI WS_inet_addr( const char *str ) { - if (!cp) return INADDR_NONE; - return inet_addr( cp ); + WS_u_long addr; + + if (WS_inet_pton( WS_AF_INET, str, &addr ) == 1) + return addr; + return WS_INADDR_NONE; }
diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c index 0a2e42721af..99c78873d9a 100644 --- a/dlls/ws2_32/tests/protocol.c +++ b/dlls/ws2_32/tests/protocol.c @@ -945,7 +945,7 @@ static void test_inet_pton(void) WSASetLastError(0xdeadbeef); ret = inet_addr(NULL); ok(ret == INADDR_NONE, "got %#x\n", ret); - todo_wine ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError()); + ok(WSAGetLastError() == WSAEFAULT, "got error %u\n", WSAGetLastError());
for (i = 0; i < ARRAY_SIZE(ipv4_tests); ++i) {
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=94861
Your paranoid android.
=== debiant2 (64 bit WoW report) ===
ws2_32: sock.c:4958: Test failed: expected timeout