Subject: bin/5872: Printing of port numbers numericay is incorrect
To: None <>
From: Paul Goyette <>
List: netbsd-bugs
Date: 07/29/1998 17:58:25
>Number:         5872
>Category:       bin
>Synopsis:       Printing of port numbers numericay is incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 29 18:05:01 1998
>Originator:     Paul Goyette
>Release:        7/25/98
System: NetBSD 1.3F NetBSD 1.3F (PC1) #12: Tue Jul 28 16:57:59 PDT 1998 i386

	When printing tcp/udp port numbers, the following decisions are
		1. If -n flag specified, print both ports numerically,
	  else	2. If local port was assigned, print it numerically,
		   but print the remote port as getservbyport()
	  else	3. If local and foreign ports differ, print local using
		   getservbyport() but force foreign port to be printed
	  else	4. Print both ports using getservbyport().

	I believe that the latter two cases should be switched, so that
	you only force the foreign port to be printed numerically if it
	has the SAME port number as the local port which will already
	be printed using getservbyport().  Consider the case where you
	have a ssh connection to a remote sshd;  current code shows:

tcp        0      0  pc1.1021               mac1.22                ESTABLISHED

	In this case the local port is not flagged as ANON because the
	local ssh client requires a privileged port.  Therefore, the
	local port is printed using getservbyport() (which returns the
	numeric value 1021 because there is no such port listed in
	/etc/services) and the foreign port is forced to print numerically
	as well.

	Implementing the following patch produces this output, which (to
	my mind) is more meaningful to the user:

tcp        0      0  pc1.1021               mac1.ssh               ESTABLISHED
	See discussion above.
	The following 1-line patch corrects this anomaly:

--- /usr/src/usr.bin/netstat/inet.c	Tue Jul 21 04:11:31 1998
+++ ./inet.c	Wed Jul 29 17:42:56 1998
@@ -156,7 +156,7 @@
 		} else {
 			inetprint(&inpcb.inp_laddr, inpcb.inp_lport, name, 0);
 			inetprint(&inpcb.inp_faddr, inpcb.inp_fport, name, 
-			    inpcb.inp_lport != inpcb.inp_fport);
+			    inpcb.inp_lport == inpcb.inp_fport);
 		if (istcp) {
 			if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)