Skip to content

Commit 36c6d4f

Browse files
committed
[net] Add ^O to toggle discarding telnet output
1 parent 982123d commit 36c6d4f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

elkscmd/inet/telnet.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <netinet/in.h>
2323
#include <arpa/inet.h>
2424

25-
#define ESCAPE (']'&0x1f) /* = ^] escape session, effectively terminate */
25+
#define CTRL(c) ((c) & 0x1f)
26+
#define ESCAPE CTRL(']') /* = escape and terminate session */
2627
#define BUFSIZE 1500
2728
#define debug(...)
2829
//#define RAWTELNET /* test mode for raw telnet without IAC */
@@ -100,8 +101,12 @@ read_keyboard(void)
100101
fprintf(stderr, "\r\ntelnet: session terminated\r\n");
101102
finish();
102103
}
103-
if (buffer[0] == 03)
104+
if (buffer[0] == CTRL('C'))
104105
discard = 1;
106+
else if (buffer[0] == CTRL('O')) {
107+
discard ^= 1;
108+
return;
109+
}
105110
count = write(tcp_fd, buffer, count);
106111
if (count < 0) {
107112
perror("Connection closed");
@@ -214,14 +219,16 @@ main(int argc, char **argv)
214219
printf("Connected\n");
215220
printf("Escape character is '^%c'.\n", escape + '@');
216221

217-
#ifdef RAWTELNET
218222
struct termios termios;
219223
tcgetattr(0, &termios);
224+
#ifdef RAWTELNET
220225
termios.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF);
221226
termios.c_oflag &= ~(OPOST);
222227
termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG);
223-
tcsetattr(0, TCSANOW, &termios);
228+
#else
229+
termios.c_lflag &= ~ISIG;
224230
#endif
231+
tcsetattr(0, TCSANOW, &termios);
225232
nonblock = 1;
226233
ioctl(0, FIONBIO, &nonblock);
227234

0 commit comments

Comments
 (0)