From 24c495a52fe47b74d1f6418706619f3100925058 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 20 Oct 2023 10:20:12 +0200 Subject: [PATCH] socks: make SOCKS5 use the CURLOPT_IPRESOLVE choice Fixes #11949 Reported-by: Ammar Faizi Closes #12163 --- lib/socks.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/socks.c b/lib/socks.c index 6d6368c3a5..88365ce280 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -823,10 +823,19 @@ CONNECT_REQ_INIT: /* FALLTHROUGH */ CONNECT_RESOLVED: case CONNECT_RESOLVED: { - char dest[MAX_IPADR_LEN] = "unknown"; /* printable address */ + char dest[MAX_IPADR_LEN]; /* printable address */ struct Curl_addrinfo *hp = NULL; if(dns) hp = dns->addr; +#ifdef ENABLE_IPV6 + if(data->set.ipver != CURL_IPRESOLVE_WHATEVER) { + int wanted_family = data->set.ipver == CURL_IPRESOLVE_V4 ? + AF_INET : AF_INET6; + /* scan for the first proper address */ + while(hp && (hp->ai_family != wanted_family)) + hp = hp->ai_next; + } +#endif if(!hp) { failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.", sx->hostname);