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

Alexandre Julliard julliard at winehq.org
Tue May 26 17:17:06 CDT 2020


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

Author: Alex Henrie <alexhenrie24 at gmail.com>
Date:   Mon May 25 22:36:24 2020 -0600

ws2_32: Reimplement inet_ntop on top of ntdll functions.

And add a couple of tests for IPv6 addresses that Windows represents
using dot-decimal notation for the last 32 bits but GNU/Linux does not.

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 configure                |  3 ---
 configure.ac             |  3 ---
 dlls/ws2_32/socket.c     | 20 ++++++--------------
 dlls/ws2_32/tests/sock.c |  6 ++++++
 include/config.h.in      |  9 ---------
 5 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/configure b/configure
index e2e03dc4ba..a5516fe60e 100755
--- a/configure
+++ b/configure
@@ -18296,9 +18296,6 @@ for ac_func in \
 	getprotobyname \
 	getprotobynumber \
 	getservbyport \
-	inet_addr \
-	inet_network \
-	inet_ntop \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
diff --git a/configure.ac b/configure.ac
index d81f5cc88c..b43ec73929 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2249,9 +2249,6 @@ AC_CHECK_FUNCS(\
 	getprotobyname \
 	getprotobynumber \
 	getservbyport \
-	inet_addr \
-	inet_network \
-	inet_ntop \
 )
 
 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 bdfe63ee19..199b7187a8 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -8351,10 +8351,8 @@ int WINAPI WSARemoveServiceClass(LPGUID info)
  */
 PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len )
 {
-#ifdef HAVE_INET_NTOP
-    struct WS_in6_addr *in6;
-    struct WS_in_addr  *in;
-    PCSTR pdst;
+    NTSTATUS status;
+    ULONG size = min( len, (ULONG)-1 );
 
     TRACE("family %d, addr (%p), buffer (%p), len %ld\n", family, addr, buffer, len);
     if (!buffer)
@@ -8367,14 +8365,12 @@ PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len )
     {
     case WS_AF_INET:
     {
-        in = addr;
-        pdst = inet_ntop( AF_INET, &in->WS_s_addr, buffer, len );
+        status = RtlIpv4AddressToStringExA( (IN_ADDR *)addr, 0, buffer, &size );
         break;
     }
     case WS_AF_INET6:
     {
-        in6 = addr;
-        pdst = inet_ntop( AF_INET6, in6->WS_s6_addr, buffer, len );
+        status = RtlIpv6AddressToStringExA( (IN6_ADDR *)addr, 0, 0, buffer, &size );
         break;
     }
     default:
@@ -8382,13 +8378,9 @@ PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len )
         return NULL;
     }
 
-    if (!pdst) SetLastError( STATUS_INVALID_PARAMETER );
-    return pdst;
-#else
-    FIXME( "not supported on this platform\n" );
-    SetLastError( WSAEAFNOSUPPORT );
+    if (status == STATUS_SUCCESS) return buffer;
+    SetLastError( STATUS_INVALID_PARAMETER );
     return NULL;
-#endif
 }
 
 /***********************************************************************
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index c72dc7a77a..cd9a13937c 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5008,6 +5008,12 @@ static void test_inet_pton(void)
         "0x12345678", NULL, NULL},
         {AF_INET6, 0, 0, /* windows bug */
         "::1:2:3:4:5:6:7", NULL, NULL},
+        {AF_INET6, 1, 0,              /* Test 30 */
+        "::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"},
     };
     int i, ret;
     DWORD err;
diff --git a/include/config.h.in b/include/config.h.in
index d2933eee65..2642487312 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -296,18 +296,9 @@
 /* Define to 1 if you have the `ilogbf' function. */
 #undef HAVE_ILOGBF
 
-/* Define to 1 if you have the `inet_addr' function. */
-#undef HAVE_INET_ADDR
-
 /* Define to 1 if you have the <inet/mib2.h> header file. */
 #undef HAVE_INET_MIB2_H
 
-/* Define to 1 if you have the `inet_network' function. */
-#undef HAVE_INET_NETWORK
-
-/* Define to 1 if you have the `inet_ntop' function. */
-#undef HAVE_INET_NTOP
-
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 




More information about the wine-cvs mailing list