|
22 | 22 | #include <netinet/in.h> |
23 | 23 | #include <arpa/inet.h> |
24 | 24 |
|
25 | | -#define ESCAPE (']'&0x1f) /* = ^] escape session, effectively terminate */ |
| 25 | +#define CTRL(c) ((c) & 0x1f) |
| 26 | +#define ESCAPE CTRL(']') /* = escape and terminate session */ |
26 | 27 | #define BUFSIZE 1500 |
27 | 28 | #define debug(...) |
28 | 29 | //#define RAWTELNET /* test mode for raw telnet without IAC */ |
@@ -100,8 +101,12 @@ read_keyboard(void) |
100 | 101 | fprintf(stderr, "\r\ntelnet: session terminated\r\n"); |
101 | 102 | finish(); |
102 | 103 | } |
103 | | - if (buffer[0] == 03) |
| 104 | + if (buffer[0] == CTRL('C')) |
104 | 105 | discard = 1; |
| 106 | + else if (buffer[0] == CTRL('O')) { |
| 107 | + discard ^= 1; |
| 108 | + return; |
| 109 | + } |
105 | 110 | count = write(tcp_fd, buffer, count); |
106 | 111 | if (count < 0) { |
107 | 112 | perror("Connection closed"); |
@@ -214,14 +219,16 @@ main(int argc, char **argv) |
214 | 219 | printf("Connected\n"); |
215 | 220 | printf("Escape character is '^%c'.\n", escape + '@'); |
216 | 221 |
|
217 | | -#ifdef RAWTELNET |
218 | 222 | struct termios termios; |
219 | 223 | tcgetattr(0, &termios); |
| 224 | +#ifdef RAWTELNET |
220 | 225 | termios.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); |
221 | 226 | termios.c_oflag &= ~(OPOST); |
222 | 227 | termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG); |
223 | | - tcsetattr(0, TCSANOW, &termios); |
| 228 | +#else |
| 229 | + termios.c_lflag &= ~ISIG; |
224 | 230 | #endif |
| 231 | + tcsetattr(0, TCSANOW, &termios); |
225 | 232 | nonblock = 1; |
226 | 233 | ioctl(0, FIONBIO, &nonblock); |
227 | 234 |
|
|
0 commit comments