diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-10 12:28:01 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-10 12:28:01 +0300 |
commit | 9de420c27cbbbd99bedc95782a6937039ff071bb (patch) | |
tree | 01c0783874d5c429b4f71496f18028d46afae302 /networking/telnet.c | |
parent | 62a6983a818ce701b924f84bf23716c4fbff170a (diff) |
Improve generic ipv4+ipv6 support in libbb.
Convert telnet to it. Now this works:
telnetd -b [::1]:1234 - bind to IPv6 non-standard port
telnet [::1]:1234 - connect to IPv6 non-standard port
telnet ::1 1234 - same
This does not require ANY ipv6-specific code in applets
(no struct sockaddr_in6. In fact, no sockaddr_in, too).
Diffstat (limited to 'networking/telnet.c')
-rw-r--r-- | networking/telnet.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/networking/telnet.c b/networking/telnet.c index e65b6918d..5ca64e133 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -22,15 +22,7 @@ */ #include <termios.h> -#include <unistd.h> -#include <errno.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <signal.h> #include <arpa/telnet.h> -#include <sys/types.h> -#include <sys/socket.h> #include <netinet/in.h> #include "busybox.h" @@ -593,8 +585,9 @@ static void cookmode(void) int telnet_main(int argc, char** argv) { + char *host; + int port; int len; - struct sockaddr_in s_in; #ifdef USE_POLL struct pollfd ufds[2]; #else @@ -610,11 +603,10 @@ int telnet_main(int argc, char** argv) ttype = getenv("TERM"); #endif - memset(&G, 0, sizeof G); + /* memset(&G, 0, sizeof G); - already is */ if (tcgetattr(0, &G.termios_def) >= 0) { G.do_termios = 1; - G.termios_raw = G.termios_def; cfmakeraw(&G.termios_raw); } @@ -627,19 +619,18 @@ int telnet_main(int argc, char** argv) autologin = getenv("USER"); if (optind < argc) { - bb_lookup_host(&s_in, argv[optind++]); - s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] : + host = argv[optind++]; + port = bb_lookup_port((optind < argc) ? argv[optind++] : "telnet", "tcp", 23); if (optind < argc) 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); + host = argv[1]; + port = bb_lookup_port((argc > 2) ? argv[2] : "telnet", "tcp", 23); #endif - - G.netfd = xconnect_tcp_v4(&s_in); + G.netfd = create_and_connect_stream_or_die(host, port); setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); @@ -655,8 +646,7 @@ int telnet_main(int argc, char** argv) maxfd = G.netfd + 1; #endif - while (1) - { + while (1) { #ifndef USE_POLL fd_set rfds = readfds; @@ -700,8 +690,7 @@ int telnet_main(int argc, char** argv) { len = read(G.netfd, G.buf, DATABUFSIZE); - if (len <= 0) - { + if (len <= 0) { WriteCS(1, "Connection closed by foreign host.\r\n"); doexit(1); } |