From 41e9a8c5fbf95bceba5be06f825bf9ae59814f3a Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Mon, 18 May 2020 21:39:48 -0600 Subject: [PATCH] ws2_32: Reimplement inet_pton on top of ntdll functions. And add a test to show that inet_pton does not accept hexadecimal IPv4 addresses, and another test to demonstrate that it has the same leading double colon bug as RtlIpv6StringToAddress. Signed-off-by: Alex Henrie Signed-off-by: Alexandre Julliard --- configure | 1 - configure.ac | 1 - dlls/ws2_32/socket.c | 25 ++++++++++++------------- dlls/ws2_32/tests/sock.c | 6 +++++- include/config.h.in | 3 --- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/configure b/configure index 7e4a153c207..a6c4384ddaa 100755 --- a/configure +++ b/configure @@ -18262,7 +18262,6 @@ for ac_func in \ inet_addr \ inet_network \ inet_ntop \ - inet_pton \ do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/configure.ac b/configure.ac index b7916fcca7d..8ddeb0710ad 100644 --- a/configure.ac +++ b/configure.ac @@ -2247,7 +2247,6 @@ AC_CHECK_FUNCS(\ inet_addr \ inet_network \ inet_ntop \ - inet_pton \ ) dnl Check for clock_gettime which may be in -lrt diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index d57fc9ecd2a..8e66ab8fec8 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -8394,10 +8394,10 @@ PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len ) /*********************************************************************** * inet_pton (WS2_32.@) */ -INT WINAPI WS_inet_pton( INT family, PCSTR addr, PVOID buffer) +INT WINAPI WS_inet_pton(INT family, const char *addr, void *buffer) { -#ifdef HAVE_INET_PTON - int unixaf, ret; + NTSTATUS status; + const char *terminator; TRACE("family %d, addr %s, buffer (%p)\n", family, debugstr_a(addr), buffer); @@ -8407,21 +8407,20 @@ INT WINAPI WS_inet_pton( INT family, PCSTR addr, PVOID buffer) return SOCKET_ERROR; } - unixaf = convert_af_w2u(family); - if (unixaf != AF_INET && unixaf != AF_INET6) + switch (family) { + case WS_AF_INET: + status = RtlIpv4StringToAddressA(addr, TRUE, &terminator, buffer); + break; + case WS_AF_INET6: + status = RtlIpv6StringToAddressA(addr, &terminator, buffer); + break; + default: SetLastError(WSAEAFNOSUPPORT); return SOCKET_ERROR; } - ret = inet_pton(unixaf, addr, buffer); - if (ret == -1) SetLastError(wsaErrno()); - return ret; -#else - FIXME( "not supported on this platform\n" ); - SetLastError( WSAEAFNOSUPPORT ); - return SOCKET_ERROR; -#endif + return (status == STATUS_SUCCESS && *terminator == 0); } /*********************************************************************** diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 8bf4e3a83bd..134c4d383f4 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -4993,7 +4993,11 @@ static void test_inet_pton(void) "\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"} + "\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, /* windows bug */ + "::1:2:3:4:5:6:7", NULL, NULL}, }; int i, ret; DWORD err; diff --git a/include/config.h.in b/include/config.h.in index 24a037a50e5..d2933eee65a 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -308,9 +308,6 @@ /* Define to 1 if you have the `inet_ntop' function. */ #undef HAVE_INET_NTOP -/* Define to 1 if you have the `inet_pton' function. */ -#undef HAVE_INET_PTON - /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H