resolve: use PF_INET6 family lookups when CURL_IPRESOLVE_V6 is set

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
This commit is contained in:
Daniel Stenberg 2023-08-01 16:47:34 +02:00
parent fc1e42190f
commit d3142b5729
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 13 additions and 4 deletions

View 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)?

View 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));