diff --git a/src/socket.c b/src/socket.c index 16d9621..23b1249 100644 --- a/src/socket.c +++ b/src/socket.c @@ -33,6 +33,7 @@ #include "socket.h" #include "options.h" #include "print.h" +#include "tty.h" #define MAX_SOCKET_CLIENTS 16 #define SOCKET_PORT_DEFAULT 3333 @@ -340,11 +341,26 @@ bool socket_handle_input(fd_set *rdfs, char *output_char) clientfds[i] = -1; continue; } - /* match the behavior of a terminal in raw mode */ - if (*output_char == '\n') + + /* If INLCR is set, a received NL character shall be translated into a CR character */ + if (*output_char == '\n' && map_i_nl_cr) { *output_char = '\r'; } + else if (*output_char == '\r') + { + /* If IGNCR is set, a received CR character shall be ignored (not read). */ + if (map_ign_cr) + { + return false; + } + + /* If IGNCR is not set and ICRNL is set, a received CR character shall be translated into an NL character. */ + if (map_i_cr_nl) + { + *output_char = '\n'; + } + } return true; } } diff --git a/src/tty.c b/src/tty.c index 92bcb7e..54ea980 100644 --- a/src/tty.c +++ b/src/tty.c @@ -129,6 +129,9 @@ const char random_array[] = }; bool interactive_mode = true; +bool map_i_nl_cr = false; +bool map_i_cr_nl = false; +bool map_ign_cr = false; static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old; static unsigned long rx_total = 0, tx_total = 0; @@ -987,14 +990,17 @@ void tty_configure(void) if (strcmp(token,"INLCR") == 0) { tio.c_iflag |= INLCR; + map_i_nl_cr = true; } else if (strcmp(token,"IGNCR") == 0) { tio.c_iflag |= IGNCR; + map_ign_cr = true; } else if (strcmp(token,"ICRNL") == 0) { tio.c_iflag |= ICRNL; + map_i_cr_nl = true; } else if (strcmp(token,"OCRNL") == 0) { diff --git a/src/tty.h b/src/tty.h index c4b6797..add8bf1 100644 --- a/src/tty.h +++ b/src/tty.h @@ -24,6 +24,9 @@ #include extern bool interactive_mode; +extern bool map_i_nl_cr; +extern bool map_i_cr_nl; +extern bool map_ign_cr; void stdout_configure(void); void stdin_configure(void);