Kai Blin : ws2_32: Handle IPv6 in WSAStringToAddress.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 2 09:52:07 CDT 2007


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

Author: Kai Blin <kai.blin at gmail.com>
Date:   Fri Jun 29 23:39:20 2007 +0200

ws2_32: Handle IPv6 in WSAStringToAddress.

---

 configure            |    2 ++
 configure.ac         |    1 +
 dlls/ws2_32/socket.c |   39 +++++++++++++++++++++++++++++++++++----
 include/config.h.in  |    3 +++
 4 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 7e2549a..3f1ff43 100755
--- a/configure
+++ b/configure
@@ -15828,6 +15828,7 @@ fi
 
 
 
+
 for ac_func in \
 	_pclose \
 	_popen \
@@ -15857,6 +15858,7 @@ for ac_func in \
 	gettid \
 	gettimeofday \
 	getuid \
+	inet_pton \
 	kqueue \
 	lstat \
 	memmove \
diff --git a/configure.ac b/configure.ac
index f499a70..b262128 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1151,6 +1151,7 @@ AC_CHECK_FUNCS(\
 	gettid \
 	gettimeofday \
 	getuid \
+	inet_pton \
 	kqueue \
 	lstat \
 	memmove \
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 90fa9b0..b3f1bae 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -4457,7 +4457,7 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
 
     switch(AddressFamily)
     {
-    case AF_INET:
+    case WS_AF_INET:
     {
         struct in_addr inetaddr;
 
@@ -4494,8 +4494,9 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
         break;
 
     }
-    case AF_INET6:
+    case WS_AF_INET6:
     {
+        struct in6_addr inetaddr;
         /* If lpAddressLength is too small, tell caller the size we need */
         if (*lpAddressLength < sizeof(SOCKADDR_IN6))
         {
@@ -4503,8 +4504,38 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
             res = WSAEFAULT;
             break;
         }
-        FIXME("We don't support IPv6 yet.\n");
-        res = WSAEINVAL;
+#ifdef HAVE_INET_PTON
+        memset(lpAddress, 0, sizeof(SOCKADDR_IN6));
+
+        ((LPSOCKADDR_IN6)lpAddress)->sin6_family = WS_AF_INET6;
+
+        /* This one is a bit tricky. An IPv6 address contains colons, so the
+         * check from IPv4 doesn't work like that. However, IPv6 addresses that
+         * contain a port are written with braces like [fd12:3456:7890::1]:12345
+         * so what we will do is to look for ']', check if the next char is a
+         * colon, and if it is, parse the port as in IPv4. */
+
+        ptrPort = strchr(workBuffer, ']');
+        if(ptrPort && *(++ptrPort) == ':')
+        {
+            ((LPSOCKADDR_IN6)lpAddress)->sin6_port = (WS_u_short)atoi(ptrPort+1);
+            *ptrPort = '\0';
+        }
+        else
+        {
+            ((LPSOCKADDR_IN6)lpAddress)->sin6_port = 0;
+        }
+
+        if(inet_pton(AF_INET6, workBuffer, &inetaddr) > 0)
+        {
+            memcpy(&((LPSOCKADDR_IN6)lpAddress)->sin6_addr, &inetaddr,
+                    sizeof(struct in6_addr));
+            res = 0;
+        }
+        else
+#endif /* HAVE_INET_PTON */
+            res = WSAEINVAL;
+
         break;
     }
     default:
diff --git a/include/config.h.in b/include/config.h.in
index 331e5cc..09d133c 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -240,6 +240,9 @@
 /* Define to 1 if you have the `inet_network' function. */
 #undef HAVE_INET_NETWORK
 
+/* 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