[PATCH 7/7] ws2_32: Reimplement inet_ntop on top of ntdll functions

Alex Henrie alexhenrie24 at gmail.com
Mon May 25 23:36:24 CDT 2020


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>
---
 configure.ac             |  1 -
 dlls/ws2_32/socket.c     | 20 ++++++--------------
 dlls/ws2_32/tests/sock.c |  6 ++++++
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/configure.ac b/configure.ac
index d81f5cc88c..7ebe73ff35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2251,7 +2251,6 @@ AC_CHECK_FUNCS(\
 	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;
-- 
2.26.2




More information about the wine-devel mailing list