summaryrefslogtreecommitdiff
path: root/networking/telnet.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 02:06:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 02:06:08 +0000
commit78b0e379d7c2db84eec34ccd89cf9afb67b94901 (patch)
treeae5bb34caa3b88968102e93193a01e4d90109b92 /networking/telnet.c
parentaddabd6f16aece578d94d810d3a9e9dc88f2cdb7 (diff)
downloadbusybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.gz
busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.bz2
busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.zip
Vladimir's last_patch_15
Diffstat (limited to 'networking/telnet.c')
-rw-r--r--networking/telnet.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/networking/telnet.c b/networking/telnet.c
index 2587193e2..ce82a0ee8 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -64,8 +64,8 @@ static const int DOTRACE = 1;
64#include <sys/time.h> 64#include <sys/time.h>
65#endif 65#endif
66 66
67static const int DATABUFSIZE = 128; 67#define DATABUFSIZE 128
68static const int IACBUFSIZE = 128; 68#define IACBUFSIZE 128
69 69
70static const int CHM_TRY = 0; 70static const int CHM_TRY = 0;
71static const int CHM_ON = 1; 71static const int CHM_ON = 1;
@@ -90,15 +90,14 @@ typedef unsigned char byte;
90static struct Globalvars { 90static struct Globalvars {
91 int netfd; /* console fd:s are 0 and 1 (and 2) */ 91 int netfd; /* console fd:s are 0 and 1 (and 2) */
92 /* same buffer used both for network and console read/write */ 92 /* same buffer used both for network and console read/write */
93 char * buf; /* allocating so static size is smaller */ 93 char buf[DATABUFSIZE]; /* allocating so static size is smaller */
94 short len;
95 byte telstate; /* telnet negotiation state from network input */ 94 byte telstate; /* telnet negotiation state from network input */
96 byte telwish; /* DO, DONT, WILL, WONT */ 95 byte telwish; /* DO, DONT, WILL, WONT */
97 byte charmode; 96 byte charmode;
98 byte telflags; 97 byte telflags;
99 byte gotsig; 98 byte gotsig;
100 /* buffer to handle telnet negotiations */ 99 /* buffer to handle telnet negotiations */
101 char * iacbuf; 100 char iacbuf[IACBUFSIZE];
102 short iaclen; /* could even use byte */ 101 short iaclen; /* could even use byte */
103 struct termios termios_def; 102 struct termios termios_def;
104 struct termios termios_raw; 103 struct termios termios_raw;
@@ -198,7 +197,7 @@ static void conescape()
198 G.gotsig = 0; 197 G.gotsig = 0;
199 198
200} 199}
201static void handlenetoutput() 200static void handlenetoutput(int len)
202{ 201{
203 /* here we could do smart tricks how to handle 0xFF:s in output 202 /* here we could do smart tricks how to handle 0xFF:s in output
204 * stream like writing twice every sequence of FF:s (thus doing 203 * stream like writing twice every sequence of FF:s (thus doing
@@ -209,7 +208,7 @@ static void handlenetoutput()
209 int i; 208 int i;
210 byte * p = G.buf; 209 byte * p = G.buf;
211 210
212 for (i = G.len; i > 0; i--, p++) 211 for (i = len; i > 0; i--, p++)
213 { 212 {
214 if (*p == 0x1d) 213 if (*p == 0x1d)
215 { 214 {
@@ -219,16 +218,16 @@ static void handlenetoutput()
219 if (*p == 0xff) 218 if (*p == 0xff)
220 *p = 0x7f; 219 *p = 0x7f;
221 } 220 }
222 write(G.netfd, G.buf, G.len); 221 write(G.netfd, G.buf, len);
223} 222}
224 223
225 224
226static void handlenetinput() 225static void handlenetinput(int len)
227{ 226{
228 int i; 227 int i;
229 int cstart = 0; 228 int cstart = 0;
230 229
231 for (i = 0; i < G.len; i++) 230 for (i = 0; i < len; i++)
232 { 231 {
233 byte c = G.buf[i]; 232 byte c = G.buf[i];
234 233
@@ -290,11 +289,11 @@ static void handlenetinput()
290 if (G.iaclen) iacflush(); 289 if (G.iaclen) iacflush();
291 if (G.telstate == TS_0) G.telstate = 0; 290 if (G.telstate == TS_0) G.telstate = 0;
292 291
293 G.len = cstart; 292 len = cstart;
294 } 293 }
295 294
296 if (G.len) 295 if (len)
297 write(1, G.buf, G.len); 296 write(1, G.buf, len);
298} 297}
299 298
300 299
@@ -530,6 +529,7 @@ extern int telnet_main(int argc, char** argv)
530{ 529{
531 struct in_addr host; 530 struct in_addr host;
532 int port; 531 int port;
532 int len;
533#ifdef USE_POLL 533#ifdef USE_POLL
534 struct pollfd ufds[2]; 534 struct pollfd ufds[2];
535#else 535#else
@@ -547,15 +547,11 @@ extern int telnet_main(int argc, char** argv)
547 exit(1); 547 exit(1);
548 548
549 G.termios_raw = G.termios_def; 549 G.termios_raw = G.termios_def;
550
551 cfmakeraw(&G.termios_raw); 550 cfmakeraw(&G.termios_raw);
552 551
553 if (argc < 2) show_usage(); 552 if (argc < 2) show_usage();
554 port = (argc > 2)? getport(argv[2]): 23; 553 port = (argc > 2)? getport(argv[2]): 23;
555 554
556 G.buf = xmalloc(DATABUFSIZE);
557 G.iacbuf = xmalloc(IACBUFSIZE);
558
559 host = getserver(argv[1]); 555 host = getserver(argv[1]);
560 556
561 G.netfd = remote_connect(host, port); 557 G.netfd = remote_connect(host, port);
@@ -599,14 +595,14 @@ extern int telnet_main(int argc, char** argv)
599 if (FD_ISSET(0, &rfds)) 595 if (FD_ISSET(0, &rfds))
600#endif 596#endif
601 { 597 {
602 G.len = read(0, G.buf, DATABUFSIZE); 598 len = read(0, G.buf, DATABUFSIZE);
603 599
604 if (G.len <= 0) 600 if (len <= 0)
605 doexit(0); 601 doexit(0);
606 602
607 TRACE(0, ("Read con: %d\n", G.len)); 603 TRACE(0, ("Read con: %d\n", len));
608 604
609 handlenetoutput(); 605 handlenetoutput(len);
610 } 606 }
611 607
612#ifdef USE_POLL 608#ifdef USE_POLL
@@ -615,16 +611,16 @@ extern int telnet_main(int argc, char** argv)
615 if (FD_ISSET(G.netfd, &rfds)) 611 if (FD_ISSET(G.netfd, &rfds))
616#endif 612#endif
617 { 613 {
618 G.len = read(G.netfd, G.buf, DATABUFSIZE); 614 len = read(G.netfd, G.buf, DATABUFSIZE);
619 615
620 if (G.len <= 0) 616 if (len <= 0)
621 { 617 {
622 WriteCS(1, "Connection closed by foreign host.\r\n"); 618 WriteCS(1, "Connection closed by foreign host.\r\n");
623 doexit(1); 619 doexit(1);
624 } 620 }
625 TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len)); 621 TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));
626 622
627 handlenetinput(); 623 handlenetinput(len);
628 } 624 }
629 } 625 }
630 } 626 }