[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
telnet --bind
From: |
Simon Josefsson |
Subject: |
telnet --bind |
Date: |
Wed, 28 Apr 2021 20:23:47 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Hi. I'm trying to get Debian to use inetutils's telnet by default, and
one discrepency compared to their current implementation (netkit) was
the --bind parameter. It seems useful, so I implemented it in inetutils
(see patch below). It appears to work -- notice the different listen
addresses in the ss output below.
/Simon
jas@latte:~/src/inetutils/telnet$ ip a|grep 192
inet 192.168.10.43/24 brd 192.168.10.255 scope global dynamic noprefixroute
wlp2s0
inet 192.168.10.49/24 scope global secondary wlp2s0
jas@latte:~/src/inetutils/telnet$ ./telnet -b 192.168.10.49 www.sjd.se 80
Trying 178.174.241.102...
Connected to www.sjd.se.
Escape character is '^]'.
^]
telnet> ^Z
[1]+ Stoppad ./telnet -b 192.168.10.49 www.sjd.se 80
jas@latte:~/src/inetutils/telnet$ sudo ss|grep 102|tail -1
tcp ESTAB 0 0 192.168.10.49:46993
178.174.241.102:http
jas@latte:~/src/inetutils/telnet$ fg
./telnet -b 192.168.10.49 www.sjd.se 80
quit
Connection closed.
jas@latte:~/src/inetutils/telnet$ ./telnet -b 192.168.10.43 www.sjd.se 80
Trying 178.174.241.102...
Connected to www.sjd.se.
Escape character is '^]'.
^]
telnet> ^Z
[1]+ Stoppad ./telnet -b 192.168.10.43 www.sjd.se 80
jas@latte:~/src/inetutils/telnet$ sudo ss|grep 102|tail -1
tcp ESTAB 0 0 192.168.10.43:45907
178.174.241.102:http
jas@latte:~/src/inetutils/telnet$ fg
./telnet -b 192.168.10.43 www.sjd.se 80
quit
Connection closed.
jas@latte:~/src/inetutils/telnet$
Simon Josefsson via Commit-inetutils <commit-inetutils@gnu.org> writes:
> This is an automated email from the git hooks/post-receive script. It was
> generated because a ref change was pushed to the repository containing
> the project "GNU Inetutils ".
>
> The branch, master has been updated
> via f70b506e3746bce45d1b684d5ac5ef513af73df4 (commit)
> from 4587969cf6aa0da90508ff1e3fd7976420ee3e7c (commit)
>
> Those revisions listed above that are new to this repository have
> not appeared on any other notification email; so we list those
> revisions in full, below.
>
> - Log -----------------------------------------------------------------
> http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=f70b506e3746bce45d1b684d5ac5ef513af73df4
>
>
> commit f70b506e3746bce45d1b684d5ac5ef513af73df4
> Author: Simon Josefsson <simon@josefsson.org>
> Date: Wed Apr 28 20:14:09 2021 +0200
>
> telnet: Support --bind (-b) for NetKit compatibility.
>
> * NEWS: Add.
> * doc/inetutils.texi (telnet invocation): Add --bind (-b).
> * telnet/commands.c (tn): New variables hostaddr and srchostp.
> Parse -b parameter. Update usage string. If -b is set, call
> getaddrinfo on it and pass that ai_addr on to bind.
> * telnet/main.c (srcaddr): New global variable.
> (argp_options): Add --bind (-b).
> (parse_opt): Set srcaddr to -b value.
> (main): Propagate -b value to tn function.
>
> diff --git a/ChangeLog b/ChangeLog
> index 3c0f942..ad515b1 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,16 @@
> +2021-04-28 Simon Josefsson <simon@josefsson.org>
> +
> + telnet: Support --bind (-b) for NetKit compatibility.
> + * NEWS: Add.
> + * doc/inetutils.texi (telnet invocation): Add --bind (-b).
> + * telnet/commands.c (tn): New variables hostaddr and srchostp.
> + Parse -b parameter. Update usage string. If -b is set, call
> + getaddrinfo on it and pass that ai_addr on to bind.
> + * telnet/main.c (srcaddr): New global variable.
> + (argp_options): Add --bind (-b).
> + (parse_opt): Set srcaddr to -b value.
> + (main): Propagate -b value to tn function.
> +
> 2021-02-11 Simon Josefsson <simon@josefsson.org>
>
> * TODO: Add items discussed on mailing list.
> diff --git a/NEWS b/NEWS
> index 6d3c9af..1f13094 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -2,6 +2,12 @@ GNU inetutils NEWS -- history of user-visible changes.
>
> * Noteworthy changes in release ?.? (????-??-??) [?]
>
> +* telnet
> +
> +** Implement --bind (-b).
> +
> +This is used to bind to a particular local socket, for compatibility
> +with NetKit's telnet.
>
> * Noteworthy changes in release 2.0 (2021-02-05) [stable]
>
> diff --git a/doc/inetutils.texi b/doc/inetutils.texi
> index 5fb7675..ba7c9d2 100644
> --- a/doc/inetutils.texi
> +++ b/doc/inetutils.texi
> @@ -2996,6 +2996,12 @@ Use an 8-bit data path.
> @opindex --login
> Attempt automatic login.
>
> +@item -b @var{address}
> +@itemx --bind=@var{address}
> +@opindex -b
> +@opindex --bind
> +Bind to specific local @var{address}.
> +
> @item -c
> @itemx --no-rc
> @opindex -c
> diff --git a/telnet/commands.c b/telnet/commands.c
> index 36a951e..5cc9b4d 100644
> --- a/telnet/commands.c
> +++ b/telnet/commands.c
> @@ -2449,7 +2449,7 @@ int
> tn (int argc, char *argv[])
> {
> #ifdef IPV6
> - struct addrinfo *result, *aip, hints;
> + struct addrinfo *result, *aip, hints, *hostaddr;
> #else
> struct hostent *host = 0;
> struct sockaddr_in sin;
> @@ -2458,7 +2458,7 @@ tn (int argc, char *argv[])
> #endif
> const int on = 1;
> int err;
> - char *cmd, *hostp = 0, *portp = 0, *user = 0;
> + char *cmd, *hostp = 0, *portp = 0, *user = 0, *srchostp = 0;
> #if defined HAVE_IDN || defined HAVE_IDN2
> char *hosttmp = 0;
> #endif
> @@ -2506,6 +2506,16 @@ tn (int argc, char *argv[])
> --argc;
> continue;
> }
> + if (strcmp (*argv, "-b") == 0)
> + {
> + --argc;
> + ++argv;
> + if (argc == 0)
> + goto usage;
> + srchostp = *argv++;
> + --argc;
> + continue;
> + }
> if (strcmp (*argv, "-a") == 0)
> {
> --argc;
> @@ -2546,7 +2556,7 @@ tn (int argc, char *argv[])
> continue;
> }
> usage:
> - printf ("usage: %s [-4] [-6] [-l user] [-a] host-name [port]\n", cmd);
> + printf ("usage: %s [-4] [-6] [-l user] [-b addr] [-a] host-name
> [port]\n", cmd);
> return 0;
> }
> if (hostp == 0)
> @@ -2624,6 +2634,18 @@ tn (int argc, char *argv[])
> hints.ai_flags = AI_IDN;
> # endif
>
> + if (srchostp)
> + {
> + err = getaddrinfo (srchostp, "0", &hints, &hostaddr);
> + if (err < 0)
> + {
> + printf ("Could not resolve %s: %s\n", srchostp,
> + gai_strerror (err));
> + return 0;
> + }
> + hints.ai_family = hostaddr->ai_family;
> + }
> +
> err = getaddrinfo (hostp, portp, &hints, &result);
> if (err)
> {
> @@ -2669,6 +2691,16 @@ tn (int argc, char *argv[])
> return 0;
> }
>
> + if (srchostp)
> + {
> + err = bind(net, hostaddr->ai_addr, hostaddr->ai_addrlen);
> + if (err < 0)
> + {
> + perror ("telnet: bind");
> + return 0;
> + }
> + }
> +
> if (debug)
> {
> err = setsockopt (net, SOL_SOCKET, SO_DEBUG, &on, sizeof (on));
> @@ -2698,6 +2730,8 @@ tn (int argc, char *argv[])
> }
> while (!connected);
>
> + if (srchostp)
> + freeaddrinfo(hostaddr);
> freeaddrinfo (result);
> #else /* !IPV6 */
> temp = inet_addr (hostp);
> diff --git a/telnet/main.c b/telnet/main.c
> index a80d3c3..c790d6e 100644
> --- a/telnet/main.c
> +++ b/telnet/main.c
> @@ -105,7 +105,7 @@ tninit (void)
> }
>
> int family = 0;
> -char *user;
> +char *user, *srcaddr;
> #ifdef FORWARD
> extern int forward_flags;
> #endif /* FORWARD */
> @@ -132,6 +132,8 @@ static struct argp_option argp_options[] = {
> /* FIXME: Called "8bit" in r* utils */
> { "binary", '8', NULL, 0,
> "use an 8-bit data transmission", GRID+1 },
> + { "bind", 'b', "ADDRESS", 0,
> + "bind to specific local ADDRESS", GRID+1 },
> { "login", 'a', NULL, 0,
> "attempt automatic login", GRID+1 },
> { "no-rc", 'c', NULL, 0,
> @@ -313,6 +315,10 @@ parse_opt (int key, char *arg, struct argp_state *state
> _GL_UNUSED_PARAMETER)
> break;
> #endif
>
> + case 'b':
> + srcaddr = arg;
> + break;
> +
> default:
> return ARGP_ERR_UNKNOWN;
> }
> @@ -374,7 +380,7 @@ main (int argc, char *argv[])
> {
> /* The command line contains at least one argument.
> */
> - char *args[8], **argp = args;
> + char *args[10], **argp = args;
>
> if (argc > 2)
> error (EXIT_FAILURE, 0, "too many arguments");
> @@ -384,6 +390,11 @@ main (int argc, char *argv[])
> *argp++ = "-l";
> *argp++ = user;
> }
> + if (srcaddr)
> + {
> + *argp++ = "-b";
> + *argp++ = srcaddr;
> + }
> if (family == 4)
> *argp++ = "-4";
> else if (family == 6)
>
> -----------------------------------------------------------------------
>
> Summary of changes:
> ChangeLog | 13 +++++++++++++
> NEWS | 6 ++++++
> doc/inetutils.texi | 6 ++++++
> telnet/commands.c | 40 +++++++++++++++++++++++++++++++++++++---
> telnet/main.c | 15 +++++++++++++--
> 5 files changed, 75 insertions(+), 5 deletions(-)
>
>
> hooks/post-receive
signature.asc
Description: PGP signature
- telnet --bind,
Simon Josefsson <=