Add ping -l (preload) and telnet -b (bind alias), closes #528
authorFlorian Fainelli <florian@openwrt.org>
Tue, 25 Jul 2006 08:22:29 +0000 (08:22 +0000)
committerFlorian Fainelli <florian@openwrt.org>
Tue, 25 Jul 2006 08:22:29 +0000 (08:22 +0000)
SVN-Revision: 4274

openwrt/package/busybox/patches/350-ping-opt-srcaddr.patch [new file with mode: 0644]
openwrt/package/busybox/patches/351-telnet-opt-srcaddr.patch [new file with mode: 0644]

diff --git a/openwrt/package/busybox/patches/350-ping-opt-srcaddr.patch b/openwrt/package/busybox/patches/350-ping-opt-srcaddr.patch
new file mode 100644 (file)
index 0000000..cec7910
--- /dev/null
@@ -0,0 +1,88 @@
+diff -urN busybox-1.00.orig/include/usage.h busybox-1.00/include/usage.h
+--- busybox-1.00.orig/include/usage.h  2006-06-27 12:44:26.000000000 +0200
++++ busybox-1.00/include/usage.h       2006-06-27 13:21:57.000000000 +0200
+@@ -1894,6 +1894,7 @@
+       "Options:\n" \
+       "\t-c COUNT\tSend only COUNT pings.\n" \
+       "\t-s SIZE\t\tSend SIZE data bytes in packets (default=56).\n" \
++      "\t-I IPADDR\tUse IPADDR as source address.\n" \
+       "\t-q\t\tQuiet mode, only displays output at start\n" \
+       "\t\t\tand when finished."
+ #endif
+diff -urN busybox-1.00.orig/networking/ping.c busybox-1.00/networking/ping.c
+--- busybox-1.00.orig/networking/ping.c        2006-06-27 12:44:26.000000000 +0200
++++ busybox-1.00/networking/ping.c     2006-06-27 13:19:04.000000000 +0200
+@@ -170,6 +170,7 @@
+ #else /* ! CONFIG_FEATURE_FANCY_PING */
+ /* full(er) version */
+ static struct sockaddr_in pingaddr;
++static struct sockaddr_in sourceaddr;
+ static int pingsock = -1;
+ static int datalen; /* intentionally uninitialized to work around gcc bug */
+@@ -342,6 +343,11 @@
+       pingsock = create_icmp_socket();
++      if (sourceaddr.sin_addr.s_addr != 0) {
++              if (bind(pingsock, (struct sockaddr*)&sourceaddr, sizeof(sourceaddr)) == -1)
++                      bb_error_msg_and_die("could not bind to address");
++      }
++
+       memset(&pingaddr, 0, sizeof(struct sockaddr_in));
+       pingaddr.sin_family = AF_INET;
+@@ -361,10 +367,14 @@
+       setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
+                          sizeof(sockopt));
+-      printf("PING %s (%s): %d data bytes\n",
++      printf("PING %s (%s)",
+                  hostent->h_name,
+-                 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
+-                 datalen);
++                 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr));
++      if (sourceaddr.sin_addr.s_addr != 0) {
++              printf(" from %s",
++                         inet_ntoa(*(struct in_addr *) &sourceaddr.sin_addr.s_addr));
++      }
++      printf(": %d data bytes\n", datalen);
+       signal(SIGINT, pingstats);
+@@ -400,6 +410,7 @@
+       argc--;
+       argv++;
+       options = 0;
++      memset(&sourceaddr, 0, sizeof(sourceaddr));
+       /* Parse any options */
+       while (argc >= 1 && **argv == '-') {
+               thisarg = *argv;
+@@ -420,6 +431,27 @@
+                       argv++;
+                       datalen = atoi(*argv);
+                       break;
++              case 'I':
++                      if (--argc <= 0)
++                              bb_show_usage();
++                      argv++;
++                      {
++                              char dummy;
++                              int i1, i2, i3, i4;
++                              if (sscanf(*argv, "%u.%u.%u.%u%c",
++                                                 &i1, &i2, &i3, &i4, &dummy) == 4) {
++                                      unsigned char* ptr;
++                                      ptr = (unsigned char*)&sourceaddr.sin_addr;
++                                      ptr[0] = i1;
++                                      ptr[1] = i2;
++                                      ptr[2] = i3;
++                                      ptr[3] = i4;
++                              }
++                              else {
++                                      bb_show_usage();
++                              }
++                      }
++                      break;
+               default:
+                       bb_show_usage();
+               }
diff --git a/openwrt/package/busybox/patches/351-telnet-opt-srcaddr.patch b/openwrt/package/busybox/patches/351-telnet-opt-srcaddr.patch
new file mode 100644 (file)
index 0000000..d343df2
--- /dev/null
@@ -0,0 +1,139 @@
+diff -urN busybox-1.00.orig/include/usage.h busybox-1.00/include/usage.h
+--- busybox-1.00.orig/include/usage.h  2006-06-27 13:34:21.000000000 +0200
++++ busybox-1.00/include/usage.h       2006-06-27 13:56:08.000000000 +0200
+@@ -2445,23 +2445,30 @@
+ #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
+ #define telnet_trivial_usage \
+-      "[-a] [-l USER] HOST [PORT]"
++      "[-a] [-l USER] [-b SRCADDR] HOST [PORT]"
+ #define telnet_full_usage \
+       "Telnet is used to establish interactive communication with another\n" \
+       "computer over a network using the TELNET protocol.\n\n" \
+       "Options:\n" \
+       "\t-a\t\tAttempt an automatic login with the USER variable.\n" \
+       "\t-l USER\t\tAttempt an automatic login with the USER argument.\n" \
++      "\t-b SRCADDR\tUse SRCADDR as local source address.\n" \
+       "\tHOST\t\tThe official name, alias or the IP address of the\n" \
+       "\t\t\tremote host.\n" \
+       "\tPORT\t\tThe remote port number to connect to. If it is not\n" \
+       "\t\t\tspecified, the default telnet (23) port is used."
+ #else
+ #define telnet_trivial_usage \
+-      "HOST [PORT]"
++      "[-b SRCADDR] HOST [PORT]"
+ #define telnet_full_usage \
+       "Telnet is used to establish interactive communication with another\n"\
+-      "computer over a network using the TELNET protocol."
++      "computer over a network using the TELNET protocol.\n\n" \
++      "Options:\n" \
++      "\t-b SRCADDR\tUse SRCADDR as local source address.\n" \
++      "\tHOST\t\tThe official name, alias or the IP address of the\n" \
++      "\t\t\tremote host.\n" \
++      "\tPORT\t\tThe remote port number to connect to. If it is not\n" \
++      "\t\t\tspecified, the default telnet (23) port is used."
+ #endif
+ #ifdef CONFIG_FEATURE_TELNETD_INETD
+diff -urN busybox-1.00.orig/networking/telnet.c busybox-1.00/networking/telnet.c
+--- busybox-1.00.orig/networking/telnet.c      2004-09-14 19:24:58.000000000 +0200
++++ busybox-1.00/networking/telnet.c   2006-06-27 13:50:52.000000000 +0200
+@@ -44,6 +44,7 @@
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
++#include <arpa/inet.h>
+ #include "busybox.h"
+ #if 0
+@@ -627,7 +628,7 @@
+ extern int telnet_main(int argc, char** argv)
+ {
+       int len;
+-      struct sockaddr_in s_in;
++      struct sockaddr_in s_in, src_in;
+ #ifdef USE_POLL
+       struct pollfd ufds[2];
+ #else
+@@ -635,9 +636,7 @@
+       int maxfd;
+ #endif
+-#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
+       int opt;
+-#endif
+ #ifdef CONFIG_FEATURE_AUTOWIDTH
+       get_terminal_width_height(0, &win_width, &win_height);
+@@ -648,6 +647,7 @@
+ #endif
+       memset(&G, 0, sizeof G);
++      memset(&src_in, 0, sizeof src_in);
+       if (tcgetattr(0, &G.termios_def) < 0)
+               exit(1);
+@@ -660,14 +660,38 @@
+ #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
+       autologin = NULL;
+-      while ((opt = getopt(argc, argv, "al:")) != EOF) {
++#define GETOPT_STRING "al:I:"
++#else
++#define GETOPT_STRING "I:"
++#endif
++      while ((opt = getopt(argc, argv, GETOPT_STRING)) != EOF) {
+               switch (opt) {
++#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
+                       case 'l':
+                               autologin = optarg;
+                               break;
+                       case 'a':
+                               autologin = getenv("USER");
+                               break;
++#endif
++                      case 'b':
++                              {
++                                      char dummy;
++                                      int i1, i2, i3, i4;
++                                      if (sscanf(optarg, "%u.%u.%u.%u%c",
++                                                         &i1, &i2, &i3, &i4, &dummy) == 4) {
++                                              unsigned char* ptr;
++                                              ptr = (unsigned char*)&src_in.sin_addr;
++                                              ptr[0] = i1;
++                                              ptr[1] = i2;
++                                              ptr[2] = i3;
++                                              ptr[3] = i4;
++                                      }
++                                      else {
++                                              bb_show_usage();
++                                      }
++                              }
++                              break;
+                       case '?':
+                               bb_show_usage();
+                               break;
+@@ -681,12 +705,18 @@
+                       bb_show_usage();
+       } else
+               bb_show_usage();
+-#else
+-      bb_lookup_host(&s_in, argv[1]);
+-      s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23);
+-#endif
+-      G.netfd = xconnect(&s_in);
++      G.netfd = socket(AF_INET, SOCK_STREAM, 0);
++      if (src_in.sin_addr.s_addr != 0) {
++              if (bind(G.netfd, (struct sockaddr*)&src_in, sizeof(src_in)) == -1)
++                      bb_perror_msg_and_die("Unable to bind local address (%s)",
++                                                                inet_ntoa(src_in.sin_addr));
++      }
++      if (connect(G.netfd, &s_in, sizeof(s_in)) < 0) {
++              bb_perror_msg_and_die("Unable to connect to remote host (%s)",
++                                                        inet_ntoa(s_in.sin_addr));
++      }
++      /*G.netfd = xconnect(&s_in);*/
+       setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);