FreeBSD

bin/402: w -n shows non-numeric addresses

From:henrich@crh.cl.msu.edu (Charles Henrich)
Date:Sat, 13 May 1995 18:13:35 -0400
Subject:w -n doesnt work as advertised.
Send-pr version:3.2

Number:402
Category:bin
Synopsis:w -n shows non-numeric addresses
Severity:non-critical
Priority:low
Responsible:ache@FreeBSD.org
State:closed
Class:sw-bug
Arrival-Date:Sat May 13 15:20:01 1995
Closed-Date:Mon Jun 17 08:46:47 PDT 1996
Last-Modified:Mon Jun 17 08:48:28 PDT 1996
Originator:Charles Henrich &
Release:FreeBSD 2.1.0-Development i386

Organization:
Michigan State University
 
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.

Download patch-1.diff
*** 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;


Release-Note:
 
Audit-Trail:
Responsible Changed
From-To:freebsd-bugs->ache
By:scrappy
When:Sun May 26 14:45:07 PDT 1996
Why:last person to do any changes to 'w' that I can find

State Changed
From-To:open->closed
By:ache
When:Mon Jun 17 08:46:47 PDT 1996
Why:Fixed in w.c 1.13 and various login/logwtmp patches

Unformatted:
 
Submit Followup | Raw PR | Find another PR