Module Name:    src
Committed By:   dyoung
Date:           Tue May  3 23:36:26 UTC 2011

Modified Files:
        src/usr.bin/netstat: inet.c inet6.c

Log Message:
Do not display expired or reclaimed vestigial TIME_WAIT entries.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.96 src/usr.bin/netstat/inet.c:1.97
--- src/usr.bin/netstat/inet.c:1.96	Tue May  3 18:28:46 2011
+++ src/usr.bin/netstat/inet.c	Tue May  3 23:36:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.96 2011/05/03 18:28:46 dyoung Exp $	*/
+/*	$NetBSD: inet.c,v 1.97 2011/05/03 23:36:26 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.96 2011/05/03 18:28:46 dyoung Exp $");
+__RCSID("$NetBSD: inet.c,v 1.97 2011/05/03 23:36:26 dyoung Exp $");
 #endif
 #endif /* not lint */
 
@@ -162,14 +162,15 @@
 			       tcpstates[t_state]);
 	}
 	if (Vflag && expires != NULL) {
-		if (expires->tv_sec != 0 || expires->tv_usec != -1) {
+		if (expires->tv_sec == 0 && expires->tv_usec == -1)
+			printf(" reclaimed");
+		else {
 			struct timeval delta;
 
 			timersub(expires, &now, &delta);
 			printf(" %.3fms",
 			    delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
-		} else
-			printf(" expired");
+		}
 	}
 	putchar('\n');
 }
@@ -187,6 +188,7 @@
 	struct timeval delta;
 	struct in_addr la, fa;
 	char buf[2][32];
+	static const struct timeval zero = {.tv_sec = 0, .tv_usec = 0};
 
 	la.s_addr = v4->laddr;
 	fa.s_addr = v4->faddr;
@@ -197,14 +199,19 @@
 	timersub(&vtw->expire, &now, &delta);
 
 	if (vtw->expire.tv_sec == 0 && vtw->expire.tv_usec == -1) {
-		dbg_printf("%15.15s:%d %15.15s:%d expired\n"
+		dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n"
 		    ,buf[0], ntohs(v4->lport)
 		    ,buf[1], ntohs(v4->fport));
 		if (!(Vflag && vflag))
 			return;
 	} else if (vtw->expire.tv_sec == 0)
 		return;
-	else {
+	else if (timercmp(&delta, &zero, <) && !(Vflag && vflag)) {
+		dbg_printf("%15.15s:%d %15.15s:%d expired\n"
+		    ,buf[0], ntohs(v4->lport)
+		    ,buf[1], ntohs(v4->fport));
+		return;
+	} else {
 		dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n"
 		    ,buf[0], ntohs(v4->lport)
 		    ,buf[1], ntohs(v4->fport)

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.54 src/usr.bin/netstat/inet6.c:1.55
--- src/usr.bin/netstat/inet6.c:1.54	Tue May  3 18:28:46 2011
+++ src/usr.bin/netstat/inet6.c	Tue May  3 23:36:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.54 2011/05/03 18:28:46 dyoung Exp $	*/
+/*	$NetBSD: inet6.c,v 1.55 2011/05/03 23:36:26 dyoung Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.54 2011/05/03 18:28:46 dyoung Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.55 2011/05/03 23:36:26 dyoung Exp $");
 #endif
 #endif /* not lint */
 
@@ -217,14 +217,15 @@
 #endif
 	}
 	if (Vflag && expires != NULL) {
-		if (expires->tv_sec != 0 || expires->tv_usec != -1) {
+		if (expires->tv_sec == 0 && expires->tv_usec == -1)
+			printf(" reclaimed");
+		else {
 			struct timeval delta;
 
 			timersub(expires, &now, &delta);
 			printf(" %.3fms",
 			    delta.tv_sec * 1000.0 + delta.tv_usec / 1000.0);
-		} else
-			printf(" expired");
+		}
 	}
 	putchar('\n');
 }
@@ -241,6 +242,7 @@
 	const vtw_v6_t *v6 = (const vtw_v6_t *)vtw;
 	struct timeval delta;
 	char buf[2][128];
+	static const struct timeval zero = {.tv_sec = 0, .tv_usec = 0};
 
 	inet_ntop(AF_INET6, &v6->laddr, buf[0], sizeof(buf[0]));
 	inet_ntop(AF_INET6, &v6->faddr, buf[1], sizeof(buf[1]));
@@ -248,14 +250,19 @@
 	timersub(&vtw->expire, &now, &delta);
 
 	if (vtw->expire.tv_sec == 0 && vtw->expire.tv_usec == -1) {
-		dbg_printf("%15.15s:%d %15.15s:%d expired\n"
+		dbg_printf("%15.15s:%d %15.15s:%d reclaimed\n"
 		    ,buf[0], ntohs(v6->lport)
 		    ,buf[1], ntohs(v6->fport));
 		if (!(Vflag && vflag))
 			return;
 	} else if (vtw->expire.tv_sec == 0)
 		return;
-	else {
+	else if (timercmp(&delta, &zero, <) && !(Vflag && vflag)) {
+		dbg_printf("%15.15s:%d %15.15s:%d expired\n"
+		    ,buf[0], ntohs(v6->lport)
+		    ,buf[1], ntohs(v6->fport));
+		return;
+	} else {
 		dbg_printf("%15.15s:%d %15.15s:%d expires in %.3fms\n"
 		    ,buf[0], ntohs(v6->lport)
 		    ,buf[1], ntohs(v6->fport)

Reply via email to