From: Daniel Stenberg Date: Tue, 1 Aug 2023 14:47:34 +0000 (+0200) Subject: resolve: use PF_INET6 family lookups when CURL_IPRESOLVE_V6 is set X-Git-Tag: curl-8_3_0~245 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3142b57299f3aeec546cc1179b9ff170f8d20ad;p=thirdparty%2Fcurl.git 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 --- diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 19fe8536b0..3e0e949681 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -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)? diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c index 6f0a2126ab..a2e294f8f5 100644 --- a/lib/asyn-thread.c +++ b/lib/asyn-thread.c @@ -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));