diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-21 09:22:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-21 09:22:28 +0000 |
commit | 1101d1c98068d7a49942d6e9e11ca2e789a9cdba (patch) | |
tree | 8fcf79323f16e9e29ad0e257184ce4714b29c23b /networking/telnet.c | |
parent | 84c8daa11f4c656bb4ba50b6e1c6d3b34c0f1b39 (diff) | |
download | busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.tar.gz busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.tar.bz2 busybox-w32-1101d1c98068d7a49942d6e9e11ca2e789a9cdba.zip |
telnet: shrink
telnetd: shrink, and fix issue file printing
test: better and shorter usage text
function old new delta
putiac2 51 50 -1
putiac 24 20 -4
handlenetoutput 95 91 -4
telnet_main 1480 1475 -5
iacflush 37 32 -5
make_new_session 436 421 -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-34) Total: -34 bytes
Diffstat (limited to 'networking/telnet.c')
-rw-r--r-- | networking/telnet.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/networking/telnet.c b/networking/telnet.c index aaaa2648f..63ee38088 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
@@ -52,9 +52,10 @@ enum { | |||
52 | 52 | ||
53 | typedef unsigned char byte; | 53 | typedef unsigned char byte; |
54 | 54 | ||
55 | enum { netfd = 3 }; | ||
56 | |||
55 | struct globals { | 57 | struct globals { |
56 | int netfd; /* console fd:s are 0 and 1 (and 2) */ | 58 | int iaclen; /* could even use byte, but it's a loss on x86 */ |
57 | short iaclen; /* could even use byte */ | ||
58 | byte telstate; /* telnet negotiation state from network input */ | 59 | byte telstate; /* telnet negotiation state from network input */ |
59 | byte telwish; /* DO, DONT, WILL, WONT */ | 60 | byte telwish; /* DO, DONT, WILL, WONT */ |
60 | byte charmode; | 61 | byte charmode; |
@@ -95,7 +96,7 @@ static int subneg(byte c); | |||
95 | 96 | ||
96 | static void iacflush(void) | 97 | static void iacflush(void) |
97 | { | 98 | { |
98 | write(G.netfd, G.iacbuf, G.iaclen); | 99 | write(netfd, G.iacbuf, G.iaclen); |
99 | G.iaclen = 0; | 100 | G.iaclen = 0; |
100 | } | 101 | } |
101 | 102 | ||
@@ -191,7 +192,7 @@ static void handlenetoutput(int len) | |||
191 | outbuf[j++] = 0x00; | 192 | outbuf[j++] = 0x00; |
192 | } | 193 | } |
193 | if (j > 0) | 194 | if (j > 0) |
194 | write(G.netfd, outbuf, j); | 195 | write(netfd, outbuf, j); |
195 | } | 196 | } |
196 | 197 | ||
197 | static void handlenetinput(int len) | 198 | static void handlenetinput(int len) |
@@ -545,7 +546,7 @@ static void cookmode(void) | |||
545 | #define USE_POLL 1 | 546 | #define USE_POLL 1 |
546 | 547 | ||
547 | int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 548 | int telnet_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
548 | int telnet_main(int argc, char **argv) | 549 | int telnet_main(int argc UNUSED_PARAM, char **argv) |
549 | { | 550 | { |
550 | char *host; | 551 | char *host; |
551 | int port; | 552 | int port; |
@@ -573,9 +574,6 @@ int telnet_main(int argc, char **argv) | |||
573 | cfmakeraw(&G.termios_raw); | 574 | cfmakeraw(&G.termios_raw); |
574 | } | 575 | } |
575 | 576 | ||
576 | if (argc < 2) | ||
577 | bb_show_usage(); | ||
578 | |||
579 | #if ENABLE_FEATURE_TELNET_AUTOLOGIN | 577 | #if ENABLE_FEATURE_TELNET_AUTOLOGIN |
580 | if (1 & getopt32(argv, "al:", &G.autologin)) | 578 | if (1 & getopt32(argv, "al:", &G.autologin)) |
581 | G.autologin = getenv("USER"); | 579 | G.autologin = getenv("USER"); |
@@ -590,20 +588,20 @@ int telnet_main(int argc, char **argv) | |||
590 | if (*argv) /* extra params?? */ | 588 | if (*argv) /* extra params?? */ |
591 | bb_show_usage(); | 589 | bb_show_usage(); |
592 | 590 | ||
593 | G.netfd = create_and_connect_stream_or_die(host, port); | 591 | xmove_fd(create_and_connect_stream_or_die(host, port), netfd); |
594 | 592 | ||
595 | setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); | 593 | setsockopt(netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); |
596 | 594 | ||
597 | signal(SIGINT, fgotsig); | 595 | signal(SIGINT, fgotsig); |
598 | 596 | ||
599 | #ifdef USE_POLL | 597 | #ifdef USE_POLL |
600 | ufds[0].fd = 0; ufds[1].fd = G.netfd; | 598 | ufds[0].fd = 0; ufds[1].fd = netfd; |
601 | ufds[0].events = ufds[1].events = POLLIN; | 599 | ufds[0].events = ufds[1].events = POLLIN; |
602 | #else | 600 | #else |
603 | FD_ZERO(&readfds); | 601 | FD_ZERO(&readfds); |
604 | FD_SET(STDIN_FILENO, &readfds); | 602 | FD_SET(STDIN_FILENO, &readfds); |
605 | FD_SET(G.netfd, &readfds); | 603 | FD_SET(netfd, &readfds); |
606 | maxfd = G.netfd + 1; | 604 | maxfd = netfd + 1; |
607 | #endif | 605 | #endif |
608 | 606 | ||
609 | while (1) { | 607 | while (1) { |
@@ -642,17 +640,17 @@ int telnet_main(int argc, char **argv) | |||
642 | #ifdef USE_POLL | 640 | #ifdef USE_POLL |
643 | if (ufds[1].revents) /* well, should check POLLIN, but ... */ | 641 | if (ufds[1].revents) /* well, should check POLLIN, but ... */ |
644 | #else | 642 | #else |
645 | if (FD_ISSET(G.netfd, &rfds)) | 643 | if (FD_ISSET(netfd, &rfds)) |
646 | #endif | 644 | #endif |
647 | { | 645 | { |
648 | len = read(G.netfd, G.buf, DATABUFSIZE); | 646 | len = read(netfd, G.buf, DATABUFSIZE); |
649 | if (len <= 0) { | 647 | if (len <= 0) { |
650 | write_str(1, "Connection closed by foreign host\r\n"); | 648 | write_str(1, "Connection closed by foreign host\r\n"); |
651 | doexit(EXIT_FAILURE); | 649 | doexit(EXIT_FAILURE); |
652 | } | 650 | } |
653 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len)); | 651 | TRACE(0, ("Read netfd (%d): %d\n", netfd, len)); |
654 | handlenetinput(len); | 652 | handlenetinput(len); |
655 | } | 653 | } |
656 | } | 654 | } |
657 | } | 655 | } /* while (1) */ |
658 | } | 656 | } |