summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2007-01-10 09:28:01 +0000
committerDenis Vlasenko2007-01-10 09:28:01 +0000
commit9de420c27cbbbd99bedc95782a6937039ff071bb (patch)
tree01c0783874d5c429b4f71496f18028d46afae302 /networking
parent62a6983a818ce701b924f84bf23716c4fbff170a (diff)
downloadbusybox-9de420c27cbbbd99bedc95782a6937039ff071bb.zip
busybox-9de420c27cbbbd99bedc95782a6937039ff071bb.tar.gz
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')
-rw-r--r--networking/telnet.c31
-rw-r--r--networking/telnetd.c2
2 files changed, 11 insertions, 22 deletions
diff --git a/networking/telnet.c b/networking/telnet.c
index e65b691..5ca64e1 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);
}
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 604f65c..a0ee2c3 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -414,7 +414,7 @@ telnetd_main(int argc, char **argv)
if (IS_INETD) {
sessions = make_new_session(0, 1);
} else {
- master_fd = create_and_bind_socket_ip4or6(opt_bindaddr, portnbr);
+ master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
xlisten(master_fd, 1);
if (!(opt & OPT_FOREGROUND))
xdaemon(0, 0);