Subject: bin/1473: netstat -i formats badly
To: None <gnats-bugs@gnats.netbsd.org>
From: David Carrel <carrel@cisco.com>
List: netbsd-bugs
Date: 09/16/1995 18:50:43
>Number:         1473
>Category:       bin
>Synopsis:       netstat -i formats badly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 18 17:20:01 1995
>Last-Modified:
>Originator:     David Carrel
>Organization:
	Just me.
>Release:        NetBSD-current, supped 14 Sept. 1995
>Environment:
	NetBSD i386, hp300, and presumably everything else.


>Description:
	The output of `netstat -i' formats badly when you don't have a lot
of zero's in you hardware address.  The output below is from my 3c589 card:

Name  Mtu   Network     Address            Ipkts Ierrs    Opkts Oerrs  Coll
ep0   1500  <Link>      0.20.af.df.7f.9e   344852     0   376130     0     0
ep0   1500  171.69.229. spion.cisco.com   344852     0   376130     0     0
lo0   32768 <Link>                            34     0       34     0     0
lo0   32768 127         localhost             34     0       34     0     0
ppp0* 1500  <Link>                             0     0        0     0     0
ppp1* 1500  <Link>                             0     0        0     0     0

Notice the top line for ep0 is skewed after the hardware address because
not enough space was left for the possible maximum 17 character string.
>How-To-Repeat:
	run netstat -i on a machine with the right hardware address.
>Fix:
The fix is to leave more spaces for the address.  There are enough spaces
available on the right margin to take two more for the address.  This
should cover all possible IP and ethernet addresses.  A patch is included.
It makes the above output look like so:

Name  Mtu   Network     Address              Ipkts Ierrs    Opkts Oerrs  Coll
ep0   1500  <Link>      0.20.af.df.7f.9e    348100     0   379371     0     0
ep0   1500  171.69.229. 171.69.229.173      348100     0   379371     0     0
lo0   32768 <Link>                              34     0       34     0     0
lo0   32768 127         127.0.0.1               34     0       34     0     0
ppp0* 1500  <Link>                               0     0        0     0     0
ppp1* 1500  <Link>                               0     0        0     0     0

Enough space exists that at least one space will always be left between the
address and "Ipkts".

*** if.c.orig	Sat Sep 16 18:32:58 1995
--- if.c	Sat Sep 16 18:32:58 1995
***************
*** 92,98 ****
  	}
  	if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
  		return;
! 	printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
  		"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
  		"Opkts", "Oerrs");
  	printf(" %5s", "Coll");
--- 92,98 ----
  	}
  	if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
  		return;
! 	printf("%-5.5s %-5.5s %-11.11s %-15.15s %10.10s %5.5s %8.8s %5.5s",
  		"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
  		"Opkts", "Oerrs");
  	printf(" %5s", "Coll");
***************
*** 138,144 ****
  			switch (sa->sa_family) {
  			case AF_UNSPEC:
  				printf("%-11.11s ", "none");
! 				printf("%-15.15s ", "none");
  				break;
  			case AF_INET:
  				sin = (struct sockaddr_in *)sa;
--- 138,144 ----
  			switch (sa->sa_family) {
  			case AF_UNSPEC:
  				printf("%-11.11s ", "none");
! 				printf("%-17.17s ", "none");
  				break;
  			case AF_INET:
  				sin = (struct sockaddr_in *)sa;
***************
*** 155,161 ****
  				    netname(ifaddr.in.ia_subnet,
  				    ifaddr.in.ia_subnetmask));
  #endif
! 				printf("%-15.15s ",
  				    routename(sin->sin_addr.s_addr));
  
  				if (aflag) {
--- 155,161 ----
  				    netname(ifaddr.in.ia_subnet,
  				    ifaddr.in.ia_subnetmask));
  #endif
! 				printf("%-17.17s ",
  				    routename(sin->sin_addr.s_addr));
  
  				if (aflag) {
***************
*** 183,189 ****
  		sprintf(netnum, "%lxH", ntohl(net));
  				upHex(netnum);
  				printf("ns:%-8s ", netnum);
! 				printf("%-15s ",
  				    ns_phost((struct sockaddr *)sns));
  				}
  				break;
--- 183,189 ----
  		sprintf(netnum, "%lxH", ntohl(net));
  				upHex(netnum);
  				printf("ns:%-8s ", netnum);
! 				printf("%-17s ",
  				    ns_phost((struct sockaddr *)sns));
  				}
  				break;
***************
*** 206,212 ****
  				while (--n >= 0)
  					m += printf("%x%c", *cp++ & 0xff,
  						    n > 0 ? '.' : ' ');
! 				m = 28 - m;
  				while (m-- > 0)
  					putchar(' ');
  				break;
--- 206,212 ----
  				while (--n >= 0)
  					m += printf("%x%c", *cp++ & 0xff,
  						    n > 0 ? '.' : ' ');
! 				m = 30 - m;
  				while (m-- > 0)
  					putchar(' ');
  				break;
>Audit-Trail:
>Unformatted: