Handle IAC (well ignore it)
This commit is contained in:
parent
318b385ce4
commit
29a19692fe
34
MD_Getc.c
34
MD_Getc.c
@ -10,12 +10,17 @@
|
||||
#include <string.h>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user