winhttp(5/5): Support IPv6 in netconn_resolve

Juan Lang juan.lang at gmail.com
Tue Jul 7 16:09:03 CDT 2009


--Juan
-------------- next part --------------
From a48947ca1cad2816f38db10ee7015871831e1a67 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Tue, 7 Jul 2009 13:58:52 -0700
Subject: [PATCH 5/5] Support IPv6 in netconn_resolve

---
 dlls/winhttp/net.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/dlls/winhttp/net.c b/dlls/winhttp/net.c
index 1239aaf..c71b694 100644
--- a/dlls/winhttp/net.c
+++ b/dlls/winhttp/net.c
@@ -581,15 +581,25 @@ BOOL netconn_resolve( WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr *sa,
 
 #ifdef HAVE_GETADDRINFO
     memset( &hints, 0, sizeof(struct addrinfo) );
+    /* Prefer IPv4 to IPv6 addresses, since some web servers do not listen on
+     * their IPv6 addresses even though they have IPv6 addresses in the DNS.
+     */
     hints.ai_family = AF_INET;
 
     ret = getaddrinfo( hostname, NULL, &hints, &res );
-    heap_free( hostname );
     if (ret != 0)
     {
-        TRACE("failed to get address of %s (%s)\n", debugstr_w(hostnameW), gai_strerror(ret));
-        return FALSE;
+        TRACE("failed to get IPv4 address of %s (%s), retrying with IPv6\n", debugstr_w(hostnameW), gai_strerror(ret));
+        hints.ai_family = AF_INET6;
+        ret = getaddrinfo( hostname, NULL, &hints, &res );
+        if (ret != 0)
+        {
+            TRACE("failed to get address of %s (%s)\n", debugstr_w(hostnameW), gai_strerror(ret));
+            heap_free( hostname );
+            return FALSE;
+        }
     }
+    heap_free( hostname );
     if (*sa_len < res->ai_addrlen)
     {
         WARN("address too small\n");
@@ -600,6 +610,7 @@ BOOL netconn_resolve( WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr *sa,
     memcpy( sa, res->ai_addr, res->ai_addrlen );
 
     freeaddrinfo( res );
+    return TRUE;
 #else
     EnterCriticalSection( &cs_gethostbyname );
 
@@ -624,8 +635,8 @@ BOOL netconn_resolve( WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr *sa,
     sin->sin_port = htons( port );
 
     LeaveCriticalSection( &cs_gethostbyname );
-#endif
     return TRUE;
+#endif
 }
 
 const void *netconn_get_certificate( netconn_t *conn )
-- 
1.6.3.2


More information about the wine-patches mailing list