1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 11:02:48 -05:00

Use the new host_str* functions to improve IPv6 literal support.

I've gone through everywhere we handle host names / addresses (on
command lines, in PuTTY config, in port forwarding, in X display
names, in host key storage...) and tried to make them handle IPv6
literals sensibly, by using the host_str* functions I introduced in my
previous commit. Generally it's now OK to use a bracketed IPv6 literal
anywhere a hostname might have been valid; in a few cases where no
ambiguity exists (e.g. no :port suffix is permitted anyway)
unbracketed IPv6 literals are also acceptable.

[originally from svn r10120]
This commit is contained in:
Simon Tatham
2014-01-25 15:58:54 +00:00
parent 0348f57077
commit 8da4fa5063
14 changed files with 65 additions and 78 deletions

View File

@ -221,7 +221,11 @@ SockAddr sk_namelookup(const char *host, char **canonicalname, int address_famil
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
err = getaddrinfo(host, NULL, &hints, &ret->ais);
{
char *trimmed_host = host_strduptrim(host); /* strip [] on literals */
err = getaddrinfo(trimmed_host, NULL, &hints, &ret->ais);
sfree(trimmed_host);
}
if (err != 0) {
ret->error = gai_strerror(err);
return ret;
@ -868,7 +872,11 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, i
hints.ai_next = NULL;
assert(port >= 0 && port <= 99999);
sprintf(portstr, "%d", port);
retcode = getaddrinfo(srcaddr, portstr, &hints, &ai);
{
char *trimmed_addr = host_strduptrim(srcaddr);
retcode = getaddrinfo(trimmed_addr, portstr, &hints, &ai);
sfree(trimmed_addr);
}
if (retcode == 0) {
addr = (union sockaddr_union *)ai->ai_addr;
addrlen = ai->ai_addrlen;

View File

@ -705,8 +705,7 @@ int main(int argc, char **argv)
q += 2;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
p += host_strcspn(p, ":/");
c = *p;
if (*p)
*p++ = '\0';
@ -847,7 +846,7 @@ int main(int argc, char **argv)
/*
* Trim off a colon suffix if it's there.
*/
host[strcspn(host, ":")] = '\0';
host[host_strcspn(host, ":")] = '\0';
/*
* Remove any remaining whitespace.

View File

@ -76,8 +76,7 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
q += 2;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
p += host_strcspn(p, ":/");
c = *p;
if (*p)
*p++ = '\0';