diff options
-rw-r--r-- | networking/telnet.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/networking/telnet.c b/networking/telnet.c index b700fbed9..58a691916 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
@@ -187,27 +187,34 @@ static void con_escape(void) | |||
187 | static void handle_net_output(int len) | 187 | static void handle_net_output(int len) |
188 | { | 188 | { |
189 | byte outbuf[2 * DATABUFSIZE]; | 189 | byte outbuf[2 * DATABUFSIZE]; |
190 | byte *p = (byte*)G.buf; | 190 | byte *dst = outbuf; |
191 | int j = 0; | 191 | byte *src = (byte*)G.buf; |
192 | byte *end = src + len; | ||
192 | 193 | ||
193 | for (; len > 0; len--, p++) { | 194 | while (src < end) { |
194 | byte c = *p; | 195 | byte c = *src++; |
195 | if (c == 0x1d) { | 196 | if (c == 0x1d) { |
196 | con_escape(); | 197 | con_escape(); |
197 | return; | 198 | return; |
198 | } | 199 | } |
199 | outbuf[j++] = c; | 200 | *dst = c; |
200 | if (c == IAC) | 201 | if (c == IAC) |
201 | outbuf[j++] = c; /* IAC -> IAC IAC */ | 202 | *++dst = c; /* IAC -> IAC IAC */ |
202 | else if (c == '\r') | 203 | else |
203 | /* See RFC 1123 3.3.1 Telnet End-of-Line Convention. | 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. | ||
204 | * Using CR LF instead of other allowed possibilities | 208 | * Using CR LF instead of other allowed possibilities |
205 | * like CR NUL - easier to talk to HTTP/SMTP servers. | 209 | * like CR NUL - easier to talk to HTTP/SMTP servers. |
206 | */ | 210 | */ |
207 | outbuf[j++] = '\n'; /* CR -> CR LF */ | 211 | *dst = '\r'; /* Enter -> CR LF */ |
212 | *++dst = '\n'; | ||
213 | } | ||
214 | dst++; | ||
208 | } | 215 | } |
209 | if (j > 0) | 216 | if (dst - outbuf != 0) |
210 | full_write(netfd, outbuf, j); | 217 | full_write(netfd, outbuf, dst - outbuf); |
211 | } | 218 | } |
212 | 219 | ||
213 | static void handle_net_input(int len) | 220 | static void handle_net_input(int len) |