Alex Henrie : ws2_32: Reimplement inet_pton on top of ntdll functions.

Alexandre Julliard julliard at winehq.org
Tue May 19 16:07:48 CDT 2020


Module: wine
Branch: master
Commit: 41e9a8c5fbf95bceba5be06f825bf9ae59814f3a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=41e9a8c5fbf95bceba5be06f825bf9ae59814f3a

Author: Alex Henrie <alexhenrie24 at gmail.com>
Date:   Mon May 18 21:39:48 2020 -0600

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 <alexhenrie24 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 7e4a153c20..a6c4384dda 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 b7916fcca7..8ddeb0710a 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 d57fc9ecd2..8e66ab8fec 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 8bf4e3a83b..134c4d383f 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 24a037a50e..d2933eee65 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 <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 




More information about the wine-cvs mailing list