summaryrefslogtreecommitdiff
path: root/networking/telnet.c
diff options
context:
space:
mode:
authorDenys Vlasenko2012-09-17 11:54:35 +0200
committerDenys Vlasenko2012-09-17 11:54:35 +0200
commit0ffd63ca9a46d1e9112e12702e4337195eade25d (patch)
tree30730bb09bcedf3fe869b2620a480bc7f3740af8 /networking/telnet.c
parent57f07bfcb276777f9ea85df7d09ae005a0231464 (diff)
downloadbusybox-0ffd63ca9a46d1e9112e12702e4337195eade25d.zip
busybox-0ffd63ca9a46d1e9112e12702e4337195eade25d.tar.gz
telnet: convert Enter -> CR LF in line mode too
function old new delta handle_net_output 87 98 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/telnet.c')
-rw-r--r--networking/telnet.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/networking/telnet.c b/networking/telnet.c
index b700fbe..58a6919 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -187,27 +187,34 @@ static void con_escape(void)
static void handle_net_output(int len)
{
byte outbuf[2 * DATABUFSIZE];
- byte *p = (byte*)G.buf;
- int j = 0;
+ byte *dst = outbuf;
+ byte *src = (byte*)G.buf;
+ byte *end = src + len;
- for (; len > 0; len--, p++) {
- byte c = *p;
+ while (src < end) {
+ byte c = *src++;
if (c == 0x1d) {
con_escape();
return;
}
- outbuf[j++] = c;
+ *dst = c;
if (c == IAC)
- outbuf[j++] = c; /* IAC -> IAC IAC */
- else if (c == '\r')
- /* See RFC 1123 3.3.1 Telnet End-of-Line Convention.
+ *++dst = c; /* IAC -> IAC IAC */
+ else
+ if (c == '\r' || c == '\n') {
+ /* Enter key sends '\r' in raw mode and '\n' in cooked one.
+ *
+ * See RFC 1123 3.3.1 Telnet End-of-Line Convention.
* Using CR LF instead of other allowed possibilities
* like CR NUL - easier to talk to HTTP/SMTP servers.
*/
- outbuf[j++] = '\n'; /* CR -> CR LF */
+ *dst = '\r'; /* Enter -> CR LF */
+ *++dst = '\n';
+ }
+ dst++;
}
- if (j > 0)
- full_write(netfd, outbuf, j);
+ if (dst - outbuf != 0)
+ full_write(netfd, outbuf, dst - outbuf);
}
static void handle_net_input(int len)