]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
socks: make SOCKS5 use the CURLOPT_IPRESOLVE choice
authorDaniel Stenberg <daniel@haxx.se>
Fri, 20 Oct 2023 08:20:12 +0000 (10:20 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 20 Oct 2023 15:14:51 +0000 (17:14 +0200)
Fixes #11949
Reported-by: Ammar Faizi
Closes #12163

lib/socks.c

index 6d6368c3a5978308161ceb43005b715cf44d826c..88365ce2803fb1849419b4e65a7d2230ea475cb7 100644 (file)
@@ -823,10 +823,19 @@ CONNECT_REQ_INIT:
     /* FALLTHROUGH */
 CONNECT_RESOLVED:
   case CONNECT_RESOLVED: {
-    char dest[MAX_IPADR_LEN] = "unknown";  /* printable address */
+    char dest[MAX_IPADR_LEN];  /* printable address */
     struct Curl_addrinfo *hp = NULL;
     if(dns)
       hp = dns->addr;
+#ifdef ENABLE_IPV6
+    if(data->set.ipver != CURL_IPRESOLVE_WHATEVER) {
+      int wanted_family = data->set.ipver == CURL_IPRESOLVE_V4 ?
+        AF_INET : AF_INET6;
+      /* scan for the first proper address */
+      while(hp && (hp->ai_family != wanted_family))
+        hp = hp->ai_next;
+    }
+#endif
     if(!hp) {
       failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.",
             sx->hostname);