X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Ftelnet.c;h=e65b6918d8d9f8eb9df0a2b2142050d8f2a43bf7;hb=52933d47bd86d6d992f7290fad93d63b53f7a15f;hp=05c7786ab335e4485cdf3c05f32d874a430e623f;hpb=0cb6f35c33a2a3fd390aaa36da72e0600f205918;p=oweals%2Fbusybox.git diff --git a/networking/telnet.c b/networking/telnet.c index 05c7786ab..e65b6918d 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -34,10 +34,6 @@ #include #include "busybox.h" -#if 0 -static const int DOTRACE = 1; -#endif - #ifdef DOTRACE #include /* for inet_ntoa()... */ #define TRACE(x, y) do { if (x) printf y; } while (0) @@ -45,24 +41,17 @@ static const int DOTRACE = 1; #define TRACE(x, y) #endif -#if 0 -#define USE_POLL -#include -#else -#include -#endif - #define DATABUFSIZE 128 #define IACBUFSIZE 128 -static const int CHM_TRY = 0; -static const int CHM_ON = 1; -static const int CHM_OFF = 2; +enum { + CHM_TRY = 0, + CHM_ON = 1, + CHM_OFF = 2, -static const int UF_ECHO = 0x01; -static const int UF_SGA = 0x02; + UF_ECHO = 0x01, + UF_SGA = 0x02, -enum { TS_0 = 1, TS_IAC = 2, TS_OPT = 3, @@ -99,7 +88,7 @@ struct Globalvars * Gptr; #define G (*Gptr) #endif -static inline void iacflush(void) +static void iacflush(void) { write(G.netfd, G.iacbuf, G.iaclen); G.iaclen = 0; @@ -114,7 +103,7 @@ static void telopt(byte c); static int subneg(byte c); /* Some globals */ -static int one = 1; +static const int one = 1; #ifdef CONFIG_FEATURE_TELNET_TTYPE static char *ttype; @@ -196,9 +185,9 @@ static void handlenetoutput(int len) * I don't agree. * first - I cannot use programs like sz/rz * second - the 0x0D is sent as one character and if the next - * char is 0x0A then it's eaten by a server side. + * char is 0x0A then it's eaten by a server side. * third - whay doy you have to make 'many write()s'? - * I don't understand. + * I don't understand. * So I implemented it. It's realy useful for me. I hope that * others people will find it interesting to. */ @@ -216,12 +205,12 @@ static void handlenetoutput(int len) } outbuf[j++] = *p; if (*p == 0xff) - outbuf[j++] = 0xff; + outbuf[j++] = 0xff; else if (*p == 0x0d) - outbuf[j++] = 0x00; + outbuf[j++] = 0x00; } if (j > 0 ) - write(G.netfd, outbuf, j); + write(G.netfd, outbuf, j); } @@ -302,7 +291,7 @@ static void handlenetinput(int len) /* ******************************* */ -static inline void putiac(int c) +static void putiac(int c) { G.iacbuf[G.iaclen++] = c; } @@ -318,17 +307,6 @@ static void putiac2(byte wwdd, byte c) putiac(c); } -#if 0 -static void putiac1(byte c) -{ - if (G.iaclen + 2 > IACBUFSIZE) - iacflush(); - - putiac(IAC); - putiac(c); -} -#endif - #ifdef CONFIG_FEATURE_TELNET_TTYPE static void putiac_subopt(byte c, char *str) { @@ -342,7 +320,7 @@ static void putiac_subopt(byte c, char *str) putiac(c); putiac(0); - while(*str) + while (*str) putiac(*str++); putiac(IAC); @@ -365,12 +343,12 @@ static void putiac_subopt_autologin(void) putiac(TELQUAL_IS); putiac(NEW_ENV_VAR); - while(*user) + while (*user) putiac(*user++); putiac(NEW_ENV_VALUE); - while(*autologin) + while (*autologin) putiac(*autologin++); putiac(IAC); @@ -450,13 +428,13 @@ static void do_linemode(void) /* ******************************* */ -static inline void to_notsup(char c) +static void to_notsup(char c) { if (G.telwish == WILL) putiac2(DONT, c); else if (G.telwish == DO) putiac2(WONT, c); } -static inline void to_echo(void) +static void to_echo(void) { /* if server requests ECHO, don't agree */ if (G.telwish == DO) { putiac2(WONT, TELOPT_ECHO); return; } @@ -483,7 +461,7 @@ static inline void to_echo(void) WriteCS(1, "\r\n"); /* sudden modec */ } -static inline void to_sga(void) +static void to_sga(void) { /* daemon always sends will/wont, client do/dont */ @@ -505,7 +483,7 @@ static inline void to_sga(void) } #ifdef CONFIG_FEATURE_TELNET_TTYPE -static inline void to_ttype(void) +static void to_ttype(void) { /* Tell server we will (or won't) do TTYPE */ @@ -519,7 +497,7 @@ static inline void to_ttype(void) #endif #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN -static inline void to_new_environ(void) +static void to_new_environ(void) { /* Tell server we will (or will not) do AUTOLOGIN */ @@ -533,7 +511,7 @@ static inline void to_new_environ(void) #endif #ifdef CONFIG_FEATURE_AUTOWIDTH -static inline void to_naws(void) +static void to_naws(void) { /* Tell server we will do NAWS */ putiac2(WILL, TELOPT_NAWS); @@ -613,7 +591,7 @@ static void cookmode(void) if (G.do_termios) tcsetattr(0, TCSADRAIN, &G.termios_def); } -extern int telnet_main(int argc, char** argv) +int telnet_main(int argc, char** argv) { int len; struct sockaddr_in s_in; @@ -629,7 +607,7 @@ extern int telnet_main(int argc, char** argv) #endif #ifdef CONFIG_FEATURE_TELNET_TTYPE - ttype = getenv("TERM"); + ttype = getenv("TERM"); #endif memset(&G, 0, sizeof G); @@ -645,7 +623,7 @@ extern int telnet_main(int argc, char** argv) bb_show_usage(); #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN - if (1 & bb_getopt_ulflags(argc, argv, "al:", &autologin)) + if (1 & getopt32(argc, argv, "al:", &autologin)) autologin = getenv("USER"); if (optind < argc) { @@ -661,7 +639,7 @@ extern int telnet_main(int argc, char** argv) s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23); #endif - G.netfd = xconnect(&s_in); + G.netfd = xconnect_tcp_v4(&s_in); setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); @@ -734,11 +712,3 @@ extern int telnet_main(int argc, char** argv) } } } - -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/