summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorshin <shin@FreeBSD.org>2000-02-12 15:16:59 +0000
committershin <shin@FreeBSD.org>2000-02-12 15:16:59 +0000
commit0a2a73d5508f74fa8b717c3afbf2c50e4c14150c (patch)
tree628caf86c4db497afa10a49cf1947eba67d6432d /usr.bin/ftp
parent4b6c4ae8e8703a11a3fd8ec1108949150418c676 (diff)
downloadFreeBSD-src-0a2a73d5508f74fa8b717c3afbf2c50e4c14150c.zip
FreeBSD-src-0a2a73d5508f74fa8b717c3afbf2c50e4c14150c.tar.gz
Fix parsing problems.
-"ftp hostname:/path" was not working. - IPv6 raw addr specification was not well supported, such as, "ftp http://\[1:2:3:4:5:6:7:8:\]/index.html" Approved by: jkh
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/fetch.c21
-rw-r--r--usr.bin/ftp/ftp.c13
2 files changed, 31 insertions, 3 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index fa6a0e4..a494e7e 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -527,7 +527,16 @@ bad_ftp_url:
if (portnum != NULL)
*portnum++ = '\0';
} else { /* classic style `host:file' */
- dir = strchr(host, ':');
+ char *end_brace;
+
+ if (*host == '[' &&
+ (end_brace = strrchr(host, ']')) != NULL) {
+ /*IPv6 addr in []*/
+ host++;
+ *end_brace = '\0';
+ dir = strchr(end_brace + 1, ':');
+ } else
+ dir = strchr(host, ':');
}
parsed_url:
if (EMPTYSTRING(host)) {
@@ -665,9 +674,19 @@ int
isurl(p)
const char *p;
{
+ char *path, pton_buf[16];
+
if (strncasecmp(p, FTP_URL, sizeof(FTP_URL) - 1) == 0
|| strncasecmp(p, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
return 1;
}
+ if (*p == '[' && (path = strrchr(p, ']')) != NULL) /*IPv6 addr in []*/
+ return (*(++path) == ':') ? 1 : 0;
+#ifdef INET6
+ if (inet_pton(AF_INET6, p, pton_buf) == 1) /* raw IPv6 addr */
+ return 0;
+#endif
+ if (strchr(p, ':') != NULL) /* else, if ':' exist */
+ return 1;
return 0;
}
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 86dc44d..1fe1c75 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -102,14 +102,23 @@ union sockunion {
union sockunion myctladdr, hisctladdr, data_addr;
char *
-hookup(host, port)
- const char *host;
+hookup(host0, port)
+ const char *host0;
char *port;
{
int s, len, tos, error;
struct addrinfo hints, *res, *res0;
static char hostnamebuf[MAXHOSTNAMELEN];
+ char *host;
+ if (*host0 == '[' && strrchr(host0, ']') != NULL) { /*IPv6 addr in []*/
+ strncpy(hostnamebuf, host0 + 1, strlen(host0) - 2);
+ hostnamebuf[strlen(host0) - 2] = '\0';
+ } else {
+ strncpy(hostnamebuf, host0, strlen(host0));
+ hostnamebuf[strlen(host0)] = '\0';
+ }
+ host = hostnamebuf;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
OpenPOWER on IntegriCloud