On Mon, 19 Jan 2015, Stanislav Brabec wrote:
...
> Technical details:
>
> Current implementation uses following set of flags:
> onlcr -icrnl echo
>
> In CRLF mode it first correctly sets
> onlcr icrnl echo
> but later in the code it changes flags to
> onlcr -icrnl echo
>
> The -icrnl causes echoing of control characters as "^{letter}",
> including LF displayed as "^M".
>
> According to Werner Fink <[email protected]>, this is a correct
> behavior of terminal, just the combination of flags used is
> incorrect.
>
> However the problem was discovered on the Linux system, I
> believe, that the problem is system independent, and affects all
> systems. Attached patch seems to fix this issue without breaking
> any other telnet modes.
...
> Proposed fix:
>
> --- src/usr.bin/telnet/sys_bsd.c 2012-01-09 17:08:55.000000000 +0100
> +++ src/usr.bin/telnet/sys_bsd.c 2014-11-14 21:24:49.540247131 +0100
> @@ -355,7 +355,6 @@
> tmp_tc.c_lflag |= ICANON;
> } else {
> tmp_tc.c_lflag &= ~ICANON;
> - tmp_tc.c_iflag &= ~ICRNL;
> tmp_tc.c_cc[VMIN] = 1;
> tmp_tc.c_cc[VTIME] = 0;
> }
Hmm, with that deleted, telnet will set but never clear ICRNL. For
consistency of state/operation, I suspect it would be better to move that
line up above the other block, so that it'll set ICRNL when echo&&crlf,
but clear it otherwise:
Index: sys_bsd.c
===================================================================
RCS file: /cvs/src/usr.bin/telnet/sys_bsd.c,v
retrieving revision 1.28
diff -u -p -r1.28 sys_bsd.c
--- sys_bsd.c 9 Sep 2014 03:41:08 -0000 1.28
+++ sys_bsd.c 21 Jan 2015 03:36:50 -0000
@@ -275,6 +275,7 @@ TerminalNewMode(int f)
prevmode = f&~MODE_FORCE;
tmp_tc = new_tc;
+ tmp_tc.c_iflag &= ~ICRNL;
if (f&MODE_ECHO) {
tmp_tc.c_lflag |= ECHO;
tmp_tc.c_oflag |= ONLCR;
@@ -310,7 +311,6 @@ TerminalNewMode(int f)
tmp_tc.c_lflag |= ICANON;
} else {
tmp_tc.c_lflag &= ~ICANON;
- tmp_tc.c_iflag &= ~ICRNL;
tmp_tc.c_cc[VMIN] = 1;
tmp_tc.c_cc[VTIME] = 0;
}
Does that pass your tests, both with local echo and without?
Philip Guenther