]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hostip: return IPv6 first for localhost resolves
authorDaniel Stenberg <daniel@haxx.se>
Wed, 19 Jul 2023 07:17:15 +0000 (09:17 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 19 Jul 2023 14:13:17 +0000 (16:13 +0200)
Fixes #11465
Reported-by: Chilledheart on github
Closes #11466

lib/hostip.c

index 8b452a8e3b580cad7fbc928d7f2549929d09f81a..1a289de8cbf20c926248f2670d8f4c9c83ae3e54 100644 (file)
@@ -557,6 +557,7 @@ static struct Curl_addrinfo *get_localhost6(int port, const char *name)
 static struct Curl_addrinfo *get_localhost(int port, const char *name)
 {
   struct Curl_addrinfo *ca;
+  struct Curl_addrinfo *ca6;
   const size_t ss_size = sizeof(struct sockaddr_in);
   const size_t hostlen = strlen(name);
   struct sockaddr_in sa;
@@ -583,8 +584,12 @@ static struct Curl_addrinfo *get_localhost(int port, const char *name)
   memcpy(ca->ai_addr, &sa, ss_size);
   ca->ai_canonname = (char *)ca->ai_addr + ss_size;
   strcpy(ca->ai_canonname, name);
-  ca->ai_next = get_localhost6(port, name);
-  return ca;
+
+  ca6 = get_localhost6(port, name);
+  if(!ca6)
+    return ca;
+  ca6->ai_next = ca;
+  return ca6;
 }
 
 #ifdef ENABLE_IPV6