From 715f1f53e0cf8ce5dc6f31f4ac6677f36e1927dc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Nov 2017 11:21:12 +0100 Subject: resolve: allow IP address within [] brackets ... so that IPv6 addresses can be passed like they can for connect-to and how they're used in URLs. Added test 1324 to verify Reported-by: Alex Malinovich Fixes #2087 Closes #2091 --- lib/hostip.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/hostip.c') diff --git a/lib/hostip.c b/lib/hostip.c index abe98028c..7f010a037 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -778,7 +778,6 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) { struct curl_slist *hostp; char hostname[256]; - char address[256]; int port; for(hostp = data->change.resolve; hostp; hostp = hostp->next) { @@ -820,6 +819,8 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) Curl_addrinfo *addr; char *entry_id; size_t entry_len; + char buffer[256]; + char *address = &buffer[0]; if(3 != sscanf(hostp->data, "%255[^:]:%d:%255s", hostname, &port, address)) { @@ -828,6 +829,16 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) continue; } + /* allow IP(v6) address within [brackets] */ + if(address[0] == '[') { + size_t alen = strlen(address); + if(address[alen-1] != ']') + /* it needs to also end with ] to be valid */ + continue; + address[alen-1] = 0; /* zero terminate there */ + address++; /* pass the open bracket */ + } + addr = Curl_str2addr(address, port); if(!addr) { infof(data, "Address in '%s' found illegal!\n", hostp->data); -- cgit v1.2.1