]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3760: squidclient ignores --disable-ipv6
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 9 Jan 2015 10:29:44 +0000 (02:29 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 9 Jan 2015 10:29:44 +0000 (02:29 -0800)
src/ip/Address.cc

index ba3cff5a2c04b8ff98fc8c790a28def046d48313..da402670fed2c71f9ad5be6c235622b4b063fc0f 100644 (file)
@@ -382,6 +382,20 @@ Ip::Address::lookupHostIP(const char *s, bool nodns)
         return false;
     }
 
+    struct addrinfo *resHead = res; // we need to free the whole list later
+    if (!Ip::EnableIpv6) {
+        // if we are IPv6-disabled, use first-IPv4 instead of first-IP.
+        struct addrinfo *maybeIpv4 = res;
+        while (maybeIpv4) {
+            if (maybeIpv4->ai_family == AF_INET)
+                break;
+            maybeIpv4 = maybeIpv4->ai_next;
+        }
+        if (maybeIpv4 != NULL)
+            res = maybeIpv4;
+        // else IPv6-only host, let the caller deal with first-IP anyway.
+    }
+
     /*
      *  NP: =(sockaddr_*) may alter the port. we don't want that.
      *      all we have been given as input was an IPA.
@@ -391,7 +405,7 @@ Ip::Address::lookupHostIP(const char *s, bool nodns)
     port(portSaved);
 
     /* free the memory getaddrinfo() dynamically allocated. */
-    freeaddrinfo(res);
+    freeaddrinfo(resHead);
     return true;
 }