From sthaug@nethelp.no  Sun Nov 15 08:57:22 1998
Received: from verdi.nethelp.no (verdi.nethelp.no [158.36.41.162])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id IAA12641
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 15 Nov 1998 08:57:16 -0800 (PST)
          (envelope-from sthaug@nethelp.no)
Received: (qmail 21228 invoked by uid 1001); 15 Nov 1998 16:56:52 +0000 (GMT)
Message-Id: <19981115165652.21227.qmail@verdi.nethelp.no>
Date: 15 Nov 1998 16:56:52 +0000 (GMT)
From: sthaug@nethelp.no
Reply-To: sthaug@nethelp.no
To: FreeBSD-gnats-submit@freebsd.org
Cc: sthaug@nethelp.no
Subject: telnet enhancement: option to prevent IP address to name lookup
X-Send-Pr-Version: 3.2

>Number:         8698
>Category:       bin
>Synopsis:       add telnet option to prevent IP address to name lookup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    billf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 15 09:00:00 PST 1998
>Closed-Date:    Sat Dec 26 10:50:32 PST 1998
>Last-Modified:  Sat Dec 26 10:51:02 PST 1998
>Originator:     Steinar Haug
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Nethelp Consulting
>Environment:

	FreeBSD 3.0-CURRENT i386 (from around 24. october 1998)

>Description:

	If a telnet destination host is given by IP address, telnet will
	attempt a gethostbyaddr() to lookup the corresponding host name.
	If the relevant name servers take a long time to answer (e.g. if
	they are lame), the telnet connection attempt will take a long
	time due to the name lookup.

	This patch adds a -N option to prevent IP address to name lookup
	when the destination host is given by IP address.

	The option really should have been -n (for similarity with route,
	arp, netstat etc), but the -n option is already taken. So use -N.

>How-To-Repeat:

	telnet (using IP address) to a site where the relevant name servers
	aren't fully functional. Observe how long the connection attempt
	takes.

>Fix:
	
	Below is a patch relative to telnet in FreeBSD 3.0-CURRENT.

	Steinar Haug, Nethelp consulting, sthaug@nethelp.no

*** commands.c.orig	Fri Jun 12 14:54:53 1998
--- commands.c	Sun Nov 15 16:58:10 1998
***************
*** 2186,2192 ****
  	if (temp != INADDR_NONE) {
  	    sin.sin_addr.s_addr = temp;
  	    sin.sin_family = AF_INET;
! 	    host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
  	    if (host)
  	        (void) strncpy(_hostname, host->h_name, sizeof(_hostname));
  	    else
--- 2186,2193 ----
  	if (temp != INADDR_NONE) {
  	    sin.sin_addr.s_addr = temp;
  	    sin.sin_family = AF_INET;
! 	    if (doaddrlookup)
! 		host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET);
  	    if (host)
  	        (void) strncpy(_hostname, host->h_name, sizeof(_hostname));
  	    else
*** main.c.orig	Sat Mar 29 05:32:57 1997
--- main.c	Sun Nov 15 17:03:33 1998
***************
*** 135,141 ****
  	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
  	autologin = -1;
  
! 	while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != -1) {
  		switch(ch) {
  		case '8':
  			eight = 3;	/* binary output and input */
--- 135,141 ----
  	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
  	autologin = -1;
  
! 	while ((ch = getopt(argc, argv, "8EKLNS:X:acde:fFk:l:n:rt:x")) != -1) {
  		switch(ch) {
  		case '8':
  			eight = 3;	/* binary output and input */
***************
*** 150,155 ****
--- 150,158 ----
  			break;
  		case 'L':
  			eight |= 2;	/* binary output only */
+ 			break;
+ 		case 'N':
+ 			doaddrlookup = 0;
  			break;
  		case 'S':
  		    {
*** telnet.c.orig	Mon Jul  6 23:01:42 1998
--- telnet.c	Sun Nov 15 17:03:22 1998
***************
*** 106,111 ****
--- 106,112 ----
  	donebinarytoggle,	/* the user has put us in binary */
  	dontlecho,	/* do we suppress local echoing right now? */
  	globalmode,
+ 	doaddrlookup = 1, /* Should we do IP address to name lookup? */
  	clienteof = 0;
  
  char *prompt = 0;
*** externs.h.orig	Tue Jan  7 20:47:56 1997
--- externs.h	Sun Nov 15 16:56:14 1998
***************
*** 145,150 ****
--- 145,151 ----
      termdata,		/* Print out terminal data flow */
  #endif	/* defined(unix) */
      debug,		/* Debug level */
+     doaddrlookup,	/* Should we do IP address to name lookup? */
      clienteof;		/* Client received EOF */
  
  extern cc_t escape;	/* Escape to command mode */
*** telnet.1.orig	Sat Dec 27 19:58:27 1997
--- telnet.1	Sun Nov 15 17:30:04 1998
***************
*** 93,98 ****
--- 93,101 ----
  Specifies an 8-bit data path on output.  This causes the
  .Dv BINARY
  option to be negotiated on output.
+ .It Fl N
+ Prevents IP address to name lookup when destination host is given as an
+ IP address.
  .It Fl S Ar tos
  Sets the IP type-of-service (TOS) option for the telnet
  connection to the value
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->billf 
Responsible-Changed-By: billf 
Responsible-Changed-When: Sun Dec 13 17:15:33 PST 1998 
Responsible-Changed-Why:  
I will look into this. 
State-Changed-From-To: open->closed 
State-Changed-By: billf 
State-Changed-When: Sat Dec 26 10:50:32 PST 1998 
State-Changed-Why:  
Committed and merged, thanks! 
>Unformatted:
