Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/telnet.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/telnet.c
r2725 r3232 22 22 */ 23 23 24 //usage:#if ENABLE_FEATURE_TELNET_AUTOLOGIN 25 //usage:#define telnet_trivial_usage 26 //usage: "[-a] [-l USER] HOST [PORT]" 27 //usage:#define telnet_full_usage "\n\n" 28 //usage: "Connect to telnet server\n" 29 //usage: "\n -a Automatic login with $USER variable" 30 //usage: "\n -l USER Automatic login as USER" 31 //usage: 32 //usage:#else 33 //usage:#define telnet_trivial_usage 34 //usage: "HOST [PORT]" 35 //usage:#define telnet_full_usage "\n\n" 36 //usage: "Connect to telnet server" 37 //usage:#endif 38 24 39 #include <arpa/telnet.h> 25 40 #include <netinet/in.h> 26 41 #include "libbb.h" 27 42 43 #ifdef __BIONIC__ 44 /* should be in arpa/telnet.h */ 45 # define IAC 255 /* interpret as command: */ 46 # define DONT 254 /* you are not to use option */ 47 # define DO 253 /* please, you use option */ 48 # define WONT 252 /* I won't use option */ 49 # define WILL 251 /* I will use option */ 50 # define SB 250 /* interpret as subnegotiation */ 51 # define SE 240 /* end sub negotiation */ 52 # define TELOPT_ECHO 1 /* echo */ 53 # define TELOPT_SGA 3 /* suppress go ahead */ 54 # define TELOPT_TTYPE 24 /* terminal type */ 55 # define TELOPT_NAWS 31 /* window size */ 56 #endif 57 28 58 #ifdef DOTRACE 29 # define TRACE(x, y) do { if (x) printf y; } while (0)59 # define TRACE(x, y) do { if (x) printf y; } while (0) 30 60 #else 31 # define TRACE(x, y)61 # define TRACE(x, y) 32 62 #endif 33 63 … … 157 187 static void handle_net_output(int len) 158 188 { 159 /* here we could do smart tricks how to handle 0xFF:s in output160 * stream like writing twice every sequence of FF:s (thus doing161 * many write()s. But I think interactive telnet application does162 * not need to be 100% 8-bit clean, so changing every 0xff:s to163 * 0x7f:s164 *165 * 2002-mar-21, Przemyslaw Czerpak (druzus@polbox.com)166 * I don't agree.167 * first - I cannot use programs like sz/rz168 * second - the 0x0D is sent as one character and if the next169 * char is 0x0A then it's eaten by a server side.170 * third - why do you have to make 'many write()s'?171 * I don't understand.172 * So I implemented it. It's really useful for me. I hope that173 * other people will find it interesting too.174 */175 189 byte outbuf[2 * DATABUFSIZE]; 176 byte *p = (byte*)G.buf; 177 int j = 0; 178 179 for (; len > 0; len--, p++) { 180 byte c = *p; 190 byte *dst = outbuf; 191 byte *src = (byte*)G.buf; 192 byte *end = src + len; 193 194 while (src < end) { 195 byte c = *src++; 181 196 if (c == 0x1d) { 182 197 con_escape(); 183 198 return; 184 199 } 185 outbuf[j++]= c;200 *dst = c; 186 201 if (c == IAC) 187 outbuf[j++] = c; /* IAC -> IAC IAC */ 188 else if (c == '\r') 189 outbuf[j++] = '\0'; /* CR -> CR NUL */ 190 } 191 if (j > 0) 192 full_write(netfd, outbuf, j); 202 *++dst = c; /* IAC -> IAC IAC */ 203 else 204 if (c == '\r' || c == '\n') { 205 /* Enter key sends '\r' in raw mode and '\n' in cooked one. 206 * 207 * See RFC 1123 3.3.1 Telnet End-of-Line Convention. 208 * Using CR LF instead of other allowed possibilities 209 * like CR NUL - easier to talk to HTTP/SMTP servers. 210 */ 211 *dst = '\r'; /* Enter -> CR LF */ 212 *++dst = '\n'; 213 } 214 dst++; 215 } 216 if (dst - outbuf != 0) 217 full_write(netfd, outbuf, dst - outbuf); 193 218 } 194 219 … … 369 394 #endif 370 395 371 static char const escapecharis[] ALIGN1 = "\r\nEscape character is ";372 373 396 static void setConMode(void) 374 397 { … … 376 399 if (G.charmode == CHM_TRY) { 377 400 G.charmode = CHM_ON; 378 printf("\r\nEntering character mode%s'^]'.\r\n", escapecharis); 401 printf("\r\nEntering %s mode" 402 "\r\nEscape character is '^%c'.\r\n", "character", ']'); 379 403 rawmode(); 380 404 } … … 382 406 if (G.charmode != CHM_OFF) { 383 407 G.charmode = CHM_OFF; 384 printf("\r\nEntering line mode%s'^C'.\r\n", escapecharis); 408 printf("\r\nEntering %s mode" 409 "\r\nEscape character is '^%c'.\r\n", "line", 'C'); 385 410 cookmode(); 386 411 }
Note:
See TracChangeset
for help on using the changeset viewer.