From 29a19692fec2787cc8e7fb0002ab93f6dd2149c3 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Mon, 12 Oct 2020 17:10:28 +1000 Subject: [PATCH] Handle IAC (well ignore it) --- MD_Getc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MD_Getc.c b/MD_Getc.c index 01a9834..03ecbb8 100644 --- a/MD_Getc.c +++ b/MD_Getc.c @@ -10,12 +10,17 @@ #include #include "MagiDoor.h" +#define IAC 255 + extern time_t mdtimeout; extern time_t mdtimeremaining; char md_getc() { char c; ssize_t ret; + + int stage = 0; + while (1) { if (mdcontrol.socket == -1) { ret = read(STDIN_FILENO, &c, 1); @@ -41,6 +46,35 @@ char md_getc() { usleep(100); continue; } + + if (mdcontrol.socket != -1) { + if ((unsigned char)c == IAC && stage == 0) { + stage = 1; + continue; + } + if (stage == 1) { + if ((unsigned char)c == IAC) { + stage = 0; + } else if ((unsigned char)c == 250) { + stage = 3; + continue; + } else { + stage = 2; + continue; + } + } + if (stage == 2) { + stage = 0; + continue; + } + if (stage == 3) { + if ((unsigned char)c == 240) { + stage = 0; + } + continue; + } + } + mdtimeout = time(NULL) + 900; return c; }