diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-07-03 14:01:57 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-07-03 14:01:57 +0000 |
commit | 2681bf68f3d8d1eef2238bfbf51b16fd9cafe660 (patch) | |
tree | 0834a86abbafdd50dde2775b550dd1a30cbf2528 | |
parent | 05efaca69dc49b002b25dd2fd4fb8f2752ebf5e6 (diff) |
Add a -b option that takes a hostname or IP-address as an argument.
This address is bound to the local socket of the TCP connection and is
useful for talking to services which does authentication based on IP-
addresses.
-rw-r--r-- | usr.bin/telnet/commands.c | 50 | ||||
-rw-r--r-- | usr.bin/telnet/main.c | 21 | ||||
-rw-r--r-- | usr.bin/telnet/telnet.1 | 14 |
3 files changed, 72 insertions, 13 deletions
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 769e2ee4070..a254d8fe105 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.4 1996/04/21 23:44:11 deraadt Exp $ */ +/* $OpenBSD: commands.c,v 1.5 1996/07/03 14:01:55 niklas Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; static char rcsid[] = "$NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $"; #else -static char rcsid[] = "$OpenBSD: commands.c,v 1.4 1996/04/21 23:44:11 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: commands.c,v 1.5 1996/07/03 14:01:55 niklas Exp $"; #endif #endif /* not lint */ @@ -2084,8 +2084,9 @@ tn(argc, argv) int argc; char *argv[]; { - register struct hostent *host = 0; + register struct hostent *host = 0, *alias = 0; struct sockaddr_in sin; + struct sockaddr_in ladr; struct servent *sp = 0; unsigned long temp; extern char *inet_ntoa(); @@ -2093,7 +2094,7 @@ tn(argc, argv) char *srp = 0, *strrchr(); unsigned long sourceroute(), srlen; #endif - char *cmd, *hostp = 0, *portp = 0, *user = 0; + char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0; /* clear the socket address prior to use */ memset((char *)&sin, 0, sizeof(sin)); @@ -2124,6 +2125,14 @@ tn(argc, argv) --argc; continue; } + if (strcmp(*argv, "-b") == 0) { + --argc; ++argv; + if (argc == 0) + goto usage; + aliasp = *argv++; + --argc; + continue; + } if (strcmp(*argv, "-a") == 0) { --argc; ++argv; autologin = 1; @@ -2242,7 +2251,38 @@ tn(argc, argv) perror("telnet: socket"); return 0; } -#if defined(IP_OPTIONS) && defined(IPPROTO_IP) + if (aliasp) { + memset ((caddr_t)&ladr, 0, sizeof (ladr)); + temp = inet_addr(aliasp); + if (temp != INADDR_NONE) { + ladr.sin_addr.s_addr = temp; + ladr.sin_family = AF_INET; + alias = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET); + } else { + alias = gethostbyname(aliasp); + if (alias) { + ladr.sin_family = alias->h_addrtype; +#if defined(h_addr) /* In 4.3, this is a #define */ + memmove((caddr_t)&ladr.sin_addr, + alias->h_addr_list[0], alias->h_length); +#else /* defined(h_addr) */ + memmove((caddr_t)&ladr.sin_addr, alias->h_addr, + alias->h_length); +#endif /* defined(h_addr) */ + } else { + herror(aliasp); + return 0; + } + } + ladr.sin_port = htons(0); + + if (bind (net, (struct sockaddr *)&ladr, sizeof(ladr)) < 0) { + perror(aliasp);; + (void) close(net); /* dump descriptor */ + return 0; + } + } + #if defined(IP_OPTIONS) && defined(IPPROTO_IP) if (srp && setsockopt(net, IPPROTO_IP, IP_OPTIONS, (char *)srp, srlen) < 0) perror("setsockopt (IP_OPTIONS)"); #endif diff --git a/usr.bin/telnet/main.c b/usr.bin/telnet/main.c index 4370fabc471..ae80438b019 100644 --- a/usr.bin/telnet/main.c +++ b/usr.bin/telnet/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.2 1996/03/27 19:33:03 niklas Exp $ */ +/* $OpenBSD: main.c,v 1.3 1996/07/03 14:01:56 niklas Exp $ */ /* $NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $ */ /* @@ -45,7 +45,7 @@ static char copyright[] = static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95"; static char rcsid[] = "$NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.2 1996/03/27 19:33:03 niklas Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.3 1996/07/03 14:01:56 niklas Exp $"; #endif #endif /* not lint */ @@ -90,10 +90,10 @@ usage() prompt, #ifdef AUTHENTICATION "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]", - "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ", + "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] [-b hostalias ]", #else "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]", - "\n\t[-n tracefile]", + "\n\t[-n tracefile] [-b hostalias ]", #endif #if defined(TN3270) && defined(unix) # ifdef AUTHENTICATION @@ -121,7 +121,7 @@ main(argc, argv) extern char *optarg; extern int optind; int ch; - char *user, *strrchr(); + char *user, *alias, *strrchr(); #ifdef FORWARD extern int forward_flags; #endif /* FORWARD */ @@ -138,12 +138,12 @@ main(argc, argv) else prompt = argv[0]; - user = NULL; + user = alias = NULL; rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE; autologin = -1; - while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != EOF) { + while ((ch = getopt(argc, argv, "8EKLS:X:ab:cde:fFk:l:n:rt:x")) != EOF) { switch(ch) { case '8': eight = 3; /* binary output and input */ @@ -241,6 +241,9 @@ main(argc, argv) autologin = 1; user = optarg; break; + case 'b': + alias = optarg; + break; case 'n': #if defined(TN3270) && defined(unix) /* distinguish between "-n oasynch" and "-noasynch" */ @@ -297,6 +300,10 @@ main(argc, argv) *argp++ = "-l"; *argp++ = user; } + if (alias) { + *argp++ = "-b"; + *argp++ = alias; + } *argp++ = argv[0]; /* host */ if (argc > 1) *argp++ = argv[1]; /* port */ diff --git a/usr.bin/telnet/telnet.1 b/usr.bin/telnet/telnet.1 index 446f994c14c..f2b1c4aef81 100644 --- a/usr.bin/telnet/telnet.1 +++ b/usr.bin/telnet/telnet.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: telnet.1,v 1.2 1996/03/27 19:33:08 niklas Exp $ +.\" $OpenBSD: telnet.1,v 1.3 1996/07/03 14:01:56 niklas Exp $ .\" $NetBSD: telnet.1,v 1.5 1996/02/28 21:04:12 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1993 @@ -52,6 +52,7 @@ protocol .Op Fl S Ar tos .Op Fl X Ar authtype .Op Fl a +.Op Fl b Ar hostalias .Op Fl c .Op Fl d .Op Fl e Ar escapechar @@ -127,6 +128,17 @@ The name used is that of the current user as returned by .Xr getlogin 2 if it agrees with the current user ID, otherwise it is the name associated with the user ID. +.It Fl b Ar hostalias +Uses +.Xr bind 2 +on the local socket to bind it to an aliased address (See +.Xr ifconfig 8 +and the \*(Lqalias\*(Rq specifier) or to the address of +another interface than the one naturally chosen by +.Xr connect 2 . +This can be useful when connecting to services which uses IP addresses +for authentication and reconfiguration of the server is undesirable (or +impossible). .It Fl c Disables the reading of the user's .Pa \&.telnetrc |