diff options
-rw-r--r-- | usr.bin/ftp/extern.h | 1 | ||||
-rw-r--r-- | usr.bin/ftp/main.c | 2 | ||||
-rw-r--r-- | usr.bin/ftp/util.c | 30 |
3 files changed, 32 insertions, 1 deletions
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 278be80..d935d9e 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -77,6 +77,7 @@ char *hookup __P((const char *, char *)); void idle __P((int, char **)); int initconn __P((void)); void intr __P((void)); +int isipv6addr __P((const char *)); void list_vertical __P((StringList *)); void lcd __P((int, char **)); int login __P((const char *, char *, char *)); diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index 4460878..eb98a97 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -273,7 +273,7 @@ main(argc, argv) #endif if (argc > 0) { - if (isurl(argv[0])) { + if (strchr(argv[0], ':') != NULL && ! isipv6addr(argv[0])) { anonftp = 1; /* Handle "automatic" transfers. */ rval = auto_fetch(argc, argv); if (rval >= 0) /* -1 == connected and cd-ed */ diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 4aa315c..0cb2e59 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -58,6 +58,9 @@ __RCSID_SOURCE("$NetBSD: util.c,v 1.16.2.1 1997/11/18 01:02:33 mellon Exp $"); #include <string.h> #include <time.h> #include <unistd.h> +#ifdef INET6 +#include <netdb.h> +#endif #include "ftp_var.h" #include "pathnames.h" @@ -846,3 +849,30 @@ controlediting() } } #endif /* !SMALL */ + +/* + * Determine if given string is an IPv6 address or not. + * Return 1 for yes, 0 for no + */ +int +isipv6addr(const char *addr) +{ + int rv = 0; +#ifdef INET6 + struct addrinfo hints, *res; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_INET6; + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + hints.ai_flags = AI_NUMERICHOST; + if (getaddrinfo(addr, "0", &hints, &res) != 0) + rv = 0; + else { + rv = 1; + freeaddrinfo(res); + } + if (debug) + printf("isipv6addr: got %d for %sn", rv, addr); +#endif + return (rv == 1) ? 1 : 0; +} |