Skip to content

Commit d1b3e49

Browse files
author
Uwe Kleine-König
committed
Only handle IAC for telnet connections
This is a bit ugly because the muxer should not be aware of telnet protocol specifics but it is aware already anyhow, so we can just as well expand it a bit. Fixes: #4 Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
1 parent d82825c commit d1b3e49

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

microcom.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <fcntl.h>
2727
#include <stdio.h>
2828
#include <stdlib.h>
29+
#include <stdbool.h>
2930
#include <signal.h>
3031
#include <string.h>
3132
#include <termios.h>
@@ -48,6 +49,7 @@ struct ios_ops {
4849
int (*set_handshake_line)(struct ios_ops *, int pin, int enable);
4950
int (*send_break)(struct ios_ops *);
5051
void (*exit)(struct ios_ops *);
52+
bool istelnet;
5153
int fd;
5254
};
5355

mux.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,6 @@ static int handle_receive_buf(struct ios_ops *ios, unsigned char *buf, int len)
308308

309309
while (len) {
310310
switch (*buf) {
311-
case IAC:
312-
/* BUG: this is telnet specific */
313-
write_receive_buf(sendbuf, buf - sendbuf);
314-
i = handle_command(ios, buf, len);
315-
if (i < 0)
316-
return i;
317-
318-
buf += i;
319-
len -= i;
320-
sendbuf = buf;
321-
break;
322311
case 5:
323312
write_receive_buf(sendbuf, buf - sendbuf);
324313
if (answerback)
@@ -330,6 +319,19 @@ static int handle_receive_buf(struct ios_ops *ios, unsigned char *buf, int len)
330319
len -= 1;
331320
sendbuf = buf;
332321
break;
322+
case IAC:
323+
if (ios->istelnet) {
324+
write_receive_buf(sendbuf, buf - sendbuf);
325+
i = handle_command(ios, buf, len);
326+
if (i < 0)
327+
return i;
328+
329+
buf += i;
330+
len -= i;
331+
sendbuf = buf;
332+
break;
333+
}
334+
/* fall through */
333335
default:
334336
buf += 1;
335337
len -= 1;

telnet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct ios_ops *telnet_init(char *hostport)
9595
ios->set_speed = telnet_set_speed;
9696
ios->set_flow = telnet_set_flow;
9797
ios->send_break = telnet_send_break;
98+
ios->istelnet = true;
9899
ios->exit = telnet_exit;
99100

100101
memset(&hints, '\0', sizeof(hints));

0 commit comments

Comments
 (0)