hostip: return IPv6 first for localhost resolves

Fixes #11465
Reported-by: Chilledheart on github
Closes #11466
This commit is contained in:
Daniel Stenberg 2023-07-19 09:17:15 +02:00
parent 51ccc7870f
commit ac67d72179
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View 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