1 diff -urN busybox-1.00.orig/include/usage.h busybox-1.00/include/usage.h
2 --- busybox-1.00.orig/include/usage.h 2006-06-27 13:34:21.000000000 +0200
3 +++ busybox-1.00/include/usage.h 2006-06-27 13:56:08.000000000 +0200
4 @@ -2445,23 +2445,30 @@
6 #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
7 #define telnet_trivial_usage \
8 - "[-a] [-l USER] HOST [PORT]"
9 + "[-a] [-l USER] [-b SRCADDR] HOST [PORT]"
10 #define telnet_full_usage \
11 "Telnet is used to establish interactive communication with another\n" \
12 "computer over a network using the TELNET protocol.\n\n" \
14 "\t-a\t\tAttempt an automatic login with the USER variable.\n" \
15 "\t-l USER\t\tAttempt an automatic login with the USER argument.\n" \
16 + "\t-b SRCADDR\tUse SRCADDR as local source address.\n" \
17 "\tHOST\t\tThe official name, alias or the IP address of the\n" \
18 "\t\t\tremote host.\n" \
19 "\tPORT\t\tThe remote port number to connect to. If it is not\n" \
20 "\t\t\tspecified, the default telnet (23) port is used."
22 #define telnet_trivial_usage \
24 + "[-b SRCADDR] HOST [PORT]"
25 #define telnet_full_usage \
26 "Telnet is used to establish interactive communication with another\n"\
27 - "computer over a network using the TELNET protocol."
28 + "computer over a network using the TELNET protocol.\n\n" \
30 + "\t-b SRCADDR\tUse SRCADDR as local source address.\n" \
31 + "\tHOST\t\tThe official name, alias or the IP address of the\n" \
32 + "\t\t\tremote host.\n" \
33 + "\tPORT\t\tThe remote port number to connect to. If it is not\n" \
34 + "\t\t\tspecified, the default telnet (23) port is used."
37 #ifdef CONFIG_FEATURE_TELNETD_INETD
38 diff -urN busybox-1.00.orig/networking/telnet.c busybox-1.00/networking/telnet.c
39 --- busybox-1.00.orig/networking/telnet.c 2004-09-14 19:24:58.000000000 +0200
40 +++ busybox-1.00/networking/telnet.c 2006-06-27 13:50:52.000000000 +0200
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 +#include <arpa/inet.h>
50 extern int telnet_main(int argc, char** argv)
53 - struct sockaddr_in s_in;
54 + struct sockaddr_in s_in, src_in;
56 struct pollfd ufds[2];
62 -#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
66 #ifdef CONFIG_FEATURE_AUTOWIDTH
67 get_terminal_width_height(0, &win_width, &win_height);
71 memset(&G, 0, sizeof G);
72 + memset(&src_in, 0, sizeof src_in);
74 if (tcgetattr(0, &G.termios_def) < 0)
78 #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
80 - while ((opt = getopt(argc, argv, "al:")) != EOF) {
81 +#define GETOPT_STRING "al:I:"
83 +#define GETOPT_STRING "I:"
85 + while ((opt = getopt(argc, argv, GETOPT_STRING)) != EOF) {
87 +#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
92 autologin = getenv("USER");
99 + if (sscanf(optarg, "%u.%u.%u.%u%c",
100 + &i1, &i2, &i3, &i4, &dummy) == 4) {
101 + unsigned char* ptr;
102 + ptr = (unsigned char*)&src_in.sin_addr;
116 @@ -681,12 +705,18 @@
121 - bb_lookup_host(&s_in, argv[1]);
122 - s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23);
125 - G.netfd = xconnect(&s_in);
126 + G.netfd = socket(AF_INET, SOCK_STREAM, 0);
127 + if (src_in.sin_addr.s_addr != 0) {
128 + if (bind(G.netfd, (struct sockaddr*)&src_in, sizeof(src_in)) == -1)
129 + bb_perror_msg_and_die("Unable to bind local address (%s)",
130 + inet_ntoa(src_in.sin_addr));
132 + if (connect(G.netfd, &s_in, sizeof(s_in)) < 0) {
133 + bb_perror_msg_and_die("Unable to connect to remote host (%s)",
134 + inet_ntoa(s_in.sin_addr));
136 + /*G.netfd = xconnect(&s_in);*/
138 setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);