aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
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 e65b6918d..5ca64e133 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -22,15 +22,7 @@
22 */ 22 */
23 23
24#include <termios.h> 24#include <termios.h>
25#include <unistd.h>
26#include <errno.h>
27#include <stdlib.h>
28#include <stdarg.h>
29#include <string.h>
30#include <signal.h>
31#include <arpa/telnet.h> 25#include <arpa/telnet.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <netinet/in.h> 26#include <netinet/in.h>
35#include "busybox.h" 27#include "busybox.h"
36 28
@@ -593,8 +585,9 @@ static void cookmode(void)
593 585
594int telnet_main(int argc, char** argv) 586int telnet_main(int argc, char** argv)
595{ 587{
588 char *host;
589 int port;
596 int len; 590 int len;
597 struct sockaddr_in s_in;
598#ifdef USE_POLL 591#ifdef USE_POLL
599 struct pollfd ufds[2]; 592 struct pollfd ufds[2];
600#else 593#else
@@ -610,11 +603,10 @@ int telnet_main(int argc, char** argv)
610 ttype = getenv("TERM"); 603 ttype = getenv("TERM");
611#endif 604#endif
612 605
613 memset(&G, 0, sizeof G); 606 /* memset(&G, 0, sizeof G); - already is */
614 607
615 if (tcgetattr(0, &G.termios_def) >= 0) { 608 if (tcgetattr(0, &G.termios_def) >= 0) {
616 G.do_termios = 1; 609 G.do_termios = 1;
617
618 G.termios_raw = G.termios_def; 610 G.termios_raw = G.termios_def;
619 cfmakeraw(&G.termios_raw); 611 cfmakeraw(&G.termios_raw);
620 } 612 }
@@ -627,19 +619,18 @@ int telnet_main(int argc, char** argv)
627 autologin = getenv("USER"); 619 autologin = getenv("USER");
628 620
629 if (optind < argc) { 621 if (optind < argc) {
630 bb_lookup_host(&s_in, argv[optind++]); 622 host = argv[optind++];
631 s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] : 623 port = bb_lookup_port((optind < argc) ? argv[optind++] :
632 "telnet", "tcp", 23); 624 "telnet", "tcp", 23);
633 if (optind < argc) 625 if (optind < argc)
634 bb_show_usage(); 626 bb_show_usage();
635 } else 627 } else
636 bb_show_usage(); 628 bb_show_usage();
637#else 629#else
638 bb_lookup_host(&s_in, argv[1]); 630 host = argv[1];
639 s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23); 631 port = bb_lookup_port((argc > 2) ? argv[2] : "telnet", "tcp", 23);
640#endif 632#endif
641 633 G.netfd = create_and_connect_stream_or_die(host, port);
642 G.netfd = xconnect_tcp_v4(&s_in);
643 634
644 setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); 635 setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);
645 636
@@ -655,8 +646,7 @@ int telnet_main(int argc, char** argv)
655 maxfd = G.netfd + 1; 646 maxfd = G.netfd + 1;
656#endif 647#endif
657 648
658 while (1) 649 while (1) {
659 {
660#ifndef USE_POLL 650#ifndef USE_POLL
661 fd_set rfds = readfds; 651 fd_set rfds = readfds;
662 652
@@ -700,8 +690,7 @@ int telnet_main(int argc, char** argv)
700 { 690 {
701 len = read(G.netfd, G.buf, DATABUFSIZE); 691 len = read(G.netfd, G.buf, DATABUFSIZE);
702 692
703 if (len <= 0) 693 if (len <= 0) {
704 {
705 WriteCS(1, "Connection closed by foreign host.\r\n"); 694 WriteCS(1, "Connection closed by foreign host.\r\n");
706 doexit(1); 695 doexit(1);
707 } 696 }
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 604f65c91..a0ee2c345 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -414,7 +414,7 @@ telnetd_main(int argc, char **argv)
414 if (IS_INETD) { 414 if (IS_INETD) {
415 sessions = make_new_session(0, 1); 415 sessions = make_new_session(0, 1);
416 } else { 416 } else {
417 master_fd = create_and_bind_socket_ip4or6(opt_bindaddr, portnbr); 417 master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
418 xlisten(master_fd, 1); 418 xlisten(master_fd, 1);
419 if (!(opt & OPT_FOREGROUND)) 419 if (!(opt & OPT_FOREGROUND))
420 xdaemon(0, 0); 420 xdaemon(0, 0);