ws2_32(3/3): Implement WS_inet_ntop for IPv4 where inet_ntop isn't available

Juan Lang juan.lang at gmail.com
Thu Jul 16 12:05:04 CDT 2009


--Juan
-------------- next part --------------
From df8648b93b33564d3c987df41d3183655d8e5b19 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Thu, 16 Jul 2009 09:28:11 -0700
Subject: [PATCH 3/3] Implement WS_inet_ntop for IPv4 where inet_ntop isn't available

---
 dlls/ws2_32/socket.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 0df61c7..64e85d9 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -160,6 +160,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(winsock);
 
 /* critical section to protect some non-reentrant net function */
 extern CRITICAL_SECTION csWSgetXXXbyYYY;
+#ifndef HAVE_INET_NTOP
+/* critical section to protect inet_ntoa */
+static CRITICAL_SECTION csNtoA;
+static CRITICAL_SECTION_DEBUG critsect_debug =
+{
+    0, 0, &csNtoA,
+    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+      0, 0, { (DWORD_PTR)(__FILE__ ": csNtoA") }
+};
+static CRITICAL_SECTION csNtoA = { &critsect_debug, -1, 0, 0, 0, 0 };
+#endif
 
 union generic_unix_sockaddr
 {
@@ -4718,7 +4729,34 @@ PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len )
         return inet_ntop( AF_INET6, in6->WS_s6_addr, buffer, len );
     }
 #else
-    FIXME( "not supported on this platform\n" );
+    switch (family)
+    {
+    case WS_AF_INET:
+    {
+        char *p;
+        struct in_addr in;
+
+        in.s_addr = ((struct WS_in_addr *)addr)->S_un.S_addr;
+        EnterCriticalSection( &csNtoA );
+        if ((p = inet_ntoa( in )))
+        {
+            if (strlen(p) < len)
+            {
+                strcpy( buffer, p );
+                p = buffer;
+            }
+            else
+            {
+                WSASetLastError( ERROR_INVALID_PARAMETER );
+                p = NULL;
+            }
+        }
+        LeaveCriticalSection( &csNtoA );
+        return p;
+    }
+    default:
+        FIXME( "address family %d not supported on this platform\n", family );
+    }
 #endif
     WSASetLastError( WSAEAFNOSUPPORT );
     return NULL;
-- 
1.6.3.2


More information about the wine-patches mailing list