commit-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Inetutils branch, master, updated. v2.0-8-gf70b506


From: Simon Josefsson
Subject: [SCM] GNU Inetutils branch, master, updated. v2.0-8-gf70b506
Date: Wed, 28 Apr 2021 14:15:30 -0400 (EDT)

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
-- 
GNU Inetutils 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]