Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Aug 1996 17:16:03 +0200
From:      Poul-Henning Kamp <phk@critter.tfs.com>
Cc:        Dave Cornejo <dave@dogwood.com>, rgrimes@gndrsh.aac.dev.com, joerg_wunsch@uriah.heep.sax.de, asami@freefall.freebsd.org, CVS-committers@freefall.freebsd.org, cvs-all@freefall.freebsd.org, cvs-etc@freefall.freebsd.org
Subject:   test, review & comments please
Message-ID:  <258.840813363@critter.tfs.com>
In-Reply-To: Your message of "Fri, 23 Aug 1996 16:23:17 %2B0200." <3457.840810197@critter.tfs.com> 

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

Here is the code to change netstat to only resolve portnumbers if
there seem to be some sense in it, please test & comment!

Poul-Henning

Index: in_pcb.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.20
diff -u -r1.20 in_pcb.c
--- in_pcb.c	1996/08/12 14:05:54	1.20
+++ in_pcb.c	1996/08/23 14:56:52
@@ -202,6 +202,8 @@
 		ushort first, last;
 		int count;
 
+		inp->inp_flags |= INP_ANONPORT;
+
 		if (inp->inp_flags & INP_HIGHPORT) {
 			first = ipport_hifirstauto;	/* sysctl */
 			last  = ipport_hilastauto;
Index: in_pcb.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.11
diff -u -r1.11 in_pcb.h
--- in_pcb.h	1996/02/22 21:32:22	1.11
+++ in_pcb.h	1996/08/23 14:56:21
@@ -80,6 +80,7 @@
 #define	INP_HDRINCL		0x08	/* user supplies entire IP header */
 #define	INP_HIGHPORT		0x10	/* user wants "high" port binding */
 #define	INP_LOWPORT		0x20	/* user wants "low" port binding */
+#define	INP_ANONPORT		0x40	/* port chosen for user */
 
 #define	INPLOOKUP_WILDCARD	1
 
Index: inet.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/inet.c,v
retrieving revision 1.19
diff -u -r1.19 inet.c
--- inet.c	1996/06/05 17:24:33	1.19
+++ inet.c	1996/08/23 15:04:08
@@ -74,7 +74,7 @@
 struct	socket sockb;
 
 char	*inetname __P((struct in_addr *));
-void	inetprint __P((struct in_addr *, int, char *));
+void	inetprint __P((struct in_addr *, int, char *, int));
 
 /*
  * Print a summary of connections related to an Internet
@@ -141,8 +141,22 @@
 				printf("%8x ", (int)next);
 		printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
 			sockb.so_snd.sb_cc);
-		inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name);
-		inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, name);
+		if (nflag) {
+			inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
+			    name, 1);
+			inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
+			    name, 1);
+		} else if (inpcb.inp_flags & INP_ANONPORT) {
+			inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
+			    name, 1);
+			inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
+			    name, 0);
+		} else {
+			inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
+			    name, 0);
+			inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
+			    name, inpcb.inp_lport != inpcb.inp_fport);
+		}
 		if (istcp) {
 			if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
 				printf(" %d", tcpcb.t_state);
@@ -431,21 +445,21 @@
 
 /*
  * Pretty print an Internet address (net address + port).
- * If the nflag was specified, use numbers instead of names.
  */
 void
-inetprint(in, port, proto)
+inetprint(in, port, proto,numeric)
 	register struct in_addr *in;
 	int port;
 	char *proto;
+	int numeric;
 {
 	struct servent *sp = 0;
 	char line[80], *cp;
 	int width;
 
-	sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(in));
+	sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in));
 	cp = index(line, '\0');
-	if (!nflag && port)
+	if (!numeric && port)
 		sp = getservbyport((int)port, proto);
 	if (sp || port == 0)
 		sprintf(cp, "%.15s", sp ? sp->s_name : "*");
--
Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
whois: [PHK]                | phk@ref.tfs.com       TRW Financial Systems, Inc.
Future will arrive by its own means, progress not so.



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