-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParse.cpp
More file actions
65 lines (61 loc) · 2.31 KB
/
Parse.cpp
File metadata and controls
65 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <WiFi.h>
#define WILL 251
#define WONT 252
#define DO 253
#define DONT 254
#define IAC 255
#define ECHO 1
#define SGA 3
void Display_Char(char ch);
void ParseTelnet(WiFiClient TCPclient)
{
while (TCPclient.available())
{
int input = TCPclient.read();
int inputoption,inputverb;
switch (input)
{
case -1:
break;
case IAC:
// interpret as command
inputverb = TCPclient.read();
if (inputverb == -1) break;
switch (inputverb)
{
case IAC:
//literal IAC = 255 escaped, so append char 255 to string
break;
case DO:
case DONT:
case WILL:
case WONT:
// reply to all commands with "WONT", unless it is SGA (suppres go ahead)
inputoption = TCPclient.read();
if (inputoption == -1) break;
TCPclient.write((byte)IAC);
if (inputoption == (int)SGA || inputoption == ECHO)
TCPclient.write(inputverb == DO ? WILL : DO);
else
TCPclient.write(inputverb == DO ? WONT : DONT);
TCPclient.write(inputoption);
break;
default:
break;
}
break;
default:
Serial.print((char)input);
Display_Char((char)input);
break;
}
}
}
void RawTelnet(WiFiClient TCPclient)
{
while (TCPclient.available()) {
int input = TCPclient.read();
Serial.print((char)input);
Display_Char((char)input);
}
}