055396
diff -uNr telnet/Makefile telnet.obsd-cvs/Makefile
055396
--- telnet/Makefile	Mon Jul 27 18:25:13 1998
055396
+++ telnet.obsd-cvs/Makefile	Sat Mar 10 10:54:26 2001
055396
@@ -36,22 +36,20 @@
055396
 
055396
 PROG=	telnet
055396
 
055396
-CFLAGS+=-DTERMCAP -DKLUDGELINEMODE -DUSE_TERMIO -DSKEY -Dunix
055396
-CFLAGS+=-DENV_HACK -D_USE_OLD_CURSES_
055396
+CFLAGS+=-DKLUDGELINEMODE -DUSE_TERMIO -DENV_HACK -DSKEY -Dunix
055396
 CFLAGS+=-I${.CURDIR}/../../lib
055396
-LDADD+=	-locurses -ltelnet
055396
-DPADD=	${LIBOLDCURSES} ${LIBTELNET}
055396
+LDADD+=	-lcurses -ltelnet
055396
+DPADD=	${LIBCURSES} ${LIBTELNET
055396
 
055396
 SRCS=	authenc.c commands.c main.c network.c ring.c sys_bsd.c telnet.c \
055396
 	terminal.c tn3270.c utilities.c
055396
 
055396
 .include <bsd.own.mk> # for KERBEROS
055396
 
055396
-.if (${KERBEROS} == "yes")
055396
+.if (${KERBEROS:L} == "yes")
055396
 CFLAGS+=-DENCRYPTION -DAUTHENTICATION -DKRB4
055396
 LDADD+= -lkrb -ldes
055396
 DPADD+= ${LIBDES} ${LIBKRB}
055396
 .endif
055396
 
055396
 .include <bsd.prog.mk>
055396
-
055396
diff -uNr telnet/commands.c telnet.obsd-cvs/commands.c
055396
--- telnet/commands.c	Fri Apr  9 02:30:20 1999
055396
+++ telnet.obsd-cvs/commands.c	Sat Mar 10 10:51:22 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: commands.c,v 1.20 1999/01/04 07:55:05 art Exp $	*/
055396
+/*	$OpenBSD: commands.c,v 1.34 2000/11/08 21:49:44 aaron Exp $	*/
055396
 /*	$NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $	*/
055396
 
055396
 /*
055396
@@ -69,7 +69,7 @@
055396
 	int status;
055396
 
055396
 	if(argc != 3) {
055396
-		printf("%s sequence challenge\n", argv[0]);
055396
+		printf("usage: %s sequence challenge\n", argv[0]);
055396
 		return 0;
055396
 	}
055396
 
055396
@@ -2175,17 +2175,19 @@
055396
     int gotmachine = 0;
055396
     int l1 = strlen(m1);
055396
     int l2 = strlen(m2);
055396
-    char m1save[64];
055396
+    char m1save[MAXHOSTNAMELEN];
055396
 
055396
     if (skiprc)
055396
 	return;
055396
 
055396
-    strcpy(m1save, m1);
055396
+    strncpy(m1save, m1, sizeof(m1save));
055396
     m1 = m1save;
055396
 
055396
     if (rcname[0] == 0) {
055396
 	char *home = getenv("HOME");
055396
 
055396
+	if (home == NULL || *home == '\0')
055396
+	    return;
055396
 	snprintf (rcname, sizeof(rcname), "%s/.telnetrc",
055396
 		  home ? home : "");
055396
     }
055396
@@ -2248,15 +2250,9 @@
055396
     int
055396
 tn(int argc, char *argv[])
055396
 {
055396
-    struct hostent *host = 0, *alias = 0;
055396
-#if defined(AF_INET6)
055396
-    struct sockaddr_in6 sin6;
055396
-#endif
055396
+    struct addrinfo hints, *res, *res0;
055396
+    int error;
055396
     struct sockaddr_in sin;
055396
-    struct sockaddr_in ladr;
055396
-    struct sockaddr *sa;
055396
-    int sa_size;
055396
-    struct servent *sp = 0;
055396
     unsigned long temp;
055396
 #if !defined(__linux__)
055396
     extern char *inet_ntoa();
055396
@@ -2266,15 +2262,18 @@
055396
     int srlen;
055396
 #endif
055396
     char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0;
055396
-    int family, port = 0;
055396
-
055396
+    int retry;
055396
+#ifdef NI_WITHSCOPEID
055396
+    const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
055396
+#else
055396
+    const int niflags = NI_NUMERICHOST;
055396
+#endif
055396
+    
055396
     /* clear the socket address prior to use */
055396
     memset((char *)&sin, 0, sizeof(sin));
055396
 
055396
     if (connected) {
055396
 	printf("?Already connected to %s\r\n", hostname);
055396
-	seteuid(getuid());
055396
-	setuid(getuid());
055396
 	return 0;
055396
     }
055396
     if (argc < 2) {
055396
@@ -2324,8 +2323,6 @@
055396
 	}
055396
     usage:
055396
 	printf("usage: %s [-l user] [-a] host-name [port]\r\n", cmd);
055396
-	seteuid(getuid());
055396
-	setuid(getuid());
055396
 	return 0;
055396
     }
055396
     if (hostp == 0)
055396
@@ -2340,185 +2337,80 @@
055396
 	temp = sourceroute(hostp, &srp, &srlen);
055396
 	if (temp == 0) {
055396
 	    herror(srp);
055396
-	    seteuid(getuid());
055396
-	    setuid(getuid());
055396
 	    return 0;
055396
 	} else if (temp == -1) {
055396
 	    printf("Bad source route option: %s\r\n", hostp);
055396
-	    seteuid(getuid());
055396
-	    setuid(getuid());
055396
 	    return 0;
055396
 	} else {
055396
 	    abort();
055396
 	}
055396
-    } else {
055396
-#endif
055396
-	memset (&sin, 0, sizeof(sin));
055396
-#if defined(HAVE_INET_PTON) && defined(AF_INET6)
055396
-	memset (&sin6, 0, sizeof(sin6));
055396
-
055396
-	if(inet_pton(AF_INET6, hostp, &sin6.sin6_addr)) {
055396
-	    sin6.sin6_family = family = AF_INET6;
055396
-	    sa = (struct sockaddr *)&sin;;
055396
-	    sa_size = sizeof(sin6);
055396
-	    strcpy(_hostname, hostp);
055396
-	    hostname =_hostname;
055396
-	} else
055396
-#endif
055396
-	    if(inet_aton(hostp, &sin.sin_addr)){
055396
-		sin.sin_family = family = AF_INET;
055396
-		sa = (struct sockaddr *)&sin;
055396
-		sa_size = sizeof(sin);
055396
-		strcpy(_hostname, hostp);
055396
-		hostname = _hostname;
055396
-	    } else {
055396
-#ifdef HAVE_GETHOSTBYNAME2
055396
-		host = gethostbyname2(hostp, AF_INET6);
055396
-		if(host == NULL)
055396
-		    host = gethostbyname2(hostp, AF_INET);
055396
-#else
055396
-		host = gethostbyname(hostp);
055396
-#endif
055396
-		if (host) {
055396
-		    strncpy(_hostname, host->h_name, sizeof(_hostname));
055396
-		    family = host->h_addrtype;
055396
-
055396
-		    switch(family) {
055396
-		    case AF_INET:
055396
-			memset(&sin, 0, sizeof(sin));
055396
-			sa_size = sizeof(sin);
055396
-			sa = (struct sockaddr *)&sin;
055396
-			sin.sin_family = family;
055396
-
055396
-			memcpy(&sin.sin_addr, *host->h_addr_list, sizeof(struct in_addr));
055396
-			break;
055396
-#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
055396
-		    case AF_INET6:
055396
-			memset(&sin6, 0, sizeof(sin6));
055396
-			sa_size = sizeof(sin6);
055396
-			sa = (struct sockaddr *)&sin;;
055396
-			sin6.sin6_family = family;
055396
-			memcpy(&sin6.sin6_addr, *host->h_addr_list, sizeof(struct in6_addr));
055396
-			break;
055396
-#endif
055396
-		    default:
055396
-			fprintf(stderr, "Bad address family: %d\n", family);
055396
-			return 0;
055396
-		    }
055396
-		    
055396
-		    _hostname[sizeof(_hostname)-1] = '\0';
055396
-		    hostname = _hostname;
055396
-		} else {
055396
-		    herror(hostp);
055396
-		    seteuid(getuid());
055396
-		    setuid(getuid());
055396
-		    return 0;
055396
-		}
055396
-	    }
055396
-#if	defined(IP_OPTIONS) && defined(IPPROTO_IP)
055396
-    }
055396
+    } else
055396
 #endif
055396
-    if (portp) {
055396
-	if (*portp == '-') {
055396
-	    portp++;
055396
-	    telnetport = 1;
055396
-	} else
055396
-	    telnetport = 0;
055396
-	port = atoi(portp);
055396
-	if (port == 0) {
055396
-	    sp = getservbyname(portp, "tcp");
055396
-	    if (sp)
055396
-		port = sp->s_port;
055396
-	    else {
055396
-		printf("%s: bad port number\r\n", portp);
055396
-		seteuid(getuid());
055396
-		setuid(getuid());
055396
-		return 0;
055396
-	    }
055396
-	} else {
055396
-	    port = htons(port);
055396
-	}
055396
-    } else {
055396
-	if (sp == 0) {
055396
-	    sp = getservbyname("telnet", "tcp");
055396
-	    if (sp == 0) {
055396
-		fprintf(stderr, "telnet: tcp/telnet: unknown service\r\n");
055396
-		seteuid(getuid());
055396
-		setuid(getuid());
055396
-		return 0;
055396
-	    }
055396
-	    port = sp->s_port;
055396
+    {
055396
+	hostname = hostp;
055396
+	memset(&hints, 0, sizeof(hints));
055396
+	hints.ai_family = PF_UNSPEC;
055396
+	hints.ai_socktype = SOCK_STREAM;
055396
+	hints.ai_flags = AI_CANONNAME;
055396
+	if (portp == NULL) {
055396
+		portp = "telnet";
055396
+	} else if (*portp == '-') {
055396
+		portp++;
055396
+		telnetport = 1;
055396
+	}
055396
+	h_errno = 0;
055396
+	error = getaddrinfo(hostp, portp, &hints, &res0);
055396
+	if (error) {
055396
+	    if (error == EAI_SERVICE)
055396
+	        warnx("%s: bad port", portp);
055396
+	    else
055396
+		warnx("%s: %s", hostp, gai_strerror(error));
055396
+	   if (h_errno)
055396
+		herror(hostp);
055396
+	   return 0;
055396
 	}
055396
-	telnetport = 1;
055396
     }
055396
-    switch(family) {
055396
-    case AF_INET:
055396
-	sin.sin_port = port;
055396
-	printf("Trying %s...\r\n", inet_ntoa(sin.sin_addr));
055396
-	break;
055396
-#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
055396
-    case AF_INET6: {
055396
-#ifndef INET6_ADDRSTRLEN
055396
-#define INET6_ADDRSTRLEN 46 
055396
-#endif
055396
 
055396
-	char buf[INET6_ADDRSTRLEN];
055396
-
055396
-	sin6.sin6_port = port;
055396
-#ifdef HAVE_INET_NTOP
055396
-	printf("Trying %s...\r\n", inet_ntop(AF_INET6,
055396
-					     &sin6.sin6_addr,
055396
-					     buf,
055396
-					     sizeof(buf)));
055396
-#endif
055396
-	break;
055396
-    }
055396
-#endif
055396
-    default:
055396
-	abort();
055396
-    }
055396
-
055396
-    do {
055396
-	net = socket(family, SOCK_STREAM, 0);
055396
-	seteuid(getuid());
055396
-	setuid(getuid());
055396
-	if (net < 0) {
055396
-	    perror("telnet: socket");
055396
-	    return 0;
055396
+    net = -1;
055396
+    retry = 0;
055396
+    for (res = res0; res; res = res->ai_next) {
055396
+	if (1 /* retry */) {
055396
+	    char hbuf[NI_MAXHOST];
055396
+	    
055396
+	    if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
055396
+	            NULL, 0, niflags) != 0) {
055396
+		strcpy(hbuf, "(invalid)");
055396
+	    }
055396
+	    printf("Trying %s...\r\n", hbuf);
055396
 	}
055396
+	net = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
055396
+	if (net < 0)
055396
+	    continue;
055396
+	    
055396
 	if (aliasp) {
055396
-	    memset ((caddr_t)&ladr, 0, sizeof (ladr));
055396
-	    temp = inet_addr(aliasp);
055396
-	    if (temp != INADDR_NONE) {
055396
-	        ladr.sin_addr.s_addr = temp;
055396
-	        ladr.sin_family = AF_INET;
055396
-	        alias = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
055396
-	    } else {
055396
-	        alias = gethostbyname(aliasp);
055396
-	        if (alias) {
055396
-		    ladr.sin_family = alias->h_addrtype;
055396
-#if	defined(h_addr)		/* In 4.3, this is a #define */
055396
-		    memmove((caddr_t)&ladr.sin_addr,
055396
-			alias->h_addr_list[0], alias->h_length);
055396
-#else	/* defined(h_addr) */
055396
-		    memmove((caddr_t)&ladr.sin_addr, alias->h_addr,
055396
-			alias->h_length);
055396
-#endif	/* defined(h_addr) */
055396
-	        } else {
055396
-		    herror(aliasp);
055396
-		    return 0;
055396
-	        }
055396
+	    struct addrinfo ahints, *ares;
055396
+	    memset(&ahints, 0, sizeof(ahints));
055396
+	    ahints.ai_family = PF_UNSPEC;
055396
+	    ahints.ai_socktype = SOCK_STREAM;
055396
+	    ahints.ai_flags = AI_PASSIVE;
055396
+	    error = getaddrinfo(aliasp, "0", &ahints, &ares);
055396
+	    if (error) {
055396
+	        warn("%s: %s", aliasp, gai_strerror(error));
055396
+	        close(net);
055396
+	        freeaddrinfo(ares);
055396
+	        continue;
055396
 	    }
055396
-            ladr.sin_port = htons(0);
055396
-  
055396
-            if (bind (net, (struct sockaddr *)&ladr, sizeof(ladr)) < 0) {
055396
-                perror(aliasp);; 
055396
+	    if (bind(net, ares->ai_addr, ares->ai_addrlen) < 0) {
055396
+	        perror(aliasp);
055396
                 (void) close(net);   /* dump descriptor */
055396
-		return 0;
055396
+		freeaddrinfo(ares);
055396
+		continue;
055396
             }
055396
+	    freeaddrinfo(ares);
055396
         }
055396
  #if	defined(IP_OPTIONS) && defined(IPPROTO_IP)
055396
-	if (srp && setsockopt(net, IPPROTO_IP, IP_OPTIONS, (char *)srp, srlen) < 0)
055396
+	if (srp && res->ai_family == AF_INET
055396
+	 && setsockopt(net, IPPROTO_IP, IP_OPTIONS, (char *)srp, srlen) < 0)
055396
 		perror("setsockopt (IP_OPTIONS)");
055396
 #endif
055396
 #if	defined(IPPROTO_IP) && defined(IP_TOS)
055396
@@ -2542,65 +2434,32 @@
055396
 		perror("setsockopt (SO_DEBUG)");
055396
 	}
055396
 
055396
-	if (connect(net, sa, sa_size) < 0) {
055396
-	    int retry = 0;
055396
-
055396
-	    if (host && host->h_addr_list[1]) {
055396
-		int oerrno = errno;
055396
-	        retry = 1;
055396
-
055396
-		switch(family) {
055396
-		case AF_INET :
055396
-		    fprintf(stderr, "telnet: connect to address %s: ",
055396
-			    inet_ntoa(sin.sin_addr));
055396
-		    ++host->h_addr_list;
055396
-		    memcpy(&sin.sin_addr, *host->h_addr_list, sizeof(struct in_addr));
055396
-		    break;
055396
-#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
055396
-		case AF_INET6: {
055396
-		    char buf[INET6_ADDRSTRLEN];
055396
-
055396
-		    fprintf(stderr, "telnet: connect to address %s: ",
055396
-			    inet_ntop(AF_INET6, &sin6.sin6_addr, buf,
055396
-				      sizeof(buf)));
055396
-		    ++host->h_addr_list;
055396
-		    memcpy(&sin6.sin6_addr, *host->h_addr_list, sizeof(struct in6_addr));
055396
-		    break;
055396
-		}
055396
-#endif
055396
-		default:
055396
-		    abort();
055396
-		}
055396
-                   
055396
-		errno = oerrno;
055396
-		perror(NULL);
055396
-
055396
-		switch(family) {
055396
-		case AF_INET :
055396
-			printf("Trying %s...\r\n", inet_ntoa(sin.sin_addr));
055396
-			break;
055396
-#if defined(AF_INET6) && defined(HAVE_STRUCT_SOCKADDR_IN6)
055396
-		case AF_INET6: {
055396
-		    printf("Trying %s...\r\n", inet_ntop(AF_INET6,
055396
-					     &sin6.sin6_addr,
055396
-					     buf,
055396
-					     sizeof(buf)));
055396
-		    break;
055396
-		}
055396
-#endif
055396
-		}
055396
-		
055396
-		(void) NetClose(net);
055396
-		continue;
055396
+	if (connect(net, res->ai_addr, res->ai_addrlen) < 0) {
055396
+	    char hbuf[NI_MAXHOST];
055396
+	    
055396
+	    if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
055396
+		    NULL, 0, NI_NUMERICHOST) != 0) {
055396
+	        strcpy(hbuf, "(invalid)");
055396
 	    }
055396
-	    perror("telnet: Unable to connect to remote host");
055396
-	    return 0;
055396
+	    fprintf(stderr, "telnet: connect to address %s: %s\n", hbuf,
055396
+	        strerror(errno));
055396
+	
055396
+	    close(net);
055396
+	    net = -1;
055396
+	    retry++;
055396
+	    continue;
055396
 	}
055396
+
055396
 	connected++;
055396
 #if	defined(AUTHENTICATION) || defined(ENCRYPTION)
055396
 	auth_encrypt_connect(connected);
055396
 #endif	/* defined(AUTHENTICATION) */
055396
-    } while (connected == 0);
055396
+	break;
055396
+    }
055396
+    freeaddrinfo(res0);
055396
+    if (net < 0) {
055396
+        return 0;
055396
+    }
055396
     cmdrc(hostp, hostname);
055396
     if (autologin && user == NULL) {
055396
 	struct passwd *pw;
055396
@@ -2652,6 +2511,9 @@
055396
         encrypthelp[] = "turn on (off) encryption ('encrypt ?' for more)",
055396
 #endif
055396
 	zhelp[] =	"suspend telnet",
055396
+#ifdef SKEY
055396
+	skeyhelp[] =	"compute response to s/key challenge",
055396
+#endif
055396
 	shellhelp[] =	"invoke a subshell",
055396
 	envhelp[] =	"change environment variables ('environ ?' for more)",
055396
 	modestring[] = "try to enter line or character mode ('mode ?' for more)";
055396
@@ -2690,7 +2552,7 @@
055396
 	{ "environ",	envhelp,	env_cmd,	0 },
055396
 	{ "?",		helphelp,	help,		0 },
055396
 #if	defined(SKEY)
055396
-	{ "skey",	NULL,		skey_calc,	0 },
055396
+	{ "skey",	skeyhelp,	skey_calc,	0 },
055396
 #endif		
055396
 	{ 0,		0,		0,		0 }
055396
 };
055396
diff -uNr telnet/externs.h telnet.obsd-cvs/externs.h
055396
--- telnet/externs.h	Mon Feb  8 22:56:11 1999
055396
+++ telnet.obsd-cvs/externs.h	Sat Mar 10 10:54:35 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: externs.h,v 1.4 1998/03/12 17:31:32 deraadt Exp $	*/
055396
+/*	$OpenBSD: externs.h,v 1.5 1998/03/12 2001/01/22 11:03:38 fgsch Exp $	*/
055396
 /* $KTH: externs.h,v 1.16 1997/11/29 02:28:35 joda Exp $ */
055396
 
055396
 /*
055396
@@ -447,7 +447,7 @@
055396
     *Ibackp,           /* Oldest byte of 3270 data */
055396
     Ibuf[],            /* 3270 buffer */
055396
     *Ifrontp,          /* Where next 3270 byte goes */
055396
-    tline[],
055396
+    tline[200],
055396
     *transcom;         /* Transparent command */
055396
 
055396
 extern int
055396
diff -uNr telnet/main.c telnet.obsd-cvs/main.c
055396
--- telnet/main.c	Wed Apr  7 23:23:35 1999
055396
+++ telnet.obsd-cvs/main.c	Sat Mar 10 09:59:35 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: main.c,v 1.7 1998/05/15 03:16:38 art Exp $	*/
055396
+/*	$OpenBSD: main.c,v 1.10 2001/01/21 22:46:37 aaron Exp $	*/
055396
 /*	$NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $	*/
055396
 
055396
 /*
055396
@@ -81,10 +81,10 @@
055396
 	    prompt,
055396
 #ifdef	AUTHENTICATION
055396
 	    "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
055396
-	    "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] [-b hostalias ]",
055396
+	    "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] [-b hostalias ] ",
055396
 #else
055396
 	    "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
055396
-	    "\n\t[-n tracefile] [-b hostalias ]",
055396
+	    "\n\t[-n tracefile] [-b hostalias ] ",
055396
 #endif
055396
 #if defined(TN3270) && defined(unix)
055396
 # ifdef AUTHENTICATION
055396
@@ -95,13 +95,11 @@
055396
 #else
055396
 	    "[-r] ",
055396
 #endif
055396
+	    "\n\r "
055396
 #ifdef ENCRYPTION
055396
-	    "[-x] [host-name [port]]"
055396
-#else
055396
-
055396
-	    "[host-name [port]]"
055396
+	    "[-x] " 
055396
 #endif
055396
-	);
055396
+	    "[host-name [port]]");
055396
 	exit(1);
055396
 }
055396
 
055396
@@ -276,8 +274,8 @@
055396
 			break;
055396
 		case 't':
055396
 #if defined(TN3270) && defined(unix)
055396
+			(void)strncpy(tline, optarg, sizeof(tline));
055396
 			transcom = tline;
055396
-			(void)strcpy(transcom, optarg);
055396
 #else
055396
 			fprintf(stderr,
055396
 			   "%s: Warning: -t ignored, no TN3270 support.\n",
055396
diff -uNr telnet/sys_bsd.c telnet.obsd-cvs/sys_bsd.c
055396
--- telnet/sys_bsd.c	Wed Apr  7 21:38:31 1999
055396
+++ telnet.obsd-cvs/sys_bsd.c	Sat Mar 10 10:55:18 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: sys_bsd.c,v 1.6 1998/12/28 11:13:51 deraadt Exp $	*/
055396
+/*	$OpenBSD: sys_bsd.c,v 1.8 2000/10/10 15:41:10 millert Exp $	*/
055396
 /*	$NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $	*/
055396
 
055396
 /*
055396
@@ -35,6 +35,7 @@
055396
  */
055396
 
055396
 #include "telnet_locl.h"
055396
+#include <err.h>
055396
 
055396
 /*
055396
  * The following routines try to encapsulate what is system dependent
055396
@@ -198,9 +199,10 @@
055396
 TerminalFlushOutput(void)
055396
 {
055396
 #ifdef	TIOCFLUSH
055396
-    (void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0);
055396
+    int com = FWRITE;
055396
+    (void) ioctl(fileno(stdout), TIOCFLUSH, (int *) &com);
055396
 #else
055396
-    (void) ioctl(fileno(stdout), TCFLSH, (char *) 0);
055396
+    (void) ioctl(fileno(stdout), TCFLSH, (int *) 0);
055396
 #endif
055396
 }
055396
 
055396
diff -uNr telnet/telnet.c telnet.obsd-cvs/telnet.c
055396
--- telnet/telnet.c	Wed Apr  7 23:22:14 1999
055396
+++ telnet.obsd-cvs/telnet.c	Sat Mar 10 11:02:34 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: telnet.c,v 1.6 1998/07/27 15:29:29 millert Exp $	*/
055396
+/*	$OpenBSD: telnet.c,v 1.11 2000/11/10 15:33:13 provos millert Exp $	*/
055396
 /*	$NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $	*/
055396
 
055396
 /*
055396
@@ -35,6 +35,8 @@
055396
  */
055396
 
055396
 #include "telnet_locl.h"
055396
+#include <curses.h>
055396
+#include <term.h>
055396
 
055396
 #define        strip(x) (eight ? (x) : ((x) & 0x7f))
055396
 
055396
@@ -523,10 +525,9 @@
055396
 }
055396
 
055396
 /*
055396
- * Given a buffer returned by tgetent(), this routine will turn
055396
- * the pipe seperated list of names in the buffer into an array
055396
- * of pointers to null terminated names.  We toss out any bad,
055396
- * duplicate, or verbose names (names with spaces).
055396
+ * This routine will turn a pipe seperated list of names in the buffer
055396
+ * into an array of pointers to NUL terminated names.  We toss out any
055396
+ * bad, duplicate, or verbose names (names with spaces).
055396
  */
055396
 
055396
 int is_unique P((char *, char **, char **));
055396
@@ -554,7 +555,7 @@
055396
 	/*
055396
 	 * Count up the number of names.
055396
 	 */
055396
-	for (n = 1, cp = buf; *cp && *cp != ':'; cp++) {
055396
+	for (n = 1, cp = buf; *cp; cp++) {
055396
 		if (*cp == '|')
055396
 			n++;
055396
 	}
055396
@@ -659,25 +660,6 @@
055396
 	return (1);
055396
 }
055396
 
055396
-static char termbuf[1024];
055396
-
055396
-int telnet_setupterm	P((char *tname, int fd, int *errp)); /* XXX move elsewhere */
055396
-	/*ARGSUSED*/
055396
-	int
055396
-telnet_setupterm(char *tname, int fd, int *errp)
055396
-{
055396
-	(void)fd;
055396
-	if (tgetent(termbuf, tname) == 1) {
055396
-		termbuf[1023] = '\0';
055396
-		if (errp)
055396
-			*errp = 1;
055396
-		return(0);
055396
-	}
055396
-	if (errp)
055396
-		*errp = 0;
055396
-	return(-1);
055396
-}
055396
-
055396
 int resettermname = 1;
055396
 
055396
 char *gettermname P((void));	/* XXX move elsewhere */
055396
@@ -687,15 +669,15 @@
055396
 	char *tname;
055396
 	static char **tnamep = 0;
055396
 	static char **next;
055396
-	int err;
055396
+	int errret;
055396
 
055396
 	if (resettermname) {
055396
 		resettermname = 0;
055396
 		if (tnamep && tnamep != unknown)
055396
 			free(tnamep);
055396
 		if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) &&
055396
-				(telnet_setupterm(tname, 1, &err) == 0)) {
055396
-			tnamep = mklist(termbuf, tname);
055396
+				(setupterm(tname, 1, &errret) == 0)) {
055396
+			tnamep = mklist(ttytype, tname);
055396
 		} else {
055396
 			if (tname && ((int)strlen(tname) <= 40)) {
055396
 				unknown[0] = tname;
055396
@@ -1482,10 +1464,15 @@
055396
 	void
055396
 env_opt_start(void)
055396
 {
055396
-	if (opt_reply)
055396
-		opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
055396
-	else
055396
-		opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
055396
+	unsigned char *p;
055396
+	
055396
+	if (opt_reply) {
055396
+		p = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
055396
+		if (p == NULL)
055396
+			free(opt_reply);
055396
+	} else
055396
+		p = (unsigned char *)malloc(OPT_REPLY_SIZE);
055396
+	opt_reply = p;	
055396
 	if (opt_reply == NULL) {
055396
 /*@*/		printf("env_opt_start: malloc()/realloc() failed!!!\n");
055396
 		opt_reply = opt_replyp = opt_replyend = NULL;
055396
@@ -1532,9 +1519,13 @@
055396
 				strlen((char *)ep) + 6 > opt_replyend)
055396
 	{
055396
 		int len;
055396
+		unsigned char *p;
055396
 		opt_replyend += OPT_REPLY_SIZE;
055396
 		len = opt_replyend - opt_reply;
055396
-		opt_reply = (unsigned char *)realloc(opt_reply, len);
055396
+		p = (unsigned char *)realloc(opt_reply, len);
055396
+		if (p == NULL)
055396
+			free(opt_reply);
055396
+		opt_reply = p;
055396
 		if (opt_reply == NULL) {
055396
 /*@*/			printf("env_opt_add: realloc() failed!!!\n");
055396
 			opt_reply = opt_replyp = opt_replyend = NULL;
055396
@@ -1945,7 +1936,7 @@
055396
 				command(0, "z\n", 2);
055396
 				continue;
055396
 			}
055396
-			if (sc == escape) {
055396
+			if (sc == escape && escape != _POSIX_VDISABLE) {
055396
 				command(0, (char *)tbp, tcc);
055396
 				bol = 1;
055396
 				count += tcc;
055396
@@ -1962,7 +1953,7 @@
055396
 		}
055396
 		if ((sc == '\n') || (sc == '\r'))
055396
 			bol = 1;
055396
-	} else if (sc == escape) {
055396
+	} else if (sc == escape && escape != _POSIX_VDISABLE) {
055396
 	    /*
055396
 	     * Double escape is a pass through of a single escape character.
055396
 	     */
055396
diff -uNr telnet/telnet_locl.h telnet.obsd-cvs/telnet_locl.h
055396
--- telnet/telnet_locl.h	Thu Mar 12 06:57:44 1998
055396
+++ telnet.obsd-cvs/telnet_locl.h	Sat Mar 10 11:12:37 2001
055396
@@ -1,4 +1,4 @@
055396
-/*	$OpenBSD: telnet_locl.h,v 1.1 1998/03/12 04:57:44 art Exp $	*/
055396
+/*	$OpenBSD: telnet_locl.h,v 1.2 1999/12/11 09:08:09 itojun Exp $	*/
055396
 /* $KTH: telnet_locl.h,v 1.13 1997/11/03 21:37:55 assar Exp $ */
055396
 
055396
 /*
055396
@@ -86,7 +86,5 @@
055396
 #include "defines.h"
055396
 #include "types.h"
055396
 
055396
-#undef AF_INET6 /* XXX - it has not been tested and it doesn't exist yet */
055396
-
055396
 /* prototypes */
055396
 
055396
diff -uNr libtelnet/kerberos.c libtelnet.obsd-cvs/kerberos.c
055396
--- libtelnet/kerberos.c	Mon Feb  8 23:38:17 1999
055396
+++ libtelnet.obsd-cvs/kerberos.c	Sat Mar 10 11:11:03 2001
055396
@@ -320,11 +320,10 @@
055396
 	    char ts[MAXPATHLEN];
055396
 	    struct passwd *pw = getpwnam(UserNameRequested);
055396
 
055396
-	    if(pw){
055396
+	    if (pw) {
055396
 		snprintf(ts, sizeof(ts),
055396
-			 "%s%u",
055396
-			 TKT_ROOT,
055396
-			 (unsigned)pw->pw_uid);
055396
+			"%s%u", TKT_ROOT, (unsigned)pw->pw_uid);
055396
+		/* XXX allocation failure? */
055396
 		setenv("KRBTKFILE", ts, 1);
055396
 	    }
055396
 	    Data(ap, KRB_ACCEPT, NULL, 0);
055396
@@ -609,16 +608,26 @@
055396
 {
055396
     unsigned char *p = buf;
055396
     
055396
-    p += krb_put_nir(cred->service, cred->instance, cred->realm, p);
055396
+    memcpy (p, cred->service, ANAME_SZ);
055396
+    p += ANAME_SZ;
055396
+    memcpy (p, cred->instance, INST_SZ);
055396
+    p += INST_SZ;
055396
+    memcpy (p, cred->realm, REALM_SZ);
055396
+    p += REALM_SZ;
055396
     memcpy(p, cred->session, 8);
055396
     p += 8;
055396
     *p++ = cred->lifetime;
055396
     *p++ = cred->kvno;
055396
-    p += krb_put_int(cred->ticket_st.length, p, 4);
055396
+    p += krb_put_int(cred->ticket_st.length, p, 4, 4);
055396
     memcpy(p, cred->ticket_st.dat, cred->ticket_st.length);
055396
     p += cred->ticket_st.length;
055396
-    p += krb_put_int(cred->issue_date, p, 4);
055396
-    p += krb_put_nir(cred->pname, cred->pinst, NULL, p);
055396
+    p += krb_put_int(cred->issue_date, p, 4, 4);
055396
+    strncpy (cred->pname, p, ANAME_SZ);
055396
+    cred->pname[ANAME_SZ - 1] = '\0';
055396
+    p += ANAME_SZ;
055396
+    strncpy (cred->pinst, p, INST_SZ);
055396
+    cred->pinst[INST_SZ - 1] = '\0';
055396
+    p += INST_SZ;
055396
     return p - buf;
055396
 }
055396
 
055396
@@ -627,7 +636,16 @@
055396
 {
055396
     unsigned char *p = buf;
055396
 
055396
-    p += krb_get_nir(p, cred->service, cred->instance, cred->realm);
055396
+    strncpy (cred->service, p, ANAME_SZ);
055396
+    cred->service[ANAME_SZ - 1] = '\0';
055396
+    p += ANAME_SZ;
055396
+    strncpy (cred->instance, p, INST_SZ);
055396
+    cred->instance[INST_SZ - 1] = '\0';
055396
+    p += INST_SZ;
055396
+    strncpy (cred->realm, p, REALM_SZ);
055396
+    cred->realm[REALM_SZ - 1] = '\0';
055396
+    p += REALM_SZ;
055396
+
055396
     memcpy(cred->session, p, 8);
055396
     p += 8;
055396
     cred->lifetime = *p++;
055396
@@ -636,7 +654,10 @@
055396
     memcpy(cred->ticket_st.dat, p, cred->ticket_st.length);
055396
     cred->ticket_st.mbz = 0;
055396
     p += krb_get_int(p, (u_int32_t *)&cred->issue_date, 4, 0);
055396
-    p += krb_get_nir(p, cred->pname, cred->pinst, NULL);
055396
+    p += krb_get_nir(p, 
055396
+		    cred->pname, sizeof(cred->pname),
055396
+		    cred->pinst, sizeof(cred->pinst),
055396
+		    NULL, 0);
055396
     return 0;
055396
 }
055396
 
055396
--- telnet/telnet.1	Thu Nov 12 01:01:46 1998
055396
+++ telnet.obsd-cvs/telnet.1	Thu Nov  9 19:52:41 2000
055396
@@ -1,4 +1,4 @@
055396
-.\"	$OpenBSD: telnet.1,v 1.14 1998/11/11 23:01:46 aaron Exp $
055396
+.\"	$OpenBSD: telnet.1,v 1.27 2000/11/09 17:52:41 aaron Exp $
055396
 .\"	$NetBSD: telnet.1,v 1.5 1996/02/28 21:04:12 thorpej Exp $
055396
 .\"
055396
 .\" Copyright (c) 1983, 1990, 1993
055396
@@ -36,45 +36,34 @@
055396
 .\"
055396
 .Dd February 3, 1994
055396
 .Dt TELNET 1
055396
-.Os BSD 4.2
055396
+.Os
055396
 .Sh NAME
055396
 .Nm telnet
055396
-.Nd user interface to the 
055396
+.Nd user interface to the
055396
 .Tn TELNET
055396
 protocol
055396
 .Sh SYNOPSIS
055396
 .Nm telnet
055396
-.Op Fl 8
055396
-.Op Fl E
055396
-.Op Fl F
055396
-.Op Fl K
055396
-.Op Fl L
055396
-.Op Fl S Ar tos
055396
+.Op Fl 8EFKLacdfrx
055396
 .Op Fl X Ar authtype
055396
-.Op Fl a
055396
 .Op Fl b Ar hostalias
055396
-.Op Fl c
055396
-.Op Fl d
055396
 .Op Fl e Ar escapechar
055396
-.Op Fl f
055396
 .Op Fl k Ar realm
055396
 .Op Fl l Ar user
055396
 .Op Fl n Ar tracefile
055396
-.Op Fl r
055396
-.Op Fl x
055396
 .Oo
055396
 .Ar host
055396
 .Op Ar port
055396
 .Oc
055396
 .Sh DESCRIPTION
055396
 The
055396
-.Nm telnet
055396
+.Nm
055396
 command
055396
-is used to communicate with another host using the 
055396
+is used to communicate with another host using the
055396
 .Tn TELNET
055396
 protocol.
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is invoked without the
055396
 .Ar host
055396
 argument, it enters command mode,
055396
@@ -85,11 +74,11 @@
055396
 .Ic open
055396
 command with those arguments.
055396
 .Pp
055396
-Options:
055396
-.Bl -tag -width indent
055396
+The options are as follows:
055396
+.Bl -tag -width Ds
055396
 .It Fl 8
055396
-Specifies an 8-bit data path.  This causes an attempt to
055396
-negotiate the
055396
+Specifies an 8-bit data path.
055396
+This causes an attempt to negotiate the
055396
 .Dv TELNET BINARY
055396
 option on both input and output.
055396
 .It Fl E
055396
@@ -103,18 +92,9 @@
055396
 .It Fl K
055396
 Specifies no automatic login to the remote system.
055396
 .It Fl L
055396
-Specifies an 8-bit data path on output.  This causes the
055396
-BINARY option to be negotiated on output.
055396
-.It Fl S Ar tos
055396
-Sets the IP type-of-service (TOS) option for the telnet
055396
-connection to the value
055396
-.Ar tos ,
055396
-which can be a numeric TOS value
055396
-or, on systems that support it, a symbolic
055396
-TOS name found in the
055396
-.Pa /etc/iptos
055396
-file.
055396
-.It Fl X Ar atype 
055396
+Specifies an 8-bit data path on output.
055396
+This causes the BINARY option to be negotiated on output.
055396
+.It Fl X Ar atype
055396
 Disables the
055396
 .Ar atype
055396
 type of authentication.
055396
@@ -144,7 +124,8 @@
055396
 .It Fl c
055396
 Disables the reading of the user's
055396
 .Pa \&.telnetrc
055396
-file.  (See the
055396
+file.
055396
+(See the
055396
 .Ic toggle skiprc
055396
 command on this man page.)
055396
 .It Fl d
055396
@@ -152,7 +133,7 @@
055396
 .Ic debug
055396
 toggle to
055396
 .Dv TRUE .
055396
-.It Fl e Ar escapechar 
055396
+.It Fl e Ar escapechar
055396
 Sets the initial
055396
 .Nm
055396
 escape character to
055396
@@ -169,14 +150,14 @@
055396
 If Kerberos authentication is being used, the
055396
 .Fl k
055396
 option requests that
055396
-.Nm telnet
055396
+.Nm
055396
 obtain tickets for the remote host in
055396
 realm
055396
 .Ar realm
055396
 instead of the remote host's realm, as determined
055396
 by
055396
 .Xr krb_realmofhost 3 .
055396
-.It Fl l Ar user 
055396
+.It Fl l Ar user
055396
 When connecting to the remote system, if the remote system
055396
 understands the
055396
 .Ev ENVIRON
055396
@@ -189,7 +170,7 @@
055396
 This option may also be used with the
055396
 .Ic open
055396
 command.
055396
-.It Fl n Ar tracefile 
055396
+.It Fl n Ar tracefile
055396
 Opens
055396
 .Ar tracefile
055396
 for recording trace information.
055396
@@ -210,35 +191,38 @@
055396
 Indicates the official name, an alias, or the Internet address
055396
 of a remote host.
055396
 .It Ar port
055396
-Indicates a port number (address of an application).  If a number is
055396
-not specified, the default
055396
-.Nm telnet
055396
+Indicates a port number (address of an application).
055396
+If a number is not specified, the default
055396
+.Nm
055396
 port is used.
055396
 .El
055396
 .Pp
055396
-When in rlogin mode, a line of the form ~.  disconnects from the
055396
+When in rlogin mode, a line of the form ~.
055396
+disconnects from the
055396
 remote host; ~ is the telnet escape character.
055396
 Similarly, the line ~^Z suspends the telnet session.
055396
 The line ~^] escapes to the normal telnet escape prompt.
055396
 .Pp
055396
 Once a connection has been opened,
055396
-.Nm telnet
055396
+.Nm
055396
 will attempt to enable the
055396
 .Dv TELNET LINEMODE
055396
 option.
055396
 If this fails,
055396
-.Nm telnet
055396
+.Nm
055396
 will revert to one of two input modes:
055396
 either ``character at a time''
055396
 or ``old line by line''
055396
 depending on what the remote system supports.
055396
 .Pp
055396
-When 
055396
+When
055396
 .Dv LINEMODE
055396
 is enabled, character processing is done on the
055396
-local system, under the control of the remote system.  When input
055396
+local system, under the control of the remote system.
055396
+When input
055396
 editing or character echoing is to be disabled, the remote system
055396
-will relay that information.  The remote system will also relay
055396
+will relay that information.
055396
+The remote system will also relay
055396
 changes to any special characters that happen on the remote
055396
 system, so that they can take effect on the local system.
055396
 .Pp
055396
@@ -252,7 +236,7 @@
055396
 (this would mostly be used to enter passwords
055396
 without the password being echoed).
055396
 .Pp
055396
-If the 
055396
+If the
055396
 .Dv LINEMODE
055396
 option is enabled, or if the
055396
 .Ic localchars
055396
@@ -267,7 +251,7 @@
055396
 characters are trapped locally, and sent as
055396
 .Tn TELNET
055396
 protocol sequences to the remote side.
055396
-If 
055396
+If
055396
 .Dv LINEMODE
055396
 has ever been enabled, then the user's
055396
 .Ic susp
055396
@@ -278,9 +262,9 @@
055396
 protocol sequences,
055396
 and
055396
 .Ic quit
055396
-is sent as a 
055396
+is sent as a
055396
 .Dv TELNET ABORT
055396
-instead of 
055396
+instead of
055396
 .Dv BREAK .
055396
 There are options (see
055396
 .Ic toggle
055396
@@ -296,17 +280,26 @@
055396
 (in the case of
055396
 .Ic quit
055396
 and
055396
-.Ic intr  ) .
055396
+.Ic intr ) .
055396
 .Pp
055396
 While connected to a remote host,
055396
-.Nm telnet
055396
+.Nm
055396
 command mode may be entered by typing the
055396
-.Nm telnet
055396
+.Nm
055396
 ``escape character'' (initially ``^]'').
055396
 When in command mode, the normal terminal editing conventions are available.
055396
+Note that the escape character will return to the command mode of the initial
055396
+invocation of
055396
+.Nm
055396
+that has the controlling terminal.
055396
+Use the
055396
+.Cm send escape
055396
+command to switch to command mode in subsequent
055396
+.Nm
055396
+processes on remote hosts.
055396
 .Pp
055396
 The following
055396
-.Nm telnet
055396
+.Nm
055396
 commands are available.
055396
 Only enough of each command to uniquely identify it need be typed
055396
 (this is also true for arguments to the
055396
@@ -320,26 +313,28 @@
055396
 .Ic display
055396
 commands).
055396
 .Bl -tag -width "mode type"
055396
-.It Ic auth Ar argument Op Ar ... 
055396
+.It Ic auth Ar argument Op Ar ...
055396
 The
055396
 .Ic auth
055396
 command manipulates the information sent through the
055396
 .Dv TELNET AUTHENTICATE
055396
-option.  Valid arguments for the
055396
-auth command are as follows:
055396
+option.
055396
+Valid arguments for the
055396
+.Ic auth
055396
+command are as follows:
055396
 .Bl -tag -width "disable type"
055396
 .It Ic disable Ar type
055396
 Disables the specified
055396
 .Ar type
055396
-of authentication.  To
055396
-obtain a list of available types, use the
055396
+of authentication.
055396
+To obtain a list of available types, use the
055396
 .Ic auth disable \&?
055396
 command.
055396
 .It Ic enable Ar type
055396
 Enables the specified
055396
 .Ar type
055396
-of authentication.  To
055396
-obtain a list of available types, use the
055396
+of authentication.
055396
+To obtain a list of available types, use the
055396
 .Ic auth enable \&?
055396
 command.
055396
 .It Ic status
055396
@@ -350,7 +345,7 @@
055396
 Close a
055396
 .Tn TELNET
055396
 session and return to command mode.
055396
-.It Ic display Ar argument Op Ar ... 
055396
+.It Ic display Ar argument Op Ar ...
055396
 Displays all, or some, of the
055396
 .Ic set
055396
 and
055396
@@ -368,26 +363,27 @@
055396
 .It Ic disable Ar type Ic [input|output]
055396
 Disables the specified
055396
 .Ar type
055396
-of encryption.  If you
055396
-omit
055396
+of encryption.
055396
+If you omit
055396
 .Ic input
055396
 and
055396
 .Ic output ,
055396
 both input and output
055396
-are disabled.  To obtain a list of available
055396
-types, use the
055396
+are disabled.
055396
+To obtain a list of available types, use the
055396
 .Ic encrypt disable \&?
055396
 command.
055396
 .It Ic enable Ar type Ic [input|output]
055396
 Enables the specified
055396
 .Ar type
055396
-of encryption.  If you
055396
-omit
055396
+of encryption.
055396
+If you omit
055396
 .Ic input
055396
 and
055396
 .Ic output ,
055396
 both input and output are
055396
-enabled.  To obtain a list of available types, use the
055396
+enabled.
055396
+To obtain a list of available types, use the
055396
 .Ic encrypt enable \&?
055396
 command.
055396
 .It Ic input
055396
@@ -407,18 +403,20 @@
055396
 .Ic encrypt stop output
055396
 command.
055396
 .It Ic start Ic [input|output]
055396
-Attempts to start encryption.  If you omit
055396
+Attempts to start encryption.
055396
+If you omit
055396
 .Ic input
055396
 and
055396
-.Ic output,
055396
-both input and output are enabled.  To
055396
-obtain a list of available types, use the
055396
+.Ic output ,
055396
+both input and output are enabled.
055396
+To obtain a list of available types, use the
055396
 .Ic encrypt enable \&?
055396
 command.
055396
 .It Ic status
055396
 Lists the current status of encryption.
055396
 .It Ic stop Ic [input|output]
055396
-Stops encryption.  If you omit
055396
+Stops encryption.
055396
+If you omit
055396
 .Ic input
055396
 and
055396
 .Ic output ,
055396
@@ -431,7 +429,7 @@
055396
 .Ic encrypt stop
055396
 commands.
055396
 .El
055396
-.It Ic environ Ar arguments Op Ar ... 
055396
+.It Ic environ Ar arguments Op Ar ...
055396
 The
055396
 .Ic environ
055396
 command is used to manipulate the
055396
@@ -456,7 +454,7 @@
055396
 .Ic environ
055396
 command are:
055396
 .Bl -tag -width Fl
055396
-.It Ic define Ar variable value 
055396
+.It Ic define Ar variable value
055396
 Define the variable
055396
 .Ar variable
055396
 to have a value of
055396
@@ -466,15 +464,15 @@
055396
 .Ar value
055396
 may be enclosed in single or double quotes so
055396
 that tabs and spaces may be included.
055396
-.It Ic undefine Ar variable 
055396
+.It Ic undefine Ar variable
055396
 Remove
055396
 .Ar variable
055396
 from the list of environment variables.
055396
-.It Ic export Ar variable 
055396
+.It Ic export Ar variable
055396
 Mark the variable
055396
 .Ar variable
055396
 to be exported to the remote side.
055396
-.It Ic unexport Ar variable 
055396
+.It Ic unexport Ar variable
055396
 Mark the variable
055396
 .Ar variable
055396
 to not be exported unless
055396
@@ -508,7 +506,7 @@
055396
 suspending a user's session for later reattachment,
055396
 the logout argument indicates that you
055396
 should terminate the session immediately.
055396
-.It Ic mode Ar type 
055396
+.It Ic mode Ar type
055396
 .Ar type
055396
 is one of several options, depending on the state of the
055396
 .Tn TELNET
055396
@@ -529,40 +527,40 @@
055396
 option, or, if the remote side does not understand the
055396
 .Dv LINEMODE
055396
 option, then attempt to enter ``old-line-by-line'' mode.
055396
-.It Ic isig Pq Ic \-isig 
055396
-Attempt to enable (disable) the 
055396
+.It Ic isig Pq Ic \-isig
055396
+Attempt to enable (disable) the
055396
 .Dv TRAPSIG
055396
-mode of the 
055396
+mode of the
055396
 .Dv LINEMODE
055396
 option.
055396
-This requires that the 
055396
+This requires that the
055396
 .Dv LINEMODE
055396
 option be enabled.
055396
-.It Ic edit Pq Ic \-edit 
055396
-Attempt to enable (disable) the 
055396
+.It Ic edit Pq Ic \-edit
055396
+Attempt to enable (disable) the
055396
 .Dv EDIT
055396
-mode of the 
055396
+mode of the
055396
 .Dv LINEMODE
055396
 option.
055396
-This requires that the 
055396
+This requires that the
055396
 .Dv LINEMODE
055396
 option be enabled.
055396
-.It Ic softtabs Pq Ic \-softtabs 
055396
-Attempt to enable (disable) the 
055396
+.It Ic softtabs Pq Ic \-softtabs
055396
+Attempt to enable (disable) the
055396
 .Dv SOFT_TAB
055396
-mode of the 
055396
+mode of the
055396
 .Dv LINEMODE
055396
 option.
055396
-This requires that the 
055396
+This requires that the
055396
 .Dv LINEMODE
055396
 option be enabled.
055396
-.It Ic litecho Pq Ic \-litecho 
055396
-Attempt to enable (disable) the 
055396
+.It Ic litecho Pq Ic \-litecho
055396
+Attempt to enable (disable) the
055396
 .Dv LIT_ECHO
055396
-mode of the 
055396
+mode of the
055396
 .Dv LINEMODE
055396
 option.
055396
-This requires that the 
055396
+This requires that the
055396
 .Dv LINEMODE
055396
 option be enabled.
055396
 .It Ic \&?
055396
@@ -579,7 +577,7 @@
055396
 Open a connection to the named host.
055396
 If no port number
055396
 is specified,
055396
-.Nm telnet
055396
+.Nm
055396
 will attempt to contact a
055396
 .Tn TELNET
055396
 server at the default port.
055396
@@ -594,24 +592,29 @@
055396
 .Ev ENVIRON
055396
 option.
055396
 When connecting to a non-standard port,
055396
-.Nm telnet
055396
+.Nm
055396
 omits any automatic initiation of
055396
 .Tn TELNET
055396
-options.  When the port number is preceded by a minus sign,
055396
+options.
055396
+When the port number is preceded by a minus sign,
055396
 the initial option negotiation is done.
055396
 After establishing a connection, the file
055396
 .Pa \&.telnetrc
055396
 in the
055396
-user's home directory is opened.  Lines beginning with a ``#'' are
055396
-comment lines.  Blank lines are ignored.  Lines that begin
055396
-without white space are the start of a machine entry.  The
055396
-first thing on the line is the name of the machine that is
055396
-being connected to.  The rest of the line, and successive
055396
-lines that begin with white space are assumed to be
055396
-.Nm telnet
055396
+user's home directory is opened.
055396
+Lines beginning with a ``#'' are
055396
+comment lines.
055396
+Blank lines are ignored.
055396
+Lines that begin
055396
+without whitespace are the start of a machine entry.
055396
+The first thing on the line is the name of the machine that is
055396
+being connected to.
055396
+The rest of the line, and successive
055396
+lines that begin with whitespace are assumed to be
055396
+.Nm
055396
 commands and are processed as if they had been typed
055396
 in manually to the
055396
-.Nm telnet
055396
+.Nm
055396
 command prompt.
055396
 .It Ic quit
055396
 Close any open
055396
@@ -619,7 +622,7 @@
055396
 session and exit
055396
 .Nm telnet .
055396
 An end-of-file (in command mode) will also close a session and exit.
055396
-.It Ic send Ar arguments 
055396
+.It Ic send Ar arguments
055396
 Sends one or more special character sequences to the remote host.
055396
 The following are the arguments which may be specified
055396
 (more than one argument may be specified at a time):
055396
@@ -673,7 +676,7 @@
055396
 sequence.
055396
 .It Ic escape
055396
 Sends the current
055396
-.Nm telnet
055396
+.Nm
055396
 escape character (initially ``^]'').
055396
 .It Ic ga
055396
 Sends the
055396
@@ -788,12 +791,12 @@
055396
 .Ic send
055396
 command.
055396
 .El
055396
-.It Ic set Ar argument value 
055396
-.It Ic unset Ar argument value 
055396
+.It Ic set Ar argument value
055396
+.It Ic unset Ar argument value
055396
 The
055396
 .Ic set
055396
 command will set any one of a number of
055396
-.Nm telnet
055396
+.Nm
055396
 variables to a specific value or to
055396
 .Dv TRUE .
055396
 The special value
055396
@@ -811,7 +814,8 @@
055396
 .Ic display
055396
 command.
055396
 The variables which may be set or unset, but not toggled, are
055396
-listed here.  In addition, any of the variables for the
055396
+listed here.
055396
+In addition, any of the variables for the
055396
 .Ic toggle
055396
 command may be explicitly set or unset using
055396
 the
055396
@@ -832,7 +836,8 @@
055396
 sequence (see
055396
 .Ic send ayt
055396
 preceding) is sent to the
055396
-remote host.  The initial value for the "Are You There"
055396
+remote host.
055396
+The initial value for the "Are You There"
055396
 character is the terminal's status character.
055396
 .It Ic echo
055396
 This is the value (initially ``^E'') which, when in
055396
@@ -841,7 +846,7 @@
055396
 echoing of entered characters (for entering, say, a password).
055396
 .It Ic eof
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in
055396
 .Dv LINEMODE
055396
 or ``old line by line'' mode, entering this character
055396
@@ -854,7 +859,7 @@
055396
 character.
055396
 .It Ic erase
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode (see
055396
@@ -862,7 +867,7 @@
055396
 .Ic localchars
055396
 below),
055396
 and if
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in ``character at a time'' mode, then when this
055396
 character is typed, a
055396
 .Dv TELNET EC
055396
@@ -879,14 +884,14 @@
055396
 character.
055396
 .It Ic escape
055396
 This is the
055396
-.Nm telnet
055396
+.Nm
055396
 escape character (initially ``^['') which causes entry
055396
 into
055396
-.Nm telnet
055396
+.Nm
055396
 command mode (when connected to a remote system).
055396
 .It Ic flushoutput
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode (see
055396
@@ -916,12 +921,13 @@
055396
 .Dv LINEMODE ,
055396
 these are the
055396
 characters that, when typed, cause partial lines to be
055396
-forwarded to the remote system.  The initial value for
055396
+forwarded to the remote system.
055396
+The initial value for
055396
 the forwarding characters are taken from the terminal's
055396
 eol and eol2 characters.
055396
 .It Ic interrupt
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode (see
055396
@@ -945,7 +951,7 @@
055396
 character.
055396
 .It Ic kill
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode (see
055396
@@ -953,7 +959,7 @@
055396
 .Ic localchars
055396
 below),
055396
 and if
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in ``character at a time'' mode, then when this
055396
 character is typed, a
055396
 .Dv TELNET EL
055396
@@ -970,7 +976,7 @@
055396
 character.
055396
 .It Ic lnext
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in
055396
 .Dv LINEMODE
055396
 or ``old line by line'' mode, then this character is taken to
055396
@@ -985,7 +991,7 @@
055396
 character.
055396
 .It Ic quit
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode (see
055396
@@ -1009,7 +1015,7 @@
055396
 character.
055396
 .It Ic reprint
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in
055396
 .Dv LINEMODE
055396
 or old line by line'' mode, then this character is taken to
055396
@@ -1031,8 +1037,9 @@
055396
 This character, at the beginning of a line, followed by
055396
 a "." closes the connection; when followed by a ^Z it
055396
 suspends the
055396
-.Nm telnet
055396
-command.  The initial state is to
055396
+.Nm
055396
+command.
055396
+The initial state is to
055396
 disable the
055396
 .Ic rlogin
055396
 escape character.
055396
@@ -1066,7 +1073,7 @@
055396
 character.
055396
 .It Ic susp
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is in
055396
 .Ic localchars
055396
 mode, or
055396
@@ -1093,12 +1100,13 @@
055396
 .Ic option
055396
 tracing being
055396
 .Dv TRUE ,
055396
-will be written.  If it is set to
055396
+will be written.
055396
+If it is set to
055396
 .Dq Fl ,
055396
 then tracing information will be written to standard output (the default).
055396
 .It Ic worderase
055396
 If
055396
-.Nm telnet
055396
+.Nm
055396
 is operating in
055396
 .Dv LINEMODE
055396
 or ``old line by line'' mode, then this character is taken to
055396
@@ -1117,25 +1125,32 @@
055396
 .Pq Ic unset
055396
 commands.
055396
 .El
055396
-.It Ic slc Ar state 
055396
+.It Ic skey Ar sequence challenge
055396
+The
055396
+.Ic skey
055396
+command computes a response to the S/Key challenge.
055396
+See
055396
+.Xr skey 1
055396
+for more information on the S/Key system.
055396
+.It Ic slc Ar state
055396
 The
055396
 .Ic slc
055396
 command (Set Local Characters) is used to set
055396
 or change the state of the special
055396
-characters when the 
055396
+characters when the
055396
 .Dv TELNET LINEMODE
055396
 option has
055396
-been enabled.  Special characters are characters that get
055396
-mapped to 
055396
+been enabled.
055396
+Special characters are characters that get mapped to
055396
 .Tn TELNET
055396
 commands sequences (like
055396
 .Ic ip
055396
 or
055396
-.Ic quit  )
055396
+.Ic quit )
055396
 or line editing characters (like
055396
 .Ic erase
055396
 and
055396
-.Ic kill  ) .
055396
+.Ic kill ) .
055396
 By default, the local special characters are exported.
055396
 .Bl -tag -width Fl
055396
 .It Ic check
055396
@@ -1144,15 +1159,15 @@
055396
 character settings, and if there are any discrepancies with
055396
 the local side, the local side will switch to the remote value.
055396
 .It Ic export
055396
-Switch to the local defaults for the special characters.  The
055396
-local default characters are those of the local terminal at
055396
+Switch to the local defaults for the special characters.
055396
+The local default characters are those of the local terminal at
055396
 the time when
055396
-.Nm telnet
055396
+.Nm
055396
 was started.
055396
 .It Ic import
055396
 Switch to the remote defaults for the special characters.
055396
 The remote default characters are those of the remote system
055396
-at the time when the 
055396
+at the time when the
055396
 .Tn TELNET
055396
 connection was established.
055396
 .It Ic \&?
055396
@@ -1165,13 +1180,13 @@
055396
 .Nm telnet .
055396
 This includes the peer one is connected to, as well
055396
 as the current mode.
055396
-.It Ic toggle Ar arguments Op Ar ... 
055396
+.It Ic toggle Ar arguments Op Ar ...
055396
 Toggle (between
055396
 .Dv TRUE
055396
 and
055396
 .Dv FALSE )
055396
 various flags that control how
055396
-.Nm telnet
055396
+.Nm
055396
 responds to events.
055396
 These flags may be set explicitly to
055396
 .Dv TRUE
055396
@@ -1206,7 +1221,7 @@
055396
 sequences; see
055396
 .Ic set
055396
 above for details),
055396
-.Nm telnet
055396
+.Nm
055396
 refuses to display any data on the user's terminal
055396
 until the remote system acknowledges (via a
055396
 .Dv TELNET TIMING MARK
055396
@@ -1220,13 +1235,14 @@
055396
 done an "stty noflsh", otherwise
055396
 .Dv FALSE
055396
 (see
055396
-.Xr stty  1  ) .
055396
+.Xr stty 1 ) .
055396
 .It Ic autodecrypt
055396
 When the
055396
 .Dv TELNET ENCRYPT
055396
 option is negotiated, by
055396
 default the actual encryption (decryption) of the data
055396
-stream does not start automatically.  The
055396
+stream does not start automatically.
055396
+The
055396
 .Ic autoencrypt
055396
 .Pq Ic autodecrypt
055396
 command states that encryption of the
055396
@@ -1238,7 +1254,8 @@
055396
 .Dv TELNET AUTHENTICATION
055396
 option
055396
 .Tn TELNET
055396
-attempts to use it to perform automatic authentication.  If the
055396
+attempts to use it to perform automatic authentication.
055396
+If the
055396
 .Dv AUTHENTICATION
055396
 option is not supported, the user's login
055396
 name are propagated through the
055396
@@ -1314,7 +1331,7 @@
055396
 The initial value for this toggle is
055396
 .Dv FALSE .
055396
 .It Ic debug
055396
-Toggles socket level debugging (useful only to the super-user).
055396
+Toggles socket level debugging (useful only to the superuser).
055396
 The initial value for this toggle is
055396
 .Dv FALSE .
055396
 .It Ic encdebug
055396
@@ -1340,7 +1357,7 @@
055396
 .Ic brk ,
055396
 .Ic ec ,
055396
 and
055396
-.Ic el  ;
055396
+.Ic el ;
055396
 see
055396
 .Ic send
055396
 above).
055396
@@ -1379,7 +1396,7 @@
055396
 .Dv FALSE .
055396
 .It Ic options
055396
 Toggles the display of some internal
055396
-.Nm telnet
055396
+.Nm
055396
 protocol processing (having to do with
055396
 .Tn TELNET
055396
 options).
055396
@@ -1404,8 +1421,8 @@
055396
 skips the reading of the
055396
 .Pa \&.telnetrc
055396
 file in the user's home
055396
-directory when connections are opened.  The initial
055396
-value for this toggle is
055396
+directory when connections are opened.
055396
+The initial value for this toggle is
055396
 .Dv FALSE .
055396
 .It Ic termdata
055396
 Toggles the display of all terminal data (in hexadecimal format).
055396
@@ -1416,9 +1433,10 @@
055396
 .Ic verbose_encrypt
055396
 toggle is
055396
 .Dv TRUE ,
055396
-.Nm telnet
055396
+.Nm
055396
 prints out a message each time encryption is enabled or
055396
-disabled.  The initial value for this toggle is
055396
+disabled.
055396
+The initial value for this toggle is
055396
 .Dv FALSE .
055396
 .It Ic \&?
055396
 Displays the legal
055396
@@ -1430,22 +1448,24 @@
055396
 .Nm telnet .
055396
 This command only works when the user is using the
055396
 .Xr csh 1 .
055396
-.It Ic \&! Op Ar command 
055396
+.It Ic \&! Op Ar command
055396
 Execute a single command in a subshell on the local
055396
-system.  If
055396
+system.
055396
+If
055396
 .Ar command
055396
 is omitted, then an interactive
055396
 subshell is invoked.
055396
-.It Ic \&? Op Ar command 
055396
-Get help.  With no arguments,
055396
-.Nm telnet
055396
+.It Ic \&? Op Ar command
055396
+Get help.
055396
+With no arguments,
055396
+.Nm
055396
 prints a help summary.
055396
 If a command is specified,
055396
-.Nm telnet
055396
+.Nm
055396
 will print the help information for just that command.
055396
 .El
055396
 .Sh ENVIRONMENT
055396
-.Nm telnet
055396
+.Nm
055396
 uses at least the
055396
 .Ev HOME ,
055396
 .Ev SHELL ,
055396
@@ -1464,16 +1484,18 @@
055396
 .El
055396
 .Sh HISTORY
055396
 The
055396
-.Nm telnet
055396
+.Nm
055396
 command appeared in
055396
 .Bx 4.2 .
055396
 .Sh NOTES
055396
 On some remote systems, echo has to be turned off manually when in
055396
 ``old line by line'' mode.
055396
 .Pp
055396
-In ``old line by line'' mode or 
055396
+In ``old line by line'' mode or
055396
 .Dv LINEMODE
055396
 the terminal's
055396
 .Ic eof
055396
 character is only recognized (and sent to the remote system)
055396
 when it is the first character on a line.
055396
+.Pp
055396
+Source routing is not supported yet for IPv6.