=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- src/usr.bin/ftp/fetch.c 2000/01/09 05:14:38 1.27 +++ src/usr.bin/ftp/fetch.c 2000/04/24 03:30:16 1.28 @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.27 2000/01/09 05:14:38 millert Exp $ */ +/* $OpenBSD: fetch.c,v 1.28 2000/04/24 03:30:16 itojun Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fetch.c,v 1.27 2000/01/09 05:14:38 millert Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.28 2000/04/24 03:30:16 itojun Exp $"; #endif /* not lint */ /* @@ -104,6 +104,7 @@ char c, *cp, *ep, *portnum, *path, buf[4096]; const char *savefile; char *line, *proxy, *host, *port; + char *hosttail; volatile sig_t oldintr; off_t hashbytes; char *cause = "unknown"; @@ -268,7 +269,14 @@ return (0); } - portnum = strchr(host, ':'); /* find portnum */ + if (*host == '[' && (hosttail = strrchr(host, ']')) != NULL && + (hosttail[1] == '\0' || hosttail[1] == ':')) { + host++; + *hosttail++ = '\0'; + } else + hosttail = host; + + portnum = strrchr(hosttail, ':'); /* find portnum */ if (portnum != NULL) *portnum++ = '\0'; @@ -327,8 +335,15 @@ fprintf(ttyout, "Requesting %s (via %s)\n", origline, proxyenv); } - snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n", - proxy ? "" : "/", path, host); + if (strchr(host, ':')) { + snprintf(buf, sizeof(buf), + "GET %s%s HTTP/1.0\r\nHost: [%s]:%s\r\n\r\n", + proxy ? "" : "/", path, host, port); + } else { + snprintf(buf, sizeof(buf), + "GET %s%s HTTP/1.0\r\nHost: %s:%s\r\n\r\n", + proxy ? "" : "/", path, host, port); + } len = strlen(buf); if (write(s, buf, len) < len) { warn("Writing HTTP request");