From 7e1273edf7a75f2797ea5c0d95d33ff1056f21d8 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 7 May 2001 17:57:45 +0000 Subject: Patch from Jim McQuillan to pass the terminal type to the remote host. --- Config.h | 3 +++ networking/telnet.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++- telnet.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/Config.h b/Config.h index 57760bec6..7438e2c81 100644 --- a/Config.h +++ b/Config.h @@ -362,6 +362,9 @@ // Enable a if you system have setuped locale //#define BB_LOCALE_SUPPORT // +// Support for TELNET to pass TERM type to remote host. Adds 384 bytes. +#define BB_FEATURE_TELNET_TTYPE +// // End of Features List // // diff --git a/networking/telnet.c b/networking/telnet.c index edcc5081f..207732b72 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -27,6 +27,8 @@ * initial revision * Modified 2000/06/13 for inclusion into BusyBox by Erik Andersen * + * Modified 2001/05/07 to add ability to pass TTYPE to remote host by Jim McQuillan + * * */ @@ -136,6 +138,10 @@ static int local_bind(int port); /* Some globals */ static int one = 1; +#ifdef BB_FEATURE_TELNET_TTYPE +static char *ttype; +#endif + static void doexit(int ev) { cookmode(); @@ -321,6 +327,27 @@ static void putiac1(byte c) } #endif +#ifdef BB_FEATURE_TELNET_TTYPE +static void putiac_subopt(byte c, char *str) +{ + int len = strlen(str) + 6; // ( 2 + 1 + 1 + strlen + 2 ) + + if (G.iaclen + len > IACBUFSIZE) + iacflush(); + + putiac(IAC); + putiac(SB); + putiac(c); + putiac(0); + + while(*str) + putiac(*str++); + + putiac(IAC); + putiac(SE); +} +#endif + /* void putiacstring (subneg strings) */ /* ******************************* */ @@ -427,12 +454,29 @@ static inline void to_sga() return; } +#ifdef BB_FEATURE_TELNET_TTYPE +static inline void to_ttype() +{ + /* Tell server we will (or won't) do TTYPE */ + + if(ttype) + putiac2(WILL, TELOPT_TTYPE); + else + putiac2(WONT, TELOPT_TTYPE); + + return; +} +#endif + static void telopt(byte c) { switch (c) { case TELOPT_ECHO: to_echo(c); break; case TELOPT_SGA: to_sga(c); break; +#ifdef BB_FEATURE_TELNET_TTYPE + case TELOPT_TTYPE: to_ttype(c); break; +#endif default: to_notsup(c); break; } } @@ -440,7 +484,7 @@ static void telopt(byte c) /* ******************************* */ -/* subnegotiation -- ignore all */ +/* subnegotiation -- ignore all (except TTYPE) */ static int subneg(byte c) { @@ -449,6 +493,11 @@ static int subneg(byte c) case TS_SUB1: if (c == IAC) G.telstate = TS_SUB2; +#ifdef BB_FEATURE_TELNET_TTYPE + else + if (c == TELOPT_TTYPE) + putiac_subopt(TELOPT_TTYPE,ttype); +#endif break; case TS_SUB2: if (c == SE) @@ -488,6 +537,9 @@ extern int telnet_main(int argc, char** argv) int maxfd; #endif +#ifdef BB_FEATURE_TELNET_TTYPE + ttype = getenv("TERM"); +#endif memset(&G, 0, sizeof G); diff --git a/telnet.c b/telnet.c index edcc5081f..207732b72 100644 --- a/telnet.c +++ b/telnet.c @@ -27,6 +27,8 @@ * initial revision * Modified 2000/06/13 for inclusion into BusyBox by Erik Andersen * + * Modified 2001/05/07 to add ability to pass TTYPE to remote host by Jim McQuillan + * * */ @@ -136,6 +138,10 @@ static int local_bind(int port); /* Some globals */ static int one = 1; +#ifdef BB_FEATURE_TELNET_TTYPE +static char *ttype; +#endif + static void doexit(int ev) { cookmode(); @@ -321,6 +327,27 @@ static void putiac1(byte c) } #endif +#ifdef BB_FEATURE_TELNET_TTYPE +static void putiac_subopt(byte c, char *str) +{ + int len = strlen(str) + 6; // ( 2 + 1 + 1 + strlen + 2 ) + + if (G.iaclen + len > IACBUFSIZE) + iacflush(); + + putiac(IAC); + putiac(SB); + putiac(c); + putiac(0); + + while(*str) + putiac(*str++); + + putiac(IAC); + putiac(SE); +} +#endif + /* void putiacstring (subneg strings) */ /* ******************************* */ @@ -427,12 +454,29 @@ static inline void to_sga() return; } +#ifdef BB_FEATURE_TELNET_TTYPE +static inline void to_ttype() +{ + /* Tell server we will (or won't) do TTYPE */ + + if(ttype) + putiac2(WILL, TELOPT_TTYPE); + else + putiac2(WONT, TELOPT_TTYPE); + + return; +} +#endif + static void telopt(byte c) { switch (c) { case TELOPT_ECHO: to_echo(c); break; case TELOPT_SGA: to_sga(c); break; +#ifdef BB_FEATURE_TELNET_TTYPE + case TELOPT_TTYPE: to_ttype(c); break; +#endif default: to_notsup(c); break; } } @@ -440,7 +484,7 @@ static void telopt(byte c) /* ******************************* */ -/* subnegotiation -- ignore all */ +/* subnegotiation -- ignore all (except TTYPE) */ static int subneg(byte c) { @@ -449,6 +493,11 @@ static int subneg(byte c) case TS_SUB1: if (c == IAC) G.telstate = TS_SUB2; +#ifdef BB_FEATURE_TELNET_TTYPE + else + if (c == TELOPT_TTYPE) + putiac_subopt(TELOPT_TTYPE,ttype); +#endif break; case TS_SUB2: if (c == SE) @@ -488,6 +537,9 @@ extern int telnet_main(int argc, char** argv) int maxfd; #endif +#ifdef BB_FEATURE_TELNET_TTYPE + ttype = getenv("TERM"); +#endif memset(&G, 0, sizeof G); -- cgit v1.2.3