*BSD News Article 15747


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!goanna!escargot!otto!davidb
From: davidb@otto.bf.rmit.oz.au (David Burren [Athos])
Newsgroups: comp.os.386bsd.bugs
Subject: Patch to netstat to clean up output
Keywords: patch
Message-ID: <davidb.736697833@otto>
Date: 6 May 93 14:17:13 GMT
Organization: Royal Melbourne Institute of Technology
Lines: 89
NNTP-Posting-Host: otto.bf.rmit.oz.au

The following patch to /usr/src/usr.bin/netstat/route.c fixes what
I saw as two bugs in `netstat -r`:

1.	The output of "Route Tree for Protocol Family" specified the
	PF as an int rather than a name.
	My fix for this was a quick hack.

2.	The gateways in the routing table were always reported as
	numeric addresses, even when "-n" was ommitted.
	The fix for this is simple and clean.

This is another of the patches I made some time ago and have
dug up in my move to NetBSD.  Looking at it now, my definition
of p_proto() was ugly, but can anyone suggest a cleaner fix?

Cheers!
__
David Burren
davidb@otto.bf.rmit.oz.au (guest acct)
+61-3-634-3635


*** route.c	Thu May  6 22:50:16 1993
--- route.c.orig	Mon Mar 22 04:16:51 1993
***************
*** 85,109 ****
  };
  
  /*
-  * Print address family.
-  */
- void
- p_proto(proto)
- 	int	proto;
- {
- 	switch (proto)
- 	{
- 	case AF_INET:
- 		printf("inet");
- 		break;
- 	default:
- 		printf("%d", proto);
- 		break;
- 	}
- }
- 
- 
- /*
   * Print routing tables.
   */
  routepr(hostaddr, netaddr, hashsizeaddr, treeaddr)
--- 85,90 ----
***************
*** 188,196 ****
  				p_tree(head.rnh_treetop);
  			}
  		} else if (af == AF_UNSPEC || af == head.rnh_af) {
! 			printf("\nRoute Tree for Protocol Family ");
! 			p_proto(head.rnh_af);
! 			printf(":\n");
  			do_rtent = 1;
  			p_tree(head.rnh_treetop);
  		}
--- 169,176 ----
  				p_tree(head.rnh_treetop);
  			}
  		} else if (af == AF_UNSPEC || af == head.rnh_af) {
! 			printf("\nRoute Tree for Protocol Family %d:\n",
! 								head.rnh_af);
  			do_rtent = 1;
  			p_tree(head.rnh_treetop);
  		}
***************
*** 398,404 ****
  	struct ifnet ifnet;
  
  	p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, 16);
! 	p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, 18);
  	p_flags(rt->rt_flags, "%-6.6s ");
  	printf("%6d %8d ", rt->rt_refcnt, rt->rt_use);
  	if (rt->rt_ifp == 0) {
--- 378,384 ----
  	struct ifnet ifnet;
  
  	p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, 16);
! 	p_sockaddr(kgetsa(rt->rt_gateway), 0, 18);
  	p_flags(rt->rt_flags, "%-6.6s ");
  	printf("%6d %8d ", rt->rt_refcnt, rt->rt_use);
  	if (rt->rt_ifp == 0) {