Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Feb 96 22:09 WET
From:      uhclem@nemesis.lonestar.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/1037: 2.x telnetd handles CTRL-M differently than other ttys		FDIV044
Message-ID:  <m0tojOB-000CiCC@nemesis.lonestar.org>
Resent-Message-ID: <199602200420.UAA18436@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         1037
>Category:       bin
>Synopsis:       2.x telnetd handles CTRL-M differently than other ttys		FDIV044
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 19 20:20:01 PST 1996
>Last-Modified:
>Originator:     Frank Durda IV
>Organization:
That's extra
>Release:        FreeBSD 2.1-STABLE i386
>Environment:

FreeBSD 2.1.0 stock system, using various applications that place
tty in character-at-a-time modes.

>Description:

Some applications that ran correctly under BSD43 on vaxen, and later on
SYSIII, SYS5 and 1.1.5.1 PC systems break when used via telnet in 2.0.5
or 2.1.0.  

When these programs are running, they interactively parse each character
received, including [ENTER], which is received as 0x0a when the program
is run from the console (syscons), from a terminal attached to a sio port,
or when connected using via telnet using telnetd from 1.1.5.1.

When the telnetd from 2.0.5 or 2.1.0 is used, instead of a 0x0a,
the program receives a 0x0d character, which it does not expect (never
sees anywhere else) and treats as an not-valid-here character.

>How-To-Repeat:

The attached code fragment can be compiled to demonstrate the problem.
Simply run it from terminals, the console, and from telnet sessions to
see the difference in performance.  (I have stripped out the SYS3-specific
code, but can provide it if needed.)  Follow the instructions in the
program source.

-----enterbug.c-----
/*	This program is peeled out of a much larger program called
	xmail.  When run in 2.1.0 over telnet, pressing ENTER
	is no longer detected by the program as receiving a 0x0a
	as it did in 1.1.5.1 telnet sessions, or from ttys, or
	from the console, or on other platforms (BSD43, SYS3, SYSV) 
	that this program has been used on.

	Start the program, and press at least the following keys:
	[ENTER] [CTRL][J] [CTRL][M]  Press Capital Q to exit.

	Here is what I see here:	(This is a 2.1.0 system)

			System	sio 	telnetd	telnetd
			console	tty	2.1.0	1.1.5.1*
	[ENTER]		0a	0a    **0d**	0a
	[CTRL][J]	0a	0a	0a	0a
	[CTRL][M]	0a	0a    **0d**	0a

	* By replacing the 2.1.0 telnetd with the telnetd from 1.1.5.1
	(but still running on a 2.1.0 system), the correct character
	(0x0a) is returned when ENTER is presed.

	Run this program from the console, from terminals, and then
	via telnet to see the difference in behavior.
*/

#include	<stdio.h>
#include	<sgtty.h>
#include	<sys/stat.h>
#include	<sys/file.h>
#define TRUE 1
#define FALSE 0
#define	EOT	'\004'

static  struct sgttyb	old, new;
static struct  stat	ttystatus;
static int	eof=EOT,  killc=CTRL('U'),  erase=CTRL('H'),  werase=CTRL('W');
char	*ttynam_stdout;
int	stdin_isatty, stdout_isatty;

main()
{	
	char c;

	save_tty();
	set_tty();

	clearerr(stdin);
	do {
		c = getchar();
		printf("%02x ",c);
	} while (c != 'Q');
	
	restore_tty();
	exit(0);
}


save_tty()
{
	struct tchars	tc;

	fstat(fileno(stdout), &ttystatus);
	ttynam_stdout = (char*) ttyname(fileno(stdout));
	stdout_isatty = (ioctl(fileno(stdout), TIOCGETP, &old) >= 0);
	stdin_isatty = (ioctl(fileno(stdin), TIOCGETP, &old) >= 0);

	printf("stdin is%s a tty\n",stdin_isatty?"":" not");
	printf("stdout is%s a tty\n",stdout_isatty?"":" not");

	killc = (int)old.sg_kill;
	erase = (int)old.sg_erase;
	if (ioctl(fileno(stdin), TIOCGETC, &tc) == 0)
		eof = (int)tc.t_eofc;

	new = old;
	new.sg_flags |= CBREAK;
	new.sg_flags &= ~ECHO;
}

set_tty()
{
	ioctl(fileno(stdin), TIOCSETN, &new);
}

restore_tty()
{
	if (stdout_isatty)
		chmod(ttynam_stdout, (int)ttystatus.st_mode&0777);
	if (stdin_isatty)
		ioctl(fileno(stdin), TIOCSETP, &old);
}
-----end of enterbug.c-----


>Fix:
	
The workaround is to replace the telnetd in 2.1.0 or 2.0.5
with the telnetd from 1.1.5.1.  This solves this problem and allows
these legacy applications to be used on FreeBSD 2.x.

*END*

>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m0tojOB-000CiCC>