[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] telnet: added support for special telnet characters
From:       Martin Lewis <martin.lewis.x84 () gmail ! com>
Date:       2019-07-07 14:38:01
Message-ID: 1562510281-18376-1-git-send-email-martin.lewis.x84 () gmail ! com
[Download RAW message or body]

Closes https://bugs.busybox.net/show_bug.cgi?id=11976

Adds a new flag in telnet client's command line, which
forces telnet to send IAC's instead of the
traditional special characters (backspace, newline etc..).

This code is similar to putty's code, and is added
for compatibility with older telnet servers.

Currently only backspace is supported,
I will add support for other characters soon.

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
---
 networking/telnet.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/networking/telnet.c b/networking/telnet.c
index fa16287..b6bebdc 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -120,6 +120,7 @@ struct globals {
 	byte    charmode;
 	byte    telflags;
 	byte	do_termios;
+	byte	keyboard_special_cmds;
 #if ENABLE_FEATURE_TELNET_TTYPE
 	char	*ttype;
 #endif
@@ -175,6 +176,7 @@ static void con_escape(void)
 	full_write1_str("\r\nConsole escape. Commands are:\r\n\n"
 			" l	go to line mode\r\n"
 			" c	go to character mode\r\n"
+			" k	toggle keyboard sends telnet special commands\r\n"
 			" z	suspend telnet\r\n"
 			" e	exit telnet\r\n");
 
@@ -194,6 +196,9 @@ static void con_escape(void)
 			goto ret;
 		}
 		break;
+	case 'k':
+		G.keyboard_special_cmds = !G.keyboard_special_cmds;
+		break;
 	case 'z':
 		cookmode();
 		kill(0, SIGTSTP);
@@ -220,15 +225,16 @@ static void handle_net_output(int len)
 
 	while (src < end) {
 		byte c = *src++;
-		if (c == 0x1d) {
+		switch (c) {
+		case 0x1d:
 			con_escape();
 			return;
-		}
-		*dst = c;
-		if (c == IAC)
+		case IAC:
+			*dst = c;
 			*++dst = c; /* IAC -> IAC IAC */
-		else
-		if (c == '\r' || c == '\n') {
+			break;
+		case '\r':
+		case '\n':
 			/* Enter key sends '\r' in raw mode and '\n' in cooked one.
 			 *
 			 * See RFC 1123 3.3.1 Telnet End-of-Line Convention.
@@ -237,6 +243,28 @@ static void handle_net_output(int len)
 			 */
 			*dst = '\r'; /* Enter -> CR LF */
 			*++dst = '\n';
+			break;
+
+		case 0x08: /* ctrl+h */
+		case 0x7f: /* backspace */
+			if (G.keyboard_special_cmds) {
+				*dst = IAC;
+				*++dst = EC;
+				break;
+			}
+			/* fall through */
+
+		case 0x03: /* ctrl+c */
+			if (G.keyboard_special_cmds) {
+				*dst = IAC;
+				*++dst = IP;
+				break;
+			}
+			/* fall through */
+
+		default:
+			*dst = c;
+			break;
 		}
 		dst++;
 	}
-- 
1.9.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic