diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-05-02 00:54:54 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-05-02 00:54:54 +0000 |
commit | afa7f44eb72657c720540a51584ef5aa6cb089ed (patch) | |
tree | 87466000e7aed01502db472e167cbfb0418510a4 /usr.bin/ftp/fetch.c | |
parent | d3e4fc2160bebab54ed0f0e61d3056eb6512f557 (diff) |
always attach port in numeric, for HTTP Host: header.
from: chris and mickey
XXX Host: header is specified in HTTP/1.1, not HTTP/1.0.
Diffstat (limited to 'usr.bin/ftp/fetch.c')
-rw-r--r-- | usr.bin/ftp/fetch.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index dc6fa4b31e4..66eb3567b6c 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.28 2000/04/24 03:30:16 itojun Exp $ */ +/* $OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 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.28 2000/04/24 03:30:16 itojun Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.29 2000/05/02 00:54:53 itojun Exp $"; #endif /* not lint */ /* @@ -102,6 +102,7 @@ url_get(origline, proxyenv, outfile) volatile int s; size_t len; char c, *cp, *ep, *portnum, *path, buf[4096]; + char pbuf[NI_MAXSERV]; const char *savefile; char *line, *proxy, *host, *port; char *hosttail; @@ -316,6 +317,13 @@ again: continue; } + /* get port in numeric */ + if (getnameinfo(res->ai_addr, res->ai_addrlen, NULL, 0, + pbuf, sizeof(pbuf), NI_NUMERICSERV) == 0) + port = pbuf; + else + port = NULL; + break; } freeaddrinfo(res0); @@ -337,12 +345,14 @@ again: } 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); + "GET %s%s HTTP/1.0\r\nHost: [%s]%s%s\r\n\r\n", + proxy ? "" : "/", path, host, + port ? ":" : "", port ? port : ""); } else { snprintf(buf, sizeof(buf), - "GET %s%s HTTP/1.0\r\nHost: %s:%s\r\n\r\n", - proxy ? "" : "/", path, host, port); + "GET %s%s HTTP/1.0\r\nHost: %s%s%s\r\n\r\n", + proxy ? "" : "/", path, host, + port ? ":" : "", port ? port : ""); } len = strlen(buf); if (write(s, buf, len) < len) { |