summaryrefslogtreecommitdiffstats
path: root/usr.bin/telnet
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>1999-06-16 15:26:22 +0000
committerru <ru@FreeBSD.org>1999-06-16 15:26:22 +0000
commit3b7c3aa4be419cf5415989e5ad1552b65226d743 (patch)
tree7469aa87b89ae1a49cf6539dba98106a1b8a15e1 /usr.bin/telnet
parentef7a7a001b4df084cccea0c127a53fc0346cb8d0 (diff)
downloadFreeBSD-src-3b7c3aa4be419cf5415989e5ad1552b65226d743.zip
FreeBSD-src-3b7c3aa4be419cf5415989e5ad1552b65226d743.tar.gz
Add "-s src_addr" option to allow setting of the source IP address.
Diffstat (limited to 'usr.bin/telnet')
-rw-r--r--usr.bin/telnet/commands.c38
-rw-r--r--usr.bin/telnet/main.c22
-rw-r--r--usr.bin/telnet/telnet.19
3 files changed, 60 insertions, 9 deletions
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index ebacc42..a4677e0 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -2100,7 +2100,7 @@ tn(argc, argv)
char *argv[];
{
register struct hostent *host = 0;
- struct sockaddr_in sin;
+ struct sockaddr_in sin, src_sin;
struct servent *sp = 0;
unsigned long temp;
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
@@ -2108,6 +2108,7 @@ tn(argc, argv)
unsigned long sourceroute(), srlen;
#endif
char *cmd, *hostp = 0, *portp = 0, *user = 0;
+ char *src_addr = NULL;
/* clear the socket address prior to use */
bzero((char *)&sin, sizeof(sin));
@@ -2143,6 +2144,14 @@ tn(argc, argv)
autologin = 1;
continue;
}
+ if (strcmp(*argv, "-s") == 0) {
+ --argc; ++argv;
+ if (argc == 0)
+ goto usage;
+ src_addr = *argv++;
+ --argc;
+ continue;
+ }
if (hostp == 0) {
hostp = *argv++;
--argc;
@@ -2154,13 +2163,31 @@ tn(argc, argv)
continue;
}
usage:
- printf("usage: telnet [-l user] [-a] host-name [port]\n");
+ printf("usage: telnet [-l user] [-a] [-s src_addr] host-name [port]\n");
setuid(getuid());
return 0;
}
if (hostp == 0)
goto usage;
+ if (src_addr != NULL) {
+ bzero((char *)&src_sin, sizeof(src_sin));
+ src_sin.sin_family = AF_INET;
+ if (!inet_aton(src_addr, &src_sin.sin_addr)) {
+ host = gethostbyname2(src_addr, AF_INET);
+ if (host == NULL) {
+ herror(src_addr);
+ return 0;
+ }
+ if (host->h_length != sizeof(src_sin.sin_addr)) {
+ fprintf(stderr, "telnet: gethostbyname2: invalid address\n");
+ return 0;
+ }
+ memcpy((void *)&src_sin.sin_addr, (void *)host->h_addr_list[0],
+ sizeof(src_sin.sin_addr));
+ }
+ }
+
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
if (hostp[0] == '@' || hostp[0] == '!') {
if ((hostname = strrchr(hostp, ':')) == NULL)
@@ -2285,6 +2312,13 @@ tn(argc, argv)
perror("setsockopt (SO_DEBUG)");
}
+ if (src_addr != NULL) {
+ if (bind(net, (struct sockaddr *)&src_sin, sizeof(src_sin)) == -1) {
+ perror("bind");
+ return 0;
+ }
+ }
+
if (connect(net, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
#if defined(h_addr) /* In 4.3, this is a #define */
if (host && host->h_addr_list[1]) {
diff --git a/usr.bin/telnet/main.c b/usr.bin/telnet/main.c
index 7f7c9ff..666005c 100644
--- a/usr.bin/telnet/main.c
+++ b/usr.bin/telnet/main.c
@@ -85,16 +85,18 @@ usage()
"\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
#else
"[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
- "\n\t[-n tracefile]",
+ "\n\t[-n tracefile] ",
#endif
#if defined(TN3270) && defined(unix)
# ifdef AUTHENTICATION
- "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
+ "[-noasynch] [-noasynctty]\n\t"
+ "[-noasyncnet] [-r] [-s src_addr] [-t transcom] ",
# else
- "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
+ "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t"
+ "[-s src_addr] [-t transcom]",
# endif
#else
- "[-r] ",
+ "[-r] [-s src_addr] ",
#endif
"[host-name [port]]"
);
@@ -114,6 +116,7 @@ main(argc, argv)
extern int optind;
int ch;
char *user, *strrchr();
+ char *src_addr = NULL;
#ifdef FORWARD
extern int forward_flags;
#endif /* FORWARD */
@@ -135,7 +138,7 @@ main(argc, argv)
rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
autologin = -1;
- while ((ch = getopt(argc, argv, "8EKLNS:X:acde:fFk:l:n:rt:x")) != -1) {
+ while ((ch = getopt(argc, argv, "8EKLNS:X:acde:fFk:l:n:rs:t:x")) != -1) {
switch(ch) {
case '8':
eight = 3; /* binary output and input */
@@ -255,6 +258,9 @@ main(argc, argv)
case 'r':
rlogin = '~';
break;
+ case 's':
+ src_addr = optarg;
+ break;
case 't':
#if defined(TN3270) && defined(unix)
transcom = tline;
@@ -283,7 +289,7 @@ main(argc, argv)
argv += optind;
if (argc) {
- char *args[7], **argp = args;
+ char *args[9], **argp = args;
if (argc > 2)
usage();
@@ -292,6 +298,10 @@ main(argc, argv)
*argp++ = "-l";
*argp++ = user;
}
+ if (src_addr) {
+ *argp++ = "-s";
+ *argp++ = src_addr;
+ }
*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 de161e8..4289733 100644
--- a/usr.bin/telnet/telnet.1
+++ b/usr.bin/telnet/telnet.1
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)telnet.1 8.5 (Berkeley) 3/1/94
-.\" $Id: telnet.1,v 1.9 1997/12/27 18:58:27 steve Exp $
+.\" $Id: telnet.1,v 1.10 1998/12/14 22:40:38 billf Exp $
.\"
.Dd March 1, 1994
.Dt TELNET 1
@@ -49,6 +49,7 @@ protocol
.Op Fl k Ar realm
.Op Fl l Ar user
.Op Fl n Ar tracefile
+.Op Fl s Ar src_addr
.Oo
.Ar host
.Op Ar port
@@ -184,6 +185,12 @@ mode, the escape character is set to the tilde (~) character,
unless modified by the
.Fl e
option.
+.It Fl s Ar src_addr
+Set the source IP address for the
+.Nm
+connection to
+.Ar src_addr ,
+which can be an IP address or a host name.
.It Fl x
Turns on encryption of the data stream if possible. This
option is not available outside of the United States and
OpenPOWER on IntegriCloud