]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
resolve: use PF_INET6 family lookups when CURL_IPRESOLVE_V6 is set
authorDaniel Stenberg <daniel@haxx.se>
Tue, 1 Aug 2023 14:47:34 +0000 (16:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 1 Aug 2023 22:49:16 +0000 (00:49 +0200)
Previously it would always do PF_UNSPEC if CURL_IPRESOLVE_V4 is not
used, thus unnecessarily asking for addresses that will not be used.

Reported-by: Joseph Tharayil
Fixes #11564
Closes #11565

lib/asyn-ares.c
lib/asyn-thread.c

index 19fe8536b02d02dedd00d7ed4a0386f2166d280e..3e0e94968163545864293be42f50f2e1e84c147a 100644 (file)
@@ -770,9 +770,14 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
       int pf = PF_INET;
       memset(&hints, 0, sizeof(hints));
 #ifdef CURLRES_IPV6
-      if((data->conn->ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data))
+      if((data->conn->ip_version != CURL_IPRESOLVE_V4) &&
+         Curl_ipv6works(data)) {
         /* The stack seems to be IPv6-enabled */
-        pf = PF_UNSPEC;
+        if(data->conn->ip_version == CURL_IPRESOLVE_V6)
+          pf = PF_INET6;
+        else
+          pf = PF_UNSPEC;
+      }
 #endif /* CURLRES_IPV6 */
       hints.ai_family = pf;
       hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP)?
index 6f0a2126ab63c60161aa3a8968f09b26fbc9eaf1..a2e294f8f5142e356f125293e96de5330682afd1 100644 (file)
@@ -696,9 +696,13 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
   *waitp = 0; /* default to synchronous response */
 
 #ifdef CURLRES_IPV6
-  if((data->conn->ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data))
+  if((data->conn->ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data)) {
     /* The stack seems to be IPv6-enabled */
-    pf = PF_UNSPEC;
+    if(data->conn->ip_version == CURL_IPRESOLVE_V6)
+      pf = PF_INET6;
+    else
+      pf = PF_UNSPEC;
+  }
 #endif /* CURLRES_IPV6 */
 
   memset(&hints, 0, sizeof(hints));