diff options
author | ru <ru@FreeBSD.org> | 1999-06-25 14:11:16 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 1999-06-25 14:11:16 +0000 |
commit | d321f9c4e499838b14e5ff3e1057ab29cabc608f (patch) | |
tree | 7be728efd338a63d9edbeaad8559863cdc69d705 /usr.bin/ftp/main.c | |
parent | 5ed26c8f51820fc71578a9f1abc4fa06760f89d3 (diff) | |
download | FreeBSD-src-d321f9c4e499838b14e5ff3e1057ab29cabc608f.zip FreeBSD-src-d321f9c4e499838b14e5ff3e1057ab29cabc608f.tar.gz |
- add "-s src_addr" option to allow setting of the source IP address;
- fix two minor bugs;
- slightly cleanup manpage.
Diffstat (limited to 'usr.bin/ftp/main.c')
-rw-r--r-- | usr.bin/ftp/main.c | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index d8e339d..0348462 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.16 1997/12/13 20:38:19 pst Exp $ */ +/* $Id: main.c,v 1.17 1999/06/07 16:35:15 des Exp $ */ /* $NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $ */ /* @@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\ #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; #else -__RCSID("$Id: main.c,v 1.16 1997/12/13 20:38:19 pst Exp $"); +__RCSID("$Id: main.c,v 1.17 1999/06/07 16:35:15 des Exp $"); __RCSID_SOURCE("$NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $"); #endif #endif /* not lint */ @@ -54,6 +54,8 @@ __RCSID_SOURCE("$NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $"); */ #include <sys/types.h> #include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> #include <err.h> #include <locale.h> @@ -80,6 +82,7 @@ main(argc, argv) struct passwd *pw = NULL; char *cp, *ep, homedir[MAXPATHLEN], *s; int dumbterm; + char *src_addr = NULL; (void) setlocale(LC_ALL, ""); @@ -166,7 +169,7 @@ main(argc, argv) if (isatty(fileno(stdout)) && !dumbterm) progress = 1; /* progress bar on if tty is usable */ - while ((ch = getopt(argc, argv, "adeginpP:tvVU")) != -1) { + while ((ch = getopt(argc, argv, "adeginpP:s:tUvV")) != -1) { switch (ch) { case 'a': anonftp = 1; @@ -207,10 +210,19 @@ main(argc, argv) ftpport = htons(port); break; + case 's': + dobind = 1; + src_addr = optarg; + break; + case 't': trace = 1; break; + case 'U': + restricted_data_ports = 0; + break; + case 'v': verbose = 1; break; @@ -219,10 +231,6 @@ main(argc, argv) verbose = 0; break; - case 'U': - restricted_data_ports = 0; - break; - default: usage(); } @@ -234,6 +242,21 @@ main(argc, argv) proxy = 0; /* proxy not active */ crflag = 1; /* strip c.r. on ascii gets */ sendport = -1; /* not using ports */ + + if (dobind) { + memset((void *)&bindto, 0, sizeof(bindto)); + if (inet_aton(src_addr, &bindto.sin_addr) == 1) + bindto.sin_family = AF_INET; + else { + struct hostent *hp = gethostbyname(src_addr); + if (hp == NULL) + errx(1, "%s: %s", src_addr, hstrerror(h_errno)); + bindto.sin_family = hp->h_addrtype; + memcpy(&bindto.sin_addr, hp->h_addr_list[0], + MIN(hp->h_length,sizeof(bindto.sin_addr))); + } + } + /* * Set up the home directory in case we're globbing. */ @@ -263,18 +286,21 @@ main(argc, argv) if (rval >= 0) /* -1 == connected and cd-ed */ exit(rval); } else { - char *xargv[5]; + char *xargv[4], **xargp = xargv; +#ifdef __GNUC__ /* XXX: to shut up gcc warnings */ + (void)&xargp; +#endif if (setjmp(toplevel)) exit(0); (void)signal(SIGINT, (sig_t)intr); (void)signal(SIGPIPE, (sig_t)lostpeer); - xargv[0] = __progname; - xargv[1] = argv[0]; - xargv[2] = argv[1]; - xargv[3] = argv[2]; - xargv[4] = NULL; - setpeer(argc+1, xargv); + *xargp++ = __progname; + *xargp++ = argv[0]; /* host */ + if (argc > 1) + *xargp++ = argv[1]; /* port */ + *xargp = NULL; + setpeer(xargp-xargv, xargv); } } #ifndef SMALL @@ -688,7 +714,7 @@ void usage() { (void)fprintf(stderr, - "usage: %s [-adeginptvV] [host [port]]\n" + "usage: %s [-adeginptUvV] [-P port] [-s src_addr] [host [port]]\n" " %s host:path[/]\n" " %s ftp://host[:port]/path[/]\n" " %s http://host[:port]/file\n", |