Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 May 1995 15:20:02 -0700
From:      henrich@crh.cl.msu.edu (Charles Henrich)
To:        freebsd-bugs
Subject:   bin/402: w -n doesnt work as advertised.
Message-ID:  <199505132220.PAA13926@freefall.cdrom.com>
In-Reply-To: Your message of Sat, 13 May 1995 18:13:35 -0400 <199505132213.SAA27116@bsdprd1.ais.msu.edu>

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

>Number:         402
>Category:       bin
>Synopsis:       w -n shows non-numeric addresses
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs (FreeBSD bugs mailing list)
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 13 15:20:01 1995
>Originator:     Charles Henrich &
>Organization:
Michigan State University
>Release:        FreeBSD 2.1.0-Development i386
>Environment:

	FreeBSD 950412-SNAP
	

>Description:

	The w manpage says w -n should:

     -n      Show network addresses as numbers (normally w interprets address-
             es and attempts to display them symbolically).

	Unfortunatly it doesnt, it just takes the value in utmp and dumps it
	to the screen.  Unless the value in ptmp is numeric, we dont get what
	we want.  This especially sucks for any scripts that rely on w -n
	showing numeric's.
	

>How-To-Repeat:

	

>Fix:
	
	I modified w.c to attempt to figure out the ip address of the hosts
	that were non-IP.  Because some folks might need an option to make w
	not do any resolver lookups, I also added -l which mirrors the
	the existing -n flag, and ensures no nameserver calls get executed.


*** w.1	Fri Aug  5 10:13:34 1994
--- w.1.new	Sat May 13 18:03:54 1995
***************
*** 39,45 ****
  .Nd "who present users are and what they are doing"
  .Sh SYNOPSIS
  .Nm w
! .Op Fl hin
  .Op Fl M Ar core
  .Op Fl N Ar system
  .Op Ar user
--- 39,45 ----
  .Nd "who present users are and what they are doing"
  .Sh SYNOPSIS
  .Nm w
! .Op Fl hiln
  .Op Fl M Ar core
  .Op Fl N Ar system
  .Op Ar user
***************
*** 65,70 ****
--- 65,72 ----
  Suppress the heading.
  .It Fl i
  Output is sorted by idle time.
+ .It Fl l
+ Never do resolver/nameserver lookups
  .It Fl M
  Extract values associated with the name list from the specified
  core instead of the default

*** w.c	Sat Feb 18 11:29:39 1995
--- w.c.new	Sat May 13 18:06:51 1995
***************
*** 88,94 ****
  int		ttywidth;	/* width of tty */
  int		argwidth;	/* width of tty */
  int		header = 1;	/* true if -h flag: don't print heading */
! int		nflag;		/* true if -n flag: don't convert addrs */
  int		sortidle;	/* sort bu idle time */
  char	       *sel_user;	/* login of particular user selected */
  char		domain[MAXHOSTNAMELEN];
--- 88,95 ----
  int		ttywidth;	/* width of tty */
  int		argwidth;	/* width of tty */
  int		header = 1;	/* true if -h flag: don't print heading */
! int		nflag;		/* true if -n flag: return numeric addrs */
! int		lflag;		/* true if -l flag: no resolver lookups -Crh */
  int		sortidle;	/* sort bu idle time */
  char	       *sel_user;	/* login of particular user selected */
  char		domain[MAXHOSTNAMELEN];
***************
*** 159,166 ****
  		case 'n':
  			nflag = 1;
  			break;
! 		case 'f': case 'l': case 's': case 'u': case 'w':
! 			warnx("[-flsuw] no longer supported");
  			/* FALLTHROUGH */
  		case '?':
  		default:
--- 160,170 ----
  		case 'n':
  			nflag = 1;
  			break;
! 		case 'l':
! 			lflag = 1;
! 			break;
! 		case 'f': case 's': case 'u': case 'w':
! 			warnx("[-fsuw] no longer supported");
  			/* FALLTHROUGH */
  		case '?':
  		default:
***************
*** 294,300 ****
  		p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-";
  		if ((x = strchr(p, ':')) != NULL)
  			*x++ = '\0';
! 		if (!nflag && isdigit(*p) &&
  		    (long)(l = inet_addr(p)) != -1 &&
  		    (hp = gethostbyaddr((char *)&l, sizeof(l), AF_INET))) {
  			if (domain[0] != '\0') {
--- 298,304 ----
  		p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-";
  		if ((x = strchr(p, ':')) != NULL)
  			*x++ = '\0';
! 		if (!lflag && !nflag && isdigit(*p) &&
  		    (long)(l = inet_addr(p)) != -1 &&
  		    (hp = gethostbyaddr((char *)&l, sizeof(l), AF_INET))) {
  			if (domain[0] != '\0') {
***************
*** 306,311 ****
--- 310,326 ----
  			}
  			p = hp->h_name;
  		}
+ 		if(!lflag && nflag && !isdigit(*p) && *p != '-')
+ 			{
+ 			hp=gethostbyname(p);
+ 			if(hp != NULL) 
+ 				{
+ 				struct in_addr in;
+ 				memmove(&in, hp->h_addr, sizeof(in));
+ 				p = inet_ntoa(in);
+ 				}
+ 			}
+ 
  		if (x) {
  			(void)snprintf(buf, sizeof(buf), "%s:%s", p, x);
  			p = buf;
>Audit-Trail:
>Unformatted:





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