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>
This commit is contained in:
Denys Vlasenko 2012-09-17 11:54:35 +02:00
parent 57f07bfcb2
commit 0ffd63ca9a

View File

@ -187,27 +187,34 @@ static void con_escape(void)
static void handle_net_output(int len) static void handle_net_output(int len)
{ {
byte outbuf[2 * DATABUFSIZE]; byte outbuf[2 * DATABUFSIZE];
byte *p = (byte*)G.buf; byte *dst = outbuf;
int j = 0; byte *src = (byte*)G.buf;
byte *end = src + len;
for (; len > 0; len--, p++) { while (src < end) {
byte c = *p; byte c = *src++;
if (c == 0x1d) { if (c == 0x1d) {
con_escape(); con_escape();
return; return;
} }
outbuf[j++] = c; *dst = c;
if (c == IAC) if (c == IAC)
outbuf[j++] = c; /* IAC -> IAC IAC */ *++dst = c; /* IAC -> IAC IAC */
else if (c == '\r') else
/* See RFC 1123 3.3.1 Telnet End-of-Line Convention. 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 * Using CR LF instead of other allowed possibilities
* like CR NUL - easier to talk to HTTP/SMTP servers. * like CR NUL - easier to talk to HTTP/SMTP servers.
*/ */
outbuf[j++] = '\n'; /* CR -> CR LF */ *dst = '\r'; /* Enter -> CR LF */
*++dst = '\n';
} }
if (j > 0) dst++;
full_write(netfd, outbuf, j); }
if (dst - outbuf != 0)
full_write(netfd, outbuf, dst - outbuf);
} }
static void handle_net_input(int len) static void handle_net_input(int len)