CVS commit: src/usr.bin/netstat

2021-03-09 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Wed Mar 10 00:32:16 UTC 2021

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Remove Network ATM soft intr queue reporting, we don't have that in the
kernel anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.100 src/usr.bin/netstat/main.c:1.101
--- src/usr.bin/netstat/main.c:1.100	Thu Apr 23 00:24:50 2020
+++ src/usr.bin/netstat/main.c	Wed Mar 10 00:32:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $	*/
+/*	$NetBSD: main.c,v 1.101 2021/03/10 00:32:15 simonb Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.101 2021/03/10 00:32:15 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,19 +182,17 @@ struct nlist nl[] = {
 	{ "_atintrq1", 0, 0, 0, 0 },
 #define	N_ATINTRQ2	40
 	{ "_atintrq2", 0, 0, 0, 0 },
-#define	N_NATMINTRQ	41
-	{ "_natmintrq", 0, 0, 0, 0 },
-#define	N_PPPOEDISCINQ	42
+#define	N_PPPOEDISCINQ	41
 	{ "_ppoediscinq", 0, 0, 0, 0 },
-#define	N_PPPOEINQ	43
+#define	N_PPPOEINQ	42
 	{ "_ppoeinq", 0, 0, 0, 0 },
-#define	N_HARDCLOCK_TICKS 44
+#define	N_HARDCLOCK_TICKS 43
 	{ "_hardclock_ticks", 0, 0, 0, 0 },
-#define N_PIMSTAT	45
+#define N_PIMSTAT	44
 	{ "_pimstat", 0, 0, 0, 0 },
-#define N_CARPSTAT	46
+#define N_CARPSTAT	45
 	{ "_carpstats", 0, 0, 0, 0 },	/* not available via kvm */
-#define N_PFSYNCSTAT	47
+#define N_PFSYNCSTAT	46
 	{ "_pfsyncstats", 0, 0, 0, 0},  /* not available via kvm */
 	{ "", 0, 0, 0, 0 },
 };
@@ -310,7 +308,6 @@ const struct softintrq {
 	{ "arpintrq", N_ARPINTRQ },
 	{ "atintrq1", N_ATINTRQ1 },
 	{ "atintrq2", N_ATINTRQ2 },
-	{ "natmintrq", N_NATMINTRQ },
 	{ "ppoediscinq", N_PPPOEDISCINQ },
 	{ "ppoeinq", N_PPPOEINQ },
 	{ NULL, -1 },



CVS commit: src/usr.bin/netstat

2021-03-01 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Mar  2 01:02:12 UTC 2021

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Don't show any of the completely and utterly undocumented VTW info if
the feature isn't enabled (by checking net.inet.tcp.vtw.enable).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.10 src/usr.bin/netstat/vtw.c:1.11
--- src/usr.bin/netstat/vtw.c:1.10	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/vtw.c	Tue Mar  2 01:02:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.10 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: vtw.c,v 1.10 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -115,10 +115,28 @@ __RCSID("$NetBSD: vtw.c,v 1.10 2018/05/0
 #include "vtw.h"
 #include "prog_ops.h"
 
+static bool	vtw_enabled(void);
 static void	snarf(const void *, void *, size_t);
 static void	*lookup(const char *);
 static void	process_vtw(const vtw_ctl_t *, void (*)(const vtw_t *));
 
+static bool
+vtw_enabled(void)
+{
+
+	if (use_sysctl) {
+		int enabled;
+		size_t size = sizeof(enabled);
+
+		if (prog_sysctlbyname("net.inet.tcp.vtw.enable",
+		, , NULL, 0) == -1)
+			return true;
+		return enabled ? true : false;
+	} else {
+		return true;
+	}
+}
+
 static void 
 snarf(const void *addr, void *buf, size_t len)
 {
@@ -172,6 +190,11 @@ timebase(struct timeval *tv)
 	void *p;
 	struct bintime timebasebin;
 
+	if (!vtw_enabled()) {
+		memset(tv, 0, sizeof(*tv));
+		return;
+	}
+
 	p = lookup("timebasebin");
 	if (!p)
 		return;
@@ -209,6 +232,9 @@ show_vtw_stats(void)
 	if (!Vflag)
 		return;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("vtw_stats")) == NULL)
 		return;
 	snarf(p, , sizeof(stats));
@@ -248,6 +274,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 	int mem = 0;
 	void *p;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("fat_tcpv4")) == NULL)
 		return;
 	snarf(p, _tcpv4, sizeof(fat_tcpv4));
@@ -350,6 +379,9 @@ show_vtw_v6(void (*print)(const vtw_t *)
 	int mem = 0;
 	void *p;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("fat_tcpv6")) == NULL)
 		return;
 	snarf(p, _tcpv6, sizeof(fat_tcpv6));



CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 07:23:48 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c inet.c inet6.c pfkey.c pfsync.c

Log Message:
netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer.  netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short.  So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.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/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.18 src/usr.bin/netstat/atalk.c:1.19
--- src/usr.bin/netstat/atalk.c:1.18	Thu Apr 23 00:23:31 2020
+++ src/usr.bin/netstat/atalk.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $	*/
+/*	$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -291,7 +291,7 @@ ddp_stats(u_long off, const char *name)
 		size_t size = sizeof(ddpstat);
 
 		if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.14 src/usr.bin/netstat/bpf.c:1.15
--- src/usr.bin/netstat/bpf.c:1.14	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/bpf.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: bpf.c,v 1.15 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -53,7 +53,8 @@ bpf_stats(void)
 	size_t len = sizeof(bpf_s);
 
 	if (use_sysctl) {
-		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
+		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1 &&
+		errno != ENOMEM)
 			err(1, "net.bpf.stats");
 	
 		printf("bpf:\n");

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.112 src/usr.bin/netstat/inet.c:1.113
--- src/usr.bin/netstat/inet.c:1.112	Fri Aug 28 06:34:17 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $	*/
+/*	$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r 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.112 2020/08/28 06:34:17 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,7 +404,7 @@ tcp_stats(u_long off, const char *name)
 		size_t size = sizeof(tcpstat);
 
 		if (prog_sysctlbyname("net.inet.tcp.stats", tcpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -531,7 +531,7 @@ udp_stats(u_long off, const char *name)
 		size_t size = sizeof(udpstat);
 
 		if (prog_sysctlbyname("net.inet.udp.stats", udpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -584,7 +584,7 @@ ip_stats(u_long off, const char *name)
 		size_t size = sizeof(ipstat);
 
 		if (prog_sysctlbyname("net.inet.ip.stats", ipstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -657,7 +657,7 @@ icmp_stats(u_long off, const char *name)
 		size_t size = sizeof(icmpstat);
 
 		if (prog_sysctlbyname("net.inet.icmp.stats", icmpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -713,7 +713,7 @@ igmp_stats(u_long off, const char *name)
 		

CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 06:34:17 UTC 2020

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

Log Message:
netstat: support new packet counters


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.75 -r1.76 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.111 src/usr.bin/netstat/inet.c:1.112
--- src/usr.bin/netstat/inet.c:1.111	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r 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.111 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -633,6 +633,13 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
 	p(IP_STAT_PFILDROP_IN, "\t%" PRIu64 " input packet%s dropped by pfil\n");
 	p(IP_STAT_PFILDROP_OUT, "\t%" PRIu64 " output packet%s dropped by pfil\n");
+	p(IP_STAT_IPSECDROP_IN, "\t%" PRIu64 " input packet%s dropped by IPsec\n");
+	p(IP_STAT_IPSECDROP_OUT, "\t%" PRIu64 " output packet%s dropped by IPsec\n");
+	p(IP_STAT_IFDROP, "\t%" PRIu64 " input packet%s dropped due to interface state\n");
+	p(IP_STAT_TIMXCEED, "\t%" PRIu64 " packet%s dropped due to TTL exceeded\n");
+	p(IP_STAT_IFNOADDR, "\t%" PRIu64 " output packet%s dropped (no IP address)\n");
+	p(IP_STAT_RTREJECT, "\t%" PRIu64 " output packet%s discarded due to reject route\n");
+	p(IP_STAT_BCASTDENIED, "\t%" PRIu64 " output packet%s dropped (broadcast prohibited)\n");
 #undef ps
 #undef p
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.75 src/usr.bin/netstat/inet6.c:1.76
--- src/usr.bin/netstat/inet6.c:1.75	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet6.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r 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.75 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -801,6 +801,13 @@ ip6_stats(u_long off, const char *name)
 	p1(IP6_STAT_FORWARD_CACHEMISS, "\t%llu forward cache miss\n");
 	p(IP6_STAT_PFILDROP_IN, "\t%llu input packet%s dropped by pfil\n");
 	p(IP6_STAT_PFILDROP_OUT, "\t%llu output packet%s dropped by pfil\n");
+	p(IP6_STAT_IPSECDROP_IN, "\t%llu input packet%s dropped by IPsec\n");
+	p(IP6_STAT_IPSECDROP_OUT, "\t%llu output packet%s dropped by IPsec\n");
+	p(IP6_STAT_IFDROP, "\t%llu input packet%s dropped due to interface state\n");
+	p(IP6_STAT_IDROPPED, "\t%llu input packet%s dropped due to no bufs, etc.\n");
+	p(IP6_STAT_TIMXCEED, "\t%llu packet%s dropped due to hop limit exceeded\n");
+	p(IP6_STAT_TOOBIG, "\t%llu packet%s dropped (too big)\n");
+	p(IP6_STAT_RTREJECT, "\t%llu output packet%s discarded due to reject route\n");
 #undef p
 #undef p1
 }



CVS commit: src/usr.bin/netstat

2020-08-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug  6 07:38:54 UTC 2020

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

Log Message:
add missing {IP,IP6}_STAT_NOIPSEC to netstat.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.74 -r1.75 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.110 src/usr.bin/netstat/inet.c:1.111
--- src/usr.bin/netstat/inet.c:1.110	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/inet.c	Thu Aug  6 07:38:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.110 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara 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.110 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $");
 #endif
 #endif /* not lint */
 
@@ -622,6 +622,7 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_CANTFORWARD, "\t%" PRIu64 " packet%s not forwardable\n");
 	p(IP_STAT_REDIRECTSENT, "\t%" PRIu64 " redirect%s sent\n");
 	p(IP_STAT_NOGIF, "\t%" PRIu64 " packet%s no matching gif found\n");
+	p(IP_STAT_NOIPSEC, "\t%" PRIu64 " packet%s no matching ipsecif found\n");
 	p(IP_STAT_LOCALOUT, "\t%" PRIu64 " packet%s sent from this host\n");
 	p(IP_STAT_RAWOUT, "\t%" PRIu64 " packet%s sent with fabricated ip header\n");
 	p(IP_STAT_ODROPPED, "\t%" PRIu64 " output packet%s dropped due to no bufs, etc.\n");

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.74 src/usr.bin/netstat/inet6.c:1.75
--- src/usr.bin/netstat/inet6.c:1.74	Thu Apr 23 00:24:16 2020
+++ src/usr.bin/netstat/inet6.c	Thu Aug  6 07:38:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $	*/
+/*	$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara 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.74 2020/04/23 00:24:16 joerg Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $");
 #endif
 #endif /* not lint */
 
@@ -724,6 +724,7 @@ ip6_stats(u_long off, const char *name)
 	p(IP6_STAT_EXTHDRTOOLONG,
 	"\t%llu packet%s whose headers are not continuous\n");
 	p(IP6_STAT_NOGIF, "\t%llu tunneling packet%s that can't find gif\n");
+	p(IP6_STAT_NOIPSEC, "\t%llu tunneling packet%s that can't find ipsecif\n");
 	p(IP6_STAT_TOOMANYHDR,
 	"\t%llu packet%s discarded due to too many headers\n");
 



CVS commit: src/usr.bin/netstat

2020-07-20 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Jul 21 04:58:44 UTC 2020

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
netstat.1: add various xrefs present in the body to "See Also"


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.73 src/usr.bin/netstat/netstat.1:1.74
--- src/usr.bin/netstat/netstat.1:1.73	Thu May 12 03:44:11 2016
+++ src/usr.bin/netstat/netstat.1	Tue Jul 21 04:58:43 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.73 2016/05/12 03:44:11 ozaki-r Exp $
+.\"	$NetBSD: netstat.1,v 1.74 2020/07/21 04:58:43 gutteridge Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\"
-.Dd May 12, 2016
+.Dd July 21, 2020
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -432,12 +432,17 @@ And the fifth character shows the header
 .Xr sockstat 1 ,
 .Xr vmstat 1 ,
 .Xr inet 3 ,
+.Xr kvm 3 ,
+.Xr kvm_openfiles 3 ,
+.Xr sysctl 3 ,
 .Xr bpf 4 ,
+.Xr route 4 ,
 .Xr hosts 5 ,
 .Xr networks 5 ,
 .Xr protocols 5 ,
 .Xr services 5 ,
 .Xr iostat 8 ,
+.Xr route 8 ,
 .Xr trpt 8
 .Sh HISTORY
 The



CVS commit: src/usr.bin/netstat

2020-05-27 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 27 05:59:16 UTC 2020

Modified Files:
src/usr.bin/netstat: route.c

Log Message:
Update sysctl key in netstat(1)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/route.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/route.c
diff -u src/usr.bin/netstat/route.c:1.85 src/usr.bin/netstat/route.c:1.86
--- src/usr.bin/netstat/route.c:1.85	Mon Apr  4 07:37:08 2016
+++ src/usr.bin/netstat/route.c	Wed May 27 05:59:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.86 2020/05/27 05:59:16 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c	8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $");
+__RCSID("$NetBSD: route.c,v 1.86 2020/05/27 05:59:16 yamaguchi Exp $");
 #endif
 #endif /* not lint */
 
@@ -303,7 +303,7 @@ rt_stats(u_long off)
 	if (use_sysctl) {
 		size_t rtsize = sizeof(rtstats);
 
-		if (sysctlbyname("net.route.stats", , ,
+		if (sysctlbyname("net.rtable.stats", , ,
 		NULL, 0) == -1)
 			err(1, "rt_stats: sysctl");
 	} else 	if (off == 0) {



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:50 UTC 2020

Modified Files:
src/usr.bin/netstat: main.c netstat.h

Log Message:
Avoid common symbol definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/netstat/netstat.h

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/main.c
diff -u src/usr.bin/netstat/main.c:1.99 src/usr.bin/netstat/main.c:1.100
--- src/usr.bin/netstat/main.c:1.99	Thu Jul 14 20:13:10 2016
+++ src/usr.bin/netstat/main.c	Thu Apr 23 00:24:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,6 +67,38 @@ __RCSID("$NetBSD: main.c,v 1.99 2016/07/
 #include "rtutil.h"
 #include "prog_ops.h"
 
+int	Aflag;
+int	aflag;
+int	Bflag;
+int	bflag;
+int	dflag;
+#ifndef SMALL
+int	gflag;
+#endif
+int	hflag;
+int	iflag;
+int	Lflag;
+int	lflag;
+int	mflag;
+int	numeric_addr;
+int	numeric_port;
+int	nflag;
+int	Pflag;
+int	pflag;
+int	qflag;
+int	rflag;
+int	sflag;
+int	tagflag;
+int	tflag;
+int	Vflag;
+int	vflag;
+
+char	*interface;
+
+int	af;
+int	use_sysctl;
+int	force_sysctl;
+
 struct nlist nl[] = {
 #define	N_MBSTAT	0
 	{ "_mbstat", 0, 0, 0, 0 },

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.51 src/usr.bin/netstat/netstat.h:1.52
--- src/usr.bin/netstat/netstat.h:1.51	Thu Nov  6 21:30:09 2014
+++ src/usr.bin/netstat/netstat.h	Thu Apr 23 00:24:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.51 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: netstat.h,v 1.52 2020/04/23 00:24:50 joerg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -34,37 +34,37 @@
 #include 
 #include 
 
-int	Aflag;		/* show addresses of protocol control block */
-int	aflag;		/* show all sockets (including servers) */
-int	Bflag;		/* show Berkeley Packet Filter information */
-int	bflag;		/* show i/f byte stats */
-int	dflag;		/* show i/f dropped packets */
+extern int	Aflag;		/* show addresses of protocol control block */
+extern int	aflag;		/* show all sockets (including servers) */
+extern int	Bflag;		/* show Berkeley Packet Filter information */
+extern int	bflag;		/* show i/f byte stats */
+extern int	dflag;		/* show i/f dropped packets */
 #ifndef SMALL
-int	gflag;		/* show group (multicast) routing or stats */
+extern int	gflag;		/* show group (multicast) routing or stats */
 #endif
-int	hflag;		/* humanize byte counts */
-int	iflag;		/* show interfaces */
-int	Lflag;		/* don't show LLINFO entries */
-int	lflag;		/* show routing table with use and ref */
-int	mflag;		/* show memory stats */
-int	numeric_addr;	/* show addresses numerically */
-int	numeric_port;	/* show ports numerically */
-int	nflag;		/* same as above, for show.c compat */
-int	Pflag;		/* dump a PCB */
-int	pflag;		/* show given protocol */
-int	qflag;		/* show softintrq */
-int	rflag;		/* show routing tables (or routing stats) */
-int	sflag;		/* show protocol statistics */
-int	tagflag;	/* show route tags */
-int	tflag;		/* show i/f watchdog timers */
-int	Vflag;		/* show Vestigial TIME_WAIT (VTW) information */
-int	vflag;		/* verbose route information or don't truncate names */
-
-char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
-
-int	af;		/* address family */
-int	use_sysctl;	/* use sysctl instead of kmem */
-int	force_sysctl;	/* force use of sysctl (or exit) - for testing */
+extern int	hflag;		/* humanize byte counts */
+extern int	iflag;		/* show interfaces */
+extern int	Lflag;		/* don't show LLINFO entries */
+extern int	lflag;		/* show routing table with use and ref */
+extern int	mflag;		/* show memory stats */
+extern int	numeric_addr;	/* show addresses numerically */
+extern int	numeric_port;	/* show ports numerically */
+extern int	nflag;		/* same as above, for show.c compat */
+extern int	Pflag;		/* dump a PCB */
+extern int	pflag;		/* show given protocol */
+extern int	qflag;		/* show softintrq */
+extern int	rflag;		/* show routing tables (or routing stats) */
+extern int	sflag;		/* show protocol statistics */
+extern int	tagflag;	/* show route tags */
+extern int	tflag;		/* show i/f watchdog timers */
+extern int	Vflag;		/* show Vestigial TIME_WAIT (VTW) information */
+extern int	vflag;		/* verbose route information or don't truncate names */
+
+extern char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
+
+extern int	af;		/* address family */
+extern int	use_sysctl;	/* use sysctl instead of kmem 

CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:23:31 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c

Log Message:
Avoid global scope for variables only used locally


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/atalk.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/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.17 src/usr.bin/netstat/atalk.c:1.18
--- src/usr.bin/netstat/atalk.c:1.17	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/atalk.c	Thu Apr 23 00:23:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -63,9 +63,6 @@ __RCSID("$NetBSD: atalk.c,v 1.17 2019/08
 #include "netstat.h"
 #include "prog_ops.h"
 
-struct ddpcbddpcb;
-struct socket   sockb;
-
 static int first = 1;
 
 /*
@@ -230,6 +227,8 @@ atalk_print2(const struct sockaddr *sa, 
 void
 atalkprotopr(u_long off, const char *name)
 {
+	struct ddpcb ddpcb;
+	struct socket sockb;
 	struct ddpcb *next;
 	struct ddpcb *initial;
 	int width = 22;



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:16 UTC 2020

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

Log Message:
sockb is only used locally, so move it into the function


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 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/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.73 src/usr.bin/netstat/inet6.c:1.74
--- src/usr.bin/netstat/inet6.c:1.73	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/inet6.c	Thu Apr 23 00:24:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.73 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg 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.73 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -147,7 +147,6 @@ struct	tcp6cb tcp6cb;
 #else
 struct	tcpcb tcpcb;
 #endif
-struct	socket sockb;
 
 char	*inet6name(const struct in6_addr *);
 void	inet6print(const struct in6_addr *, int, const char *);
@@ -283,8 +282,9 @@ print_vtw_v6(const vtw_t *vtw)
 
 
 static struct kinfo_pcb *
-getpcblist_kmem(u_long off, const char *name, size_t *len) {
-
+getpcblist_kmem(u_long off, const char *name, size_t *len)
+{
+	struct socket sockb;
 	struct inpcbtable table;
 	struct inpcb_hdr *next, *prev;
 	int istcp = strcmp(name, "tcp6") == 0;



CVS commit: src/usr.bin/netstat

2020-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr  3 16:42:00 UTC 2020

Modified Files:
src/usr.bin/netstat: Makefile netstat_hostops.c netstat_rumpops.c
Removed Files:
src/usr.bin/netstat: prog_ops.h

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c
cvs rdiff -u -r1.4 -r0 src/usr.bin/netstat/prog_ops.h

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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.47 src/usr.bin/netstat/Makefile:1.48
--- src/usr.bin/netstat/Makefile:1.47	Sun Oct 13 03:28:16 2019
+++ src/usr.bin/netstat/Makefile	Fri Apr  3 12:41:59 2020
@@ -1,10 +1,15 @@
-#	$NetBSD: Makefile,v 1.47 2019/10/13 07:28:16 mrg Exp $
+#	$NetBSD: Makefile,v 1.48 2020/04/03 16:41:59 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
 
 USE_FORT?= yes	# setgid
 
+ROUTE=${NETBSDSRCDIR}/sbin/route
+PF=${NETBSDSRCDIR}/sys/dist/pf
+
+.PATH: ${ROUTE} 
+
 RUMPPRG=netstat
 SRCS=	atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c \
 	main.c mbuf.c mroute.c mroute6.c pfkey.c pfsync.c route.c \
@@ -14,10 +19,8 @@ BINMODE=2555
 LDADD=	-lutil -lkvm
 DPADD=	${LIBUTIL} ${LIBKVM}
 CPPFLAGS+= -DIPSEC -I${.CURDIR}
-CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
-CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
-
-.PATH:  ${.CURDIR}/../../sbin/route
+CPPFLAGS+= -I${PF}
+CPPFLAGS+= -I${ROUTE}
 
 .if (${MKRUMP} != "no")
 .PATH:  ${.CURDIR}/../../lib/libc/gen

Index: src/usr.bin/netstat/netstat_hostops.c
diff -u src/usr.bin/netstat/netstat_hostops.c:1.3 src/usr.bin/netstat/netstat_hostops.c:1.4
--- src/usr.bin/netstat/netstat_hostops.c:1.3	Fri Apr  3 12:20:51 2020
+++ src/usr.bin/netstat/netstat_hostops.c	Fri Apr  3 12:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $	*/
+/*	$NetBSD: netstat_hostops.c,v 1.4 2020/04/03 16:41:59 christos Exp $	*/
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,9 +26,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include 
-#ifndef lint
-__RCSID("$NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $");
-#endif /* !lint */
-
-#include "../../sbin/route/route_hostops.c"
+#include "route_hostops.c"
Index: src/usr.bin/netstat/netstat_rumpops.c
diff -u src/usr.bin/netstat/netstat_rumpops.c:1.3 src/usr.bin/netstat/netstat_rumpops.c:1.4
--- src/usr.bin/netstat/netstat_rumpops.c:1.3	Fri Apr  3 12:20:51 2020
+++ src/usr.bin/netstat/netstat_rumpops.c	Fri Apr  3 12:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat_rumpops.c,v 1.3 2020/04/03 16:20:51 martin Exp $	*/
+/*	$NetBSD: netstat_rumpops.c,v 1.4 2020/04/03 16:41:59 christos Exp $	*/
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,4 +26,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "../../sbin/route/route_rumpops.c"
+#include "route_rumpops.c"



CVS commit: src/usr.bin/netstat

2020-02-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb  2 03:41:12 UTC 2020

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Update for per-cpu interface statistics.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.95 src/usr.bin/netstat/if.c:1.96
--- src/usr.bin/netstat/if.c:1.95	Wed Jul 11 07:46:20 2018
+++ src/usr.bin/netstat/if.c	Sun Feb  2 03:41:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $");
 #endif
 #endif /* not lint */
 
@@ -289,9 +289,34 @@ union ifaddr_u {
 };
 
 static void
+ifnet_to_ifdata_kvm(const struct ifnet * const ifp, struct if_data * const ifd)
+{
+
+	/*
+	 * Interface statistics are no longer kept in struct ifnet,
+	 * and thus an if_data is no longer embedded in struct ifnet.
+	 * We cannot read stats via kvm without chasing per-cpu data,
+	 * and maybe someday we could do that.  But for now, this is
+	 * what we have.
+	 *
+	 * Just copy the fields that do exist.
+	 */
+	memset(ifd, 0, sizeof(*ifd));
+	ifd->ifi_type = ifp->if_type;
+	ifd->ifi_addrlen = ifp->if_addrlen;
+	ifd->ifi_hdrlen = ifp->if_hdrlen;
+	ifd->ifi_link_state = ifp->if_link_state;
+	ifd->ifi_mtu = ifp->if_mtu;
+	ifd->ifi_metric = ifp->if_metric;
+	ifd->ifi_baudrate = ifp->if_baudrate;
+	ifd->ifi_lastchange = ifp->if_lastchange;
+}
+
+static void
 intpr_kvm(u_long ifnetaddr, void (*pfunc)(const char *))
 {
 	struct ifnet ifnet;
+	struct if_data ifd;
 	union ifaddr_u ifaddr;
 	u_long ifaddraddr;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
@@ -358,8 +383,9 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
+			ifnet_to_ifdata_kvm(, );
 			print_addr(ifnet.if_index, sa, (void *),
-			_data, );
+			, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -787,6 +813,7 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	sigset_t emptyset;
 	sigset_t noalrm;
 	struct ifnet ifnet;
+	struct if_data ifd;
 	u_long firstifnet;
 	struct iftot *ip, *total;
 	unsigned line;
@@ -906,53 +933,54 @@ loop:
 			off = 0;
 			continue;
 		}
+		ifnet_to_ifdata_kvm(, );
 		if (ip == interesting) {
 			if (bflag) {
 char humbuf[HUMBUF_SIZE];
 
 if (hflag && humanize_number(humbuf,
 sizeof(humbuf),
-ifnet.if_ibytes - ip->ift_ib, "",
+ifd.ifi_ibytes - ip->ift_ib, "",
 HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
 	printf("%10s %8.8s ", humbuf, " ");
 else
 	printf("%10llu %8.8s ", 
 	(unsigned long long)
-	(ifnet.if_ibytes-ip->ift_ib), " ");
+	(ifd.ifi_ibytes-ip->ift_ib), " ");
 
 if (hflag && humanize_number(humbuf,
 sizeof(humbuf),
-ifnet.if_obytes - ip->ift_ob, "",
+ifd.ifi_obytes - ip->ift_ob, "",
 HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
 	printf("%10s %5.5s", humbuf, " ");
 else
 	printf("%10llu %5.5s", 
 	(unsigned long long)
-	(ifnet.if_obytes-ip->ift_ob), " ");
+	(ifd.ifi_obytes-ip->ift_ob), " ");
 			} else {
 printf("%8llu %5llu %8llu %5llu %5llu",
 (unsigned long long)
-	(ifnet.if_ipackets - ip->ift_ip),
+	(ifd.ifi_ipackets - ip->ift_ip),
 (unsigned long long)
-	(ifnet.if_ierrors - ip->ift_ie),
+	(ifd.ifi_ierrors - ip->ift_ie),
 (unsigned long long)
-	(ifnet.if_opackets - ip->ift_op),
+	(ifd.ifi_opackets - ip->ift_op),
 (unsigned long long)
-	(ifnet.if_oerrors - ip->ift_oe),
+	(ifd.ifi_oerrors - ip->ift_oe),
 (unsigned long long)
-	(ifnet.if_collisions - ip->ift_co));
+	(ifd.ifi_collisions - ip->ift_co));
 			}
 			if (dflag)
 printf(" %5" PRIu64,
 	ifnet.if_snd.ifq_drops - ip->ift_dr);
 		}
-		ip->ift_ip = ifnet.if_ipackets;
-		ip->ift_ib = ifnet.if_ibytes;
-		ip->ift_ie = ifnet.if_ierrors;
-		ip->ift_op = ifnet.if_opackets;
-		ip->ift_ob = ifnet.if_obytes;
-		ip->ift_oe = ifnet.if_oerrors;
-		ip->ift_co = ifnet.if_collisions;
+		ip->ift_ip = ifd.ifi_ipackets;
+		ip->ift_ib = ifd.ifi_ibytes;
+		ip->ift_ie = ifd.ifi_ierrors;
+		ip->ift_op = ifd.ifi_opackets;
+		ip->ift_ob = ifd.ifi_obytes;
+		ip->ift_oe = ifd.ifi_oerrors;
+		ip->ift_co = ifd.ifi_collisions;
 		ip->ift_dr = ifnet.if_snd.ifq_drops;
 		sum->ift_ip += ip->ift_ip;
 		sum->ift_ib += ip->ift_ib;



CVS commit: src/usr.bin/netstat

2018-07-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 11 07:46:21 UTC 2018

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
 Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.94 src/usr.bin/netstat/if.c:1.95
--- src/usr.bin/netstat/if.c:1.94	Thu Feb 23 07:57:10 2017
+++ src/usr.bin/netstat/if.c	Wed Jul 11 07:46:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.94 2017/02/23 07:57:10 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.94 2017/02/23 07:57:10 ozaki-r Exp $");
+__RCSID("$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -152,14 +152,17 @@ intpr_header(void)
 			   "Ibytes", "Obytes");
 		} else {
 			printf("%-5.5s %-5.5s %-13.13s %-17.17s "
-			   "%8.8s %5.5s %8.8s %5.5s %5.5s",
-			   "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
-			   "Opkts", "Oerrs", "Colls");
+			"%8.8s %5.5s",
+			"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+			if (dflag)
+printf(" %6.6s", "Idrops");
+			printf(" %8.8s %5.5s %5.5s",
+			"Opkts", "Oerrs", "Colls");
 		}
+		if (dflag)
+			printf(" %6.6s", "Odrops");
 		if (tflag)
 			printf(" %4.4s", "Time");
-		if (dflag)
-			printf(" %5.5s", "Drops");
 		putchar('\n');
 	}
 }
@@ -617,19 +620,21 @@ print_addr(const int ifindex, struct soc
 		else
 			printf("%10llu", (unsigned long long)ifd->ifi_obytes);
 	} else {
-		printf("%8llu %5llu %8llu %5llu %5llu",
+		printf("%8llu %5llu",
 			(unsigned long long)ifd->ifi_ipackets,
-			(unsigned long long)ifd->ifi_ierrors,
+			(unsigned long long)ifd->ifi_ierrors);
+		if (dflag)
+			printf(" %6" PRIu64, ifd->ifi_iqdrops);
+		printf(" %8llu %5llu %5llu",
 			(unsigned long long)ifd->ifi_opackets,
 			(unsigned long long)ifd->ifi_oerrors,
 			(unsigned long long)ifd->ifi_collisions);
 	}
+	if (dflag)
+		printf(" %6lld", ifnet ?
+		(unsigned long long)ifnet->if_snd.ifq_drops : 0);
 	if (tflag)
 		printf(" %4d", ifnet ? ifnet->if_timer : 0);
-	if (dflag)
-		printf(" %5lld", ifnet ?
-		(unsigned long long)ifnet->if_snd.ifq_drops :
-		ifd->ifi_iqdrops);
 	putchar('\n');
 }
 



CVS commit: src/usr.bin/netstat

2018-06-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Jun 26 09:50:42 UTC 2018

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
 Fix a bug that BPF_D_OUT isn't printed correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/bpf.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/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.12 src/usr.bin/netstat/bpf.c:1.13
--- src/usr.bin/netstat/bpf.c:1.12	Tue Jun 26 06:48:03 2018
+++ src/usr.bin/netstat/bpf.c	Tue Jun 26 09:50:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.12 2018/06/26 06:48:03 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.13 2018/06/26 09:50:42 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -148,7 +148,7 @@ bpf_dump(const char *bpfif)
 			printf("%c", BPFEXT(bde_promisc) ? 'P' : '-');
 			printf("%c", BPFEXT(bde_immediate) ? 'R' : '-');
 			printf("%c", (BPFEXT(bde_direction) == BPF_D_IN) ? '-'
-			: (BPFEXT(bde_direction) == BPF_D_IN) ? 'O' : 'S');
+			: (BPFEXT(bde_direction) == BPF_D_OUT) ? 'O' : 'S');
 			printf("%c", BPFEXT(bde_hdrcmplt) ? 'H' : '-');
 			printf("  %-8d ", BPFEXT(bde_bufsize));
 



CVS commit: src/usr.bin/netstat

2017-12-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Dec 19 17:05:15 UTC 2017

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

Log Message:
Add names of a few more ICMPv6 messages, from RFC6275 (Mobile IPv6)
and RFC4286 (Multicast Router Discovery.) and as shown in the IANA
parameters page available at:
  https://www.ietf.org/assignments/icmpv6-parameters/icmpv6-parameters.txt

Also make the array be explicitly 256 entries long, one for each possible
code, which will detect attempts to insert names without deleting the
place holder (and mean a good solid NULL de-ref if too many place holders
are deleted, rather than just random results.)


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 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/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.69 src/usr.bin/netstat/inet6.c:1.70
--- src/usr.bin/netstat/inet6.c:1.69	Sat Dec 17 09:12:22 2016
+++ src/usr.bin/netstat/inet6.c	Tue Dec 19 17:05:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $	*/
+/*	$NetBSD: inet6.c,v 1.70 2017/12/19 17:05:15 kre 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.69 2016/12/17 09:12:22 mlelstv Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.70 2017/12/19 17:05:15 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -860,7 +860,7 @@ ip6_ifstats(const char *ifname)
 #undef p_5
 }
 
-static	const char *icmp6names[] = {
+static	const char *icmp6names[256] = {
 	"#0",
 	"unreach",
 	"packet too big",
@@ -1004,17 +1004,17 @@ static	const char *icmp6names[] = {
 	"node information reply",
 	"#141",
 	"#142",
-	"#143",
-	"#144",
-	"#145",
-	"#146",
-	"#147",
+	"multicast listener report (v2)",
+	"home agent discovery request",
+	"home agent discovery reply",
+	"mobile prefix solicitation",
+	"mobile prefix advertisement",
 	"#148",
 	"#149",	
 	"#150",
-	"#151",
-	"#152",
-	"#153",
+	"multicast router advertisement",
+	"multicast router solicitation",
+	"multicast router termination",
 	"#154",
 	"#155",
 	"#156",



CVS commit: src/usr.bin/netstat

2017-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct 10 19:31:10 UTC 2017

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
use librumpres


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/netstat/Makefile

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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.44 src/usr.bin/netstat/Makefile:1.45
--- src/usr.bin/netstat/Makefile:1.44	Fri Dec 23 05:19:57 2016
+++ src/usr.bin/netstat/Makefile	Tue Oct 10 15:31:10 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.44 2016/12/23 10:19:57 mrg Exp $
+#	$NetBSD: Makefile,v 1.45 2017/10/10 19:31:10 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
@@ -17,12 +17,16 @@ CPPFLAGS+= -DIPSEC -I${.CURDIR}
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
 CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
 
-.PATH:  ${.CURDIR}/../../lib/libc/gen
-.PATH:  ${.CURDIR}/../../lib/libc/net
 .PATH:  ${.CURDIR}/../../sbin/route
-CPPFLAGS+= -DRUMP_ACTION
+
+.if (${MKRUMP} != "no")
+.PATH:  ${.CURDIR}/../../lib/libc/gen
 RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c
-RUMPSRCS+= if_indextoname.c getifaddrs.c getnameinfo.c
+LDADD.rump+=	-lrumpres
+DPADD.add+=	${LIBRUMPRES}
+CPPFLAGS+=  -DRUMP_ACTION
+.endif
+
 
 .if (${USE_INET6} != "no")
 CPPFLAGS+= -DINET6



CVS commit: src/usr.bin/netstat

2017-06-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jun 29 07:15:27 UTC 2017

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
Tweak outputs of netstat -s for IPsec

- Get rid of "Fast"
- Use ipsec and ipsec6 for titles to clarify protocol
- Indent outputs of sub protocols

Original outputs were organized like this:

(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:
(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:

New outputs are organized like this:

ipsec:
ah:
esp:
ipip:
ipcomp:
ipsec6:
ah:
esp:
ipip:
ipcomp:


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/netstat/fast_ipsec.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/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.21 src/usr.bin/netstat/fast_ipsec.c:1.22
--- src/usr.bin/netstat/fast_ipsec.c:1.21	Thu Apr 13 16:38:32 2017
+++ src/usr.bin/netstat/fast_ipsec.c	Thu Jun 29 07:15:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.21 2017/04/13 16:38:32 christos Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include 
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID("$NetBSD: fast_ipsec.c,v 1.21 2017/04/13 16:38:32 christos Exp $");
+__RCSID("$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $");
 #endif
 #endif /* not lint*/
 
@@ -145,7 +145,7 @@ fast_ipsec_stats(u_long off, const char 
 	if (status < 0 && errno != ENOMEM)
 		err(1, "net.inet.ipip.ipip_stats");
 
-	printf("(Fast) IPsec:\n");
+	printf("%s:\n", name);
 
 #define	STAT(x,fmt)	if ((x) || sflag <= 1) printf("\t%"PRIu64" " fmt "\n", x)
 	if (ipsecstats[IPSEC_STAT_IN_POLVIO]+ipsecstats[IPSEC_STAT_OUT_POLVIO])
@@ -160,10 +160,9 @@ fast_ipsec_stats(u_long off, const char 
 	STAT(ipsecstats[IPSEC_STAT_SPDCACHELOOKUP], "SPD cache lookups");
 	STAT(ipsecstats[IPSEC_STAT_SPDCACHEMISS], "SPD cache misses");
 #undef STAT
-	printf("\n");
 	
-	printf("IPsec ah:\n");
-#define	AHSTAT(x,fmt)	if ((x) || sflag <= 1) printf("\t%"PRIu64" ah " fmt "\n", x)
+	printf("\tah:\n");
+#define	AHSTAT(x,fmt)	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ah " fmt "\n", x)
 	AHSTAT(ahstats[AH_STAT_INPUT],   "input packets processed");
 	AHSTAT(ahstats[AH_STAT_OUTPUT],  "output packets processed");
 	AHSTAT(ahstats[AH_STAT_HDROPS],  "headers too short");
@@ -192,10 +191,9 @@ fast_ipsec_stats(u_long off, const char 
 	AHSTAT(ahstats[AH_STAT_IBYTES], "bytes received");
 	AHSTAT(ahstats[AH_STAT_OBYTES], "bytes transmitted");
 #undef AHSTAT
-	printf("\n");
 
-	printf("IPsec esp:\n");
-#define	ESPSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t%"PRIu64" esp " fmt "\n", x)
+	printf("\tesp:\n");
+#define	ESPSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t\t%"PRIu64" esp " fmt "\n", x)
 	ESPSTAT(espstats[ESP_STAT_INPUT],"input packets processed");
 	ESPSTAT(espstats[ESP_STAT_OUTPUT],"output packets processed");
 	ESPSTAT(espstats[ESP_STAT_HDROPS],"headers too short");
@@ -224,10 +222,10 @@ fast_ipsec_stats(u_long off, const char 
 	ESPSTAT(espstats[ESP_STAT_IBYTES], "bytes received");
 	ESPSTAT(espstats[ESP_STAT_OBYTES], "bytes transmitted");
 #undef ESPSTAT
-	printf("IPsec ipip:\n");
+	printf("\tipip:\n");
 
 #define	IPIPSTAT(x,fmt) \
-	if ((x) || sflag <= 1) printf("\t%"PRIu64" ipip " fmt "\n", x)
+	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipip " fmt "\n", x)
 	IPIPSTAT(ipips[IPIP_STAT_IPACKETS],"total input packets");
 	IPIPSTAT(ipips[IPIP_STAT_OPACKETS],"total output packets");
 	IPIPSTAT(ipips[IPIP_STAT_HDROPS],"packets too short for header length");
@@ -240,9 +238,9 @@ fast_ipsec_stats(u_long off, const char 
 	IPIPSTAT(ipips[IPIP_STAT_OBYTES],"output bytes processed");
 #undef IPIPSTAT
 
-	printf("IPsec ipcomp:\n");
+	printf("\tipcomp:\n");
 #define	IPCOMP(x,fmt) \
-	if ((x) || sflag <= 1) printf("\t%"PRIu64" ipcomp " fmt "\n", x)
+	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipcomp " fmt "\n", x)
 
 	IPCOMP(ipcs[IPCOMP_STAT_HDROPS],"packets too short for header length");
 	IPCOMP(ipcs[IPCOMP_STAT_NOPF],	"protocol family not supported");
@@ -260,7 +258,7 @@ fast_ipsec_stats(u_long off, const char 
 	IPCOMP(ipcs[IPCOMP_STAT_PDROPS],"packets blocked due to policy");
 	IPCOMP(ipcs[IPCOMP_STAT_CRYPTO],"failed crypto requests");
 
-	printf("\tIPcomp histogram:\n");
+	printf("\tipcomp histogram:\n");
 	for (i = 0; i < IPCOMP_ALG_MAX; i++)
 		if (ipcs[IPCOMP_STAT_HIST + i])
 			printf("\t\tIPcomp packets with %s: %"PRIu64"\n"



CVS commit: src/usr.bin/netstat

2017-01-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jan 22 04:52:04 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.92 src/usr.bin/netstat/if.c:1.93
--- src/usr.bin/netstat/if.c:1.92	Sun Jan 22 04:26:31 2017
+++ src/usr.bin/netstat/if.c	Sun Jan 22 04:52:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.93 2017/01/22 04:52:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.93 2017/01/22 04:52:04 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -169,7 +169,9 @@ intpr_sysctl(void)
 {
 	struct if_msghdr *ifm;
 	int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
-	char *buf = NULL, *next, *lim, *cp;
+	static char *buf = NULL;
+	static size_t olen;
+	char *next, *lim, *cp;
 	struct rt_msghdr *rtm;
 	struct ifa_msghdr *ifam;
 	struct if_data *ifd = NULL;
@@ -183,8 +185,12 @@ intpr_sysctl(void)
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
-	if ((buf = malloc(len)) == NULL)
-		err(1, NULL);
+	if (len > olen) {
+		free(buf);
+		if ((buf = malloc(len)) == NULL)
+			err(1, NULL);
+		olen = len;
+	}
 	if (prog_sysctl(mib, 6, buf, , NULL, 0) == -1)
 		err(1, "sysctl");
 
@@ -269,7 +275,6 @@ intpr_sysctl(void)
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
-	free(buf);
 }
 
 union ifaddr_u {
@@ -1058,14 +1063,20 @@ fetchifs(void)
 	struct if_data *ifd = NULL;
 	struct sockaddr *sa, *rti_info[RTAX_MAX];
 	struct sockaddr_dl *sdl;
-	char *buf, *next, *lim;
+	static char *buf = NULL;
+	static size_t olen;
+	char *next, *lim;
 	char name[IFNAMSIZ];
 	size_t len;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
-	if ((buf = malloc(len)) == NULL)
-		err(1, NULL);
+	if (len > olen) {
+		free(buf);
+		if ((buf = malloc(len)) == NULL)
+			err(1, NULL);
+		olen = len;
+	}
 	if (prog_sysctl(mib, 6, buf, , NULL, 0) == -1)
 		err(1, "sysctl");
 
@@ -1127,5 +1138,4 @@ fetchifs(void)
 		ip_cur.ift_co = ifd->ifi_collisions;
 		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
-	free(buf);
 }



CVS commit: src/usr.bin/netstat

2017-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 22 04:26:31 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
sprinkle free


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.91 src/usr.bin/netstat/if.c:1.92
--- src/usr.bin/netstat/if.c:1.91	Tue Jan 10 20:25:05 2017
+++ src/usr.bin/netstat/if.c	Sat Jan 21 23:26:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $");
+__RCSID("$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -269,6 +269,7 @@ intpr_sysctl(void)
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
+	free(buf);
 }
 
 union ifaddr_u {
@@ -1126,4 +1127,5 @@ fetchifs(void)
 		ip_cur.ift_co = ifd->ifi_collisions;
 		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
+	free(buf);
 }



CVS commit: src/usr.bin/netstat

2017-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 13 04:22:51 UTC 2017

Modified Files:
src/usr.bin/netstat: unix.c

Log Message:
use _KMEMUSER for 


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/unix.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/unix.c
diff -u src/usr.bin/netstat/unix.c:1.34 src/usr.bin/netstat/unix.c:1.35
--- src/usr.bin/netstat/unix.c:1.34	Tue Mar 20 16:34:58 2012
+++ src/usr.bin/netstat/unix.c	Thu Jan 12 23:22:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix.c,v 1.34 2012/03/20 20:34:58 matt Exp $	*/
+/*	$NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)unix.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: unix.c,v 1.34 2012/03/20 20:34:58 matt Exp $");
+__RCSID("$NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -52,9 +52,9 @@ __RCSID("$NetBSD: unix.c,v 1.34 2012/03/
 #include 
 #include 
 #include 
-#define _KERNEL
+#define _KMEMUSER
 #include 
-#undef _KERNEL
+#undef _KMEMUSER
 
 #include 
 



CVS commit: src/usr.bin/netstat

2017-01-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jan 11 01:25:05 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.90 src/usr.bin/netstat/if.c:1.91
--- src/usr.bin/netstat/if.c:1.90	Thu Nov 24 00:05:13 2016
+++ src/usr.bin/netstat/if.c	Wed Jan 11 01:25:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $	*/
+/*	$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $");
+__RCSID("$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,7 +84,7 @@ struct	iftot {
 };
 
 static void set_lines(void);
-static void print_addr(const char *, struct sockaddr *, struct sockaddr **,
+static void print_addr(const int, struct sockaddr *, struct sockaddr **,
 struct if_data *, struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
 
@@ -179,6 +179,7 @@ intpr_sysctl(void)
 	size_t len;
 	int did = 1, rtax = 0, n;
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	int ifindex = 0;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
@@ -216,6 +217,8 @@ intpr_sysctl(void)
 			if (interface != 0 && strcmp(name, interface) != 0)
 continue;
 
+			ifindex = sdl->sdl_index;
+
 			/* mark inactive interfaces with a '*' */
 			cp = strchr(name, '\0');
 			if ((ifm->ifm_flags & IFF_UP) == 0)
@@ -264,7 +267,7 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		print_addr(name, rti_info[rtax], rti_info, ifd, NULL);
+		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
 }
 
@@ -346,8 +349,8 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
-			print_addr(name, sa, (void *), _data,
-			);
+			print_addr(ifnet.if_index, sa, (void *),
+			_data, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -355,16 +358,12 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
-mc_print(const char *ifname, const size_t ias, const char *oid, int *mcast_oids,
+mc_print(const int ifindex, const size_t ias, const char *oid, int *mcast_oids,
 void (*pr)(const void *))
 {
 	uint8_t *mcast_addrs, *p;
 	const size_t incr = 2 * ias + sizeof(uint32_t);
 	size_t len;
-	int ifindex;
-
-	if ((ifindex = if_nametoindex(ifname)) == 0)
-		warn("Interface %s not found", ifname);
 
 	if (mcast_oids[0] == 0) {
 		size_t oidlen = 4;
@@ -423,11 +422,11 @@ ia6_print(const struct in6_addr *ia)
 }
 
 static void
-mc6_print(const char *ifname)
+mc6_print(const int ifindex)
 {
 	static int mcast_oids[4];
 
-	mc_print(ifname, sizeof(struct in6_addr), "net.inet6.multicast",
+	mc_print(ifindex, sizeof(struct in6_addr), "net.inet6.multicast",
 	mcast_oids, (void (*)(const void *))ia6_print);
 }
 #endif
@@ -439,17 +438,17 @@ ia4_print(const struct in_addr *ia)
 }
 
 static void
-mc4_print(const char *ifname)
+mc4_print(const int ifindex)
 {
 	static int mcast_oids[4];
 
-	mc_print(ifname, sizeof(struct in_addr), "net.inet.multicast",
+	mc_print(ifindex, sizeof(struct in_addr), "net.inet.multicast",
 	mcast_oids, (void (*)(const void *))ia4_print);
 }
 
 static void
-print_addr(const char *name, struct sockaddr *sa, struct sockaddr **rtinfo,
-struct if_data *ifd, struct ifnet *ifnet)
+print_addr(const int ifindex, struct sockaddr *sa,
+struct sockaddr **rtinfo, struct if_data *ifd, struct ifnet *ifnet)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = "%02x%c";	/* for hexprint */
@@ -503,7 +502,7 @@ print_addr(const char *name, struct sock
 multiaddr = (u_long)inm.inm_list.le_next;
 			}
 		} else {
-			mc4_print(name);
+			mc4_print(ifindex);
 		}
 		break;
 #ifdef INET6
@@ -555,7 +554,7 @@ print_addr(const char *name, struct sock
 multiaddr = (u_long)inm.in6m_entry.le_next;
 			}
 		} else {
-			mc6_print(name);
+			mc6_print(ifindex);
 		}
 		break;
 #endif /*INET6*/



CVS commit: src/usr.bin/netstat

2016-12-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Dec 23 06:22:00 UTC 2016

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

Log Message:
in getpcblist_sysctl() if sysctlnametomib() fails, return NULL and
set *len = 0, rather than bailing.  now "netstat" doesn't give up
early on kernels without INET6.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/netstat/inet.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.106 src/usr.bin/netstat/inet.c:1.107
--- src/usr.bin/netstat/inet.c:1.106	Sun Feb  8 15:09:45 2015
+++ src/usr.bin/netstat/inet.c	Fri Dec 23 06:22:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg 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.106 2015/02/08 15:09:45 christos Exp $");
+__RCSID("$NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,6 +88,8 @@ __RCSID("$NetBSD: inet.c,v 1.106 2015/02
 #include 
 #include 
 #include 
+#include 
+
 #include "netstat.h"
 #include "vtw.h"
 #include "prog_ops.h"
@@ -240,8 +242,14 @@ getpcblist_sysctl(const char *name, size
 		err(1, "asprintf");
 
 	/* get dynamic pcblist node */
-	if (sysctlnametomib(mibname, mib, ) == -1)
+	if (sysctlnametomib(mibname, mib, ) == -1) {
+		if (errno == ENOENT) {
+			*len = 0;
+			return NULL;
+		}
+			
 		err(1, "sysctlnametomib: %s", mibname);
+	}
 
 	free(mibname);
 



CVS commit: src/usr.bin/netstat

2016-12-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Dec 17 09:12:22 UTC 2016

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

Log Message:
Print previously missing fields from a TCP6 PCB.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.68 src/usr.bin/netstat/inet6.c:1.69
--- src/usr.bin/netstat/inet6.c:1.68	Sun Feb  8 15:09:45 2015
+++ src/usr.bin/netstat/inet6.c	Sat Dec 17 09:12:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv 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.68 2015/02/08 15:09:45 christos Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -1494,6 +1494,9 @@ tcp6_dump(u_long off, const char *name, 
 #ifdef TCP6
 	printf("peermaxseg %u, maxseg %u, force %d\n\n", mypcb.t_peermaxseg,
 	mypcb.t_maxseg, mypcb.t_force);
+#else
+printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
+	tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
 #endif
 
 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
@@ -1511,8 +1514,11 @@ tcp6_dump(u_long off, const char *name, 
 	(unsigned long long)mypcb.snd_ssthresh);
 
 #ifdef TCP6
-	printf("idle %d, rtt %d, " mypcb.t_idle, mypcb.t_rtt)
+	printf("idle %d, rtt %d, " mypcb.t_idle, mypcb.t_rtt);
+#else
+	printf("rcvtime %u, rtttime %u, ", tcpcb.t_rcvtime, tcpcb.t_rtttime);
 #endif
+
 	printf("rtseq %u, srtt %d, rttvar %d, rttmin %d, "
 	"max_sndwnd %llu\n\n", mypcb.t_rtseq,
 	mypcb.t_srtt, mypcb.t_rttvar, mypcb.t_rttmin,



CVS commit: src/usr.bin/netstat

2016-11-23 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Nov 24 00:05:13 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.89 src/usr.bin/netstat/if.c:1.90
--- src/usr.bin/netstat/if.c:1.89	Thu Jul 14 20:38:20 2016
+++ src/usr.bin/netstat/if.c	Thu Nov 24 00:05:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -100,7 +100,7 @@ static void intpr_sysctl(void);
 static void intpr_kvm(u_long, void (*)(const char *));
 
 struct iftot iftot[MAXIF], ip_cur, ip_old, sum_cur, sum_old;
-bool	signalled;			/* set if alarm goes off "early" */
+static sig_atomic_t signalled;		/* set when alarm goes off */
 
 static unsigned redraw_lines = 21;
 
@@ -712,7 +712,9 @@ iftot_print_sum(struct iftot *cur, struc
 __dead static void
 sidewaysintpr_sysctl(unsigned interval)
 {
+	struct itimerval it;
 	sigset_t emptyset;
+	sigset_t noalrm;
 	unsigned line;
 
 	set_lines();
@@ -724,9 +726,18 @@ sidewaysintpr_sysctl(unsigned interval)
 		exit(1);
 	}
 
-	(void)signal(SIGALRM, catchalarm);
+	sigemptyset();
+	sigemptyset();
+	sigaddset(, SIGALRM);
+	sigprocmask(SIG_SETMASK, , NULL);
+
 	signalled = 0;
-	(void)alarm(interval);
+	(void)signal(SIGALRM, catchalarm);
+
+	it.it_interval.tv_sec = it.it_value.tv_sec = interval;
+	it.it_interval.tv_usec = it.it_value.tv_usec = 0;
+	setitimer(ITIMER_REAL, , NULL);
+
 banner:
 	iftot_banner(_cur);
 
@@ -749,11 +760,10 @@ loop:
 	putchar('\n');
 	fflush(stdout);
 	line++;
-	sigemptyset();
-	if (!signalled)
+	if (signalled == 0) {
 		sigsuspend();
+	}
 	signalled = 0;
-	(void)alarm(interval);
 	if (line == redraw_lines)
 		goto banner;
 	goto loop;
@@ -764,13 +774,14 @@ static void
 sidewaysintpr_kvm(unsigned interval, u_long off)
 {
 	struct itimerval it;
+	sigset_t emptyset;
+	sigset_t noalrm;
 	struct ifnet ifnet;
 	u_long firstifnet;
 	struct iftot *ip, *total;
 	unsigned line;
 	struct iftot *lastif, *sum, *interesting;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
-	int oldmask;
 
 	set_lines();
 
@@ -806,8 +817,13 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	}
 	lastif = ip;
 
+	sigemptyset();
+	sigemptyset();
+	sigaddset(, SIGALRM);
+	sigprocmask(SIG_SETMASK, , NULL);
+
+	signalled = 0;
 	(void)signal(SIGALRM, catchalarm);
-	signalled = false;
 
 	it.it_interval.tv_sec = it.it_value.tv_sec = interval;
 	it.it_interval.tv_usec = it.it_value.tv_usec = 0;
@@ -980,12 +996,10 @@ loop:
 	putchar('\n');
 	fflush(stdout);
 	line++;
-	oldmask = sigblock(sigmask(SIGALRM));
-	if (! signalled) {
-		sigpause(0);
+	if (signalled == 0) {
+		sigsuspend();
 	}
-	sigsetmask(oldmask);
-	signalled = false;
+	signalled = 0;
 	if (line == redraw_lines)
 		goto banner;
 	goto loop;



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:38:20 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
more XXX removal.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.88 src/usr.bin/netstat/if.c:1.89
--- src/usr.bin/netstat/if.c:1.88	Thu Jul 14 16:34:36 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 16:38:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -80,7 +80,7 @@ struct	iftot {
 	u_quad_t ift_ob;		/* output bytes */
 	u_quad_t ift_oe;		/* output errors */
 	u_quad_t ift_co;		/* collisions */
-	int ift_dr;			/* drops */
+	u_quad_t ift_dr;		/* drops */
 };
 
 static void set_lines(void);
@@ -687,7 +687,7 @@ iftot_print(struct iftot *cur, struct if
 		cur->ift_oe - old->ift_oe,
 		cur->ift_co - old->ift_co);
 	if (dflag)
-		printf(" %5u", cur->ift_dr - old->ift_dr);
+		printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
 }
 
 static void
@@ -706,7 +706,7 @@ iftot_print_sum(struct iftot *cur, struc
 		cur->ift_co - old->ift_co);
 
 	if (dflag)
-		printf(" %5u", cur->ift_dr - old->ift_dr);
+		printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
 }
 
 __dead static void
@@ -917,9 +917,8 @@ loop:
 	(ifnet.if_collisions - ip->ift_co));
 			}
 			if (dflag)
-printf(" %5llu",
-(unsigned long long)
-	(ifnet.if_snd.ifq_drops - ip->ift_dr));
+printf(" %5" PRIu64,
+	ifnet.if_snd.ifq_drops - ip->ift_dr);
 		}
 		ip->ift_ip = ifnet.if_ipackets;
 		ip->ift_ib = ifnet.if_ibytes;
@@ -1088,8 +1087,7 @@ fetchifs(void)
 ip_cur.ift_ob = ifd->ifi_obytes;
 ip_cur.ift_oe = ifd->ifi_oerrors;
 ip_cur.ift_co = ifd->ifi_collisions;
-ip_cur.ift_dr = 0;
-/* XXX-elad ifnet.if_snd.ifq_drops */
+ip_cur.ift_dr = ifd->ifi_iqdrops;
 			}
 
 			sum_cur.ift_ip += ifd->ifi_ipackets;
@@ -1099,7 +1097,7 @@ fetchifs(void)
 			sum_cur.ift_ob += ifd->ifi_obytes;
 			sum_cur.ift_oe += ifd->ifi_oerrors;
 			sum_cur.ift_co += ifd->ifi_collisions;
-			sum_cur.ift_dr += 0; /* XXX-elad ifnet.if_snd.ifq_drops */
+			sum_cur.ift_dr += ifd->ifi_iqdrops;
 			break;
 		}
 	}
@@ -1113,7 +,6 @@ fetchifs(void)
 		ip_cur.ift_ob = ifd->ifi_obytes;
 		ip_cur.ift_oe = ifd->ifi_oerrors;
 		ip_cur.ift_co = ifd->ifi_collisions;
-		ip_cur.ift_dr = 0;
-		/* XXX-elad ifnet.if_snd.ifq_drops */
+		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
 }



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:34:36 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
XXX: removal


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.87 src/usr.bin/netstat/if.c:1.88
--- src/usr.bin/netstat/if.c:1.87	Thu Jul 14 15:39:41 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 16:34:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -227,10 +227,8 @@ intpr_sysctl(void)
 ifd->ifi_ipackets + ifd->ifi_ierrors +
 ifd->ifi_opackets + ifd->ifi_oerrors +
 ifd->ifi_collisions;
-if (tflag)
-	total += 0; // XXX-elad ifnet.if_timer;
 if (dflag)
-	total += 0; // XXX-elad ifnet.if_snd.ifq_drops;
+	total += ifd->ifi_iqdrops;
 if (total == 0)
 	continue;
 			}
@@ -624,7 +622,9 @@ print_addr(const char *name, struct sock
 	if (tflag)
 		printf(" %4d", ifnet ? ifnet->if_timer : 0);
 	if (dflag)
-		printf(" %5d", ifnet ? ifnet->if_snd.ifq_drops : 0);
+		printf(" %5lld", ifnet ?
+		(unsigned long long)ifnet->if_snd.ifq_drops :
+		ifd->ifi_iqdrops);
 	putchar('\n');
 }
 
@@ -687,9 +687,7 @@ iftot_print(struct iftot *cur, struct if
 		cur->ift_oe - old->ift_oe,
 		cur->ift_co - old->ift_co);
 	if (dflag)
-		printf(" %5llu",
-		/* XXX ifnet.if_snd.ifq_drops - ip->ift_dr); */
-		0LL);
+		printf(" %5u", cur->ift_dr - old->ift_dr);
 }
 
 static void
@@ -708,7 +706,7 @@ iftot_print_sum(struct iftot *cur, struc
 		cur->ift_co - old->ift_co);
 
 	if (dflag)
-		printf(" %5llu", (unsigned long long)(cur->ift_dr - old->ift_dr));
+		printf(" %5u", cur->ift_dr - old->ift_dr);
 }
 
 __dead static void



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:13:10 UTC 2016

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
remove soft interrupt queues that don't exist anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.98 src/usr.bin/netstat/main.c:1.99
--- src/usr.bin/netstat/main.c:1.98	Thu Jul 14 15:39:41 2016
+++ src/usr.bin/netstat/main.c	Thu Jul 14 16:13:10 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -146,35 +146,23 @@ struct nlist nl[] = {
 	{ "_rip6stat", 0, 0, 0, 0 },	/* not available via kvm */
 #define	N_ARPINTRQ	38
 	{ "_arpintrq", 0, 0, 0, 0 },
-#define	N_IPINTRQ	39
-	{ "_ipintrq", 0, 0, 0, 0 },
-#define	N_IP6INTRQ	40
-	{ "_ip6intrq", 0, 0, 0, 0 },
-#define	N_ATINTRQ1	41
+#define	N_ATINTRQ1	39
 	{ "_atintrq1", 0, 0, 0, 0 },
-#define	N_ATINTRQ2	42
+#define	N_ATINTRQ2	40
 	{ "_atintrq2", 0, 0, 0, 0 },
-#define	N_NSINTRQ	43
-	{ "_nsintrq", 0, 0, 0, 0 },
-#define	N_LLCINTRQ	44
-	{ "_llcintrq", 0, 0, 0, 0 },
-#define	N_HDINTRQ	45
-	{ "_hdintrq", 0, 0, 0, 0 },
-#define	N_NATMINTRQ	46
+#define	N_NATMINTRQ	41
 	{ "_natmintrq", 0, 0, 0, 0 },
-#define	N_PPPOEDISCINQ	47
+#define	N_PPPOEDISCINQ	42
 	{ "_ppoediscinq", 0, 0, 0, 0 },
-#define	N_PPPOEINQ	48
+#define	N_PPPOEINQ	43
 	{ "_ppoeinq", 0, 0, 0, 0 },
-#define	N_PKINTRQ	49
-	{ "_pkintrq", 0, 0, 0, 0 },
-#define	N_HARDCLOCK_TICKS 50
+#define	N_HARDCLOCK_TICKS 44
 	{ "_hardclock_ticks", 0, 0, 0, 0 },
-#define N_PIMSTAT	51
+#define N_PIMSTAT	45
 	{ "_pimstat", 0, 0, 0, 0 },
-#define N_CARPSTAT	52
+#define N_CARPSTAT	46
 	{ "_carpstats", 0, 0, 0, 0 },	/* not available via kvm */
-#define N_PFSYNCSTAT	53
+#define N_PFSYNCSTAT	47
 	{ "_pfsyncstats", 0, 0, 0, 0},  /* not available via kvm */
 	{ "", 0, 0, 0, 0 },
 };
@@ -288,16 +276,11 @@ const struct softintrq {
 	int siq_index;
 } softintrq[] = {
 	{ "arpintrq", N_ARPINTRQ },
-	{ "ipintrq", N_IPINTRQ },
-	{ "ip6intrq", N_IP6INTRQ },
 	{ "atintrq1", N_ATINTRQ1 },
 	{ "atintrq2", N_ATINTRQ2 },
-	{ "llcintrq", N_LLCINTRQ },
-	{ "hdintrq", N_HDINTRQ },
 	{ "natmintrq", N_NATMINTRQ },
 	{ "ppoediscinq", N_PPPOEDISCINQ },
 	{ "ppoeinq", N_PPPOEINQ },
-	{ "pkintrq", N_PKINTRQ },
 	{ NULL, -1 },
 };
 



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 19:39:41 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c main.c

Log Message:
remove __P


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/main.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/if.c
diff -u src/usr.bin/netstat/if.c:1.86 src/usr.bin/netstat/if.c:1.87
--- src/usr.bin/netstat/if.c:1.86	Thu Jul 14 14:58:26 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 15:39:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -92,7 +92,7 @@ static void iftot_banner(struct iftot *)
 static void iftot_print_sum(struct iftot *, struct iftot *);
 static void iftot_print(struct iftot *, struct iftot *);
 
-static void catchalarm __P((int));
+static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
 

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.97 src/usr.bin/netstat/main.c:1.98
--- src/usr.bin/netstat/main.c:1.97	Thu Jul 14 14:19:11 2016
+++ src/usr.bin/netstat/main.c	Thu Jul 14 15:39:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.97 2016/07/14 18:19:11 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.97 2016/07/14 18:19:11 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -184,13 +184,13 @@ struct protox {
 	u_char	pr_sindex;		/* index into nlist of stat block */
 	u_char	pr_wanted;		/* 1 if wanted, 0 otherwise */
 	void	(*pr_cblocks)		/* control blocks printing routine */
-			__P((u_long, const char *));
+			(u_long, const char *);
 	void	(*pr_stats)		/* statistics printing routine */
-			__P((u_long, const char *));
+			(u_long, const char *);
 	void	(*pr_istats)
-			__P((const char *));	/* per/if statistics printing routine */
+			(const char *);	/* per/if statistics printing routine */
 	void	(*pr_dump)		/* PCB state dump routine */
-			__P((u_long, const char *, u_long));
+			(u_long, const char *, u_long);
 	const char *pr_name;		/* well-known name */
 } protox[] = {
 	{ N_TCBTABLE,	N_TCPSTAT,	1,	protopr,
@@ -301,12 +301,11 @@ const struct softintrq {
 	{ NULL, -1 },
 };
 
-int main __P((int, char *[]));
-static void printproto __P((struct protox *, const char *));
-static void print_softintrq __P((void));
+static void printproto(struct protox *, const char *);
+static void print_softintrq(void);
 __dead static void usage(void);
-static struct protox *name2protox __P((const char *));
-static struct protox *knownname __P((const char *));
+static struct protox *name2protox(const char *);
+static struct protox *knownname(const char *);
 static void prepare(const char *, const char *, struct protox *tp);
 static kvm_t *prepare_kvmd(const char *, const char *, char *);
 
@@ -723,7 +722,7 @@ main(int argc, char *argv[])
 static void
 printproto(struct protox *tp, const char *name)
 {
-	void (*pr) __P((u_long, const char *));
+	void (*pr)(u_long, const char *);
 	u_long off;
 
 	if (sflag) {



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 18:58:26 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
dedup


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.85 src/usr.bin/netstat/if.c:1.86
--- src/usr.bin/netstat/if.c:1.85	Thu Jul 14 14:19:11 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 14:58:26 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -357,69 +357,42 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
-ia6_print(struct in6_addr *ia)
+mc_print(const char *ifname, const size_t ias, const char *oid, int *mcast_oids,
+void (*pr)(const void *))
 {
-	struct sockaddr_in6 as6;
-	char hbuf[NI_MAXHOST];		/* for getnameinfo() */
-	int n;
-
-	memset(, 0, sizeof(as6));
-	as6.sin6_len = sizeof(struct sockaddr_in6);
-	as6.sin6_family = AF_INET6;
-	as6.sin6_addr = *ia;
-	inet6_getscopeid(, INET6_IS_ADDR_MC_LINKLOCAL);
-	if (getnameinfo((struct sockaddr *), as6.sin6_len, hbuf,
-	sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
-		strlcpy(hbuf, "??", sizeof(hbuf));
-	}
-	if (vflag)
-		n = strlen(hbuf) < 17 ? 17 : strlen(hbuf);
-	else
-		n = 17;
-	printf("\n%25s %-*.*s ", "", n, n, hbuf);
-}
-
-static void
-mc6_print(const char *ifname)
-{
-	static const size_t incr =
-	2 * sizeof(struct in6_addr) + sizeof(uint32_t);
-	static int mcast_oids[4];
-	static int oifindex = -1;
 	uint8_t *mcast_addrs, *p;
+	const size_t incr = 2 * ias + sizeof(uint32_t);
 	size_t len;
 	int ifindex;
 
 	if ((ifindex = if_nametoindex(ifname)) == 0)
 		warn("Interface %s not found", ifname);
 
-	if (ifindex == oifindex)
-		return;
-	oifindex = ifindex;
-
 	if (mcast_oids[0] == 0) {
-		size_t oidlen = __arraycount(mcast_oids);
-		if (sysctlnametomib("net.inet6.multicast", mcast_oids,
-		) == -1) {
-			warnx("net.inet6.multicast not found");
+		size_t oidlen = 4;
+		if (sysctlnametomib(oid, mcast_oids, ) == -1) {
+			warnx("'%s' not found", oid);
 			return;
 		}
 		if (oidlen != 3) {
-			warnx("Wrong OID path for net.inet6.multicast");
+			warnx("Wrong OID path for '%s'", oid);
 			return;
 		}
 	}
+
+	if (mcast_oids[3] == ifindex)
+		return;
 	mcast_oids[3] = ifindex;
 
 	mcast_addrs = asysctl(mcast_oids, 4, );
 	if (mcast_addrs == NULL && len != 0) {
-		warn("failed to read net.inet6.multicast");
+		warn("failed to read '%s'", oid);
 		return;
 	}
 	if (len) {
 		p = mcast_addrs;
 		while (len >= incr) {
-			ia6_print((void *)(p + sizeof(struct in6_addr)));
+			(*pr)((p + ias));
 			p += incr;
 			len -= incr;
 		}
@@ -427,58 +400,53 @@ mc6_print(const char *ifname)
 	free(mcast_addrs);
 }
 
+#ifdef INET6
 static void
-ia4_print(const struct in_addr *ia)
+ia6_print(const struct in6_addr *ia)
 {
-	printf("\n%25s %-17.17s ", "", routename4(ia->s_addr, nflag));
+	struct sockaddr_in6 as6;
+	char hbuf[NI_MAXHOST];		/* for getnameinfo() */
+	int n;
+
+	memset(, 0, sizeof(as6));
+	as6.sin6_len = sizeof(struct sockaddr_in6);
+	as6.sin6_family = AF_INET6;
+	as6.sin6_addr = *ia;
+	inet6_getscopeid(, INET6_IS_ADDR_MC_LINKLOCAL);
+	if (getnameinfo((struct sockaddr *), as6.sin6_len, hbuf,
+	sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
+		strlcpy(hbuf, "??", sizeof(hbuf));
+	}
+	if (vflag)
+		n = strlen(hbuf) < 17 ? 17 : strlen(hbuf);
+	else
+		n = 17;
+	printf("\n%25s %-*.*s ", "", n, n, hbuf);
 }
 
 static void
-mc4_print(const char *ifname)
+mc6_print(const char *ifname)
 {
-	static const size_t incr =
-	2 * sizeof(struct in_addr) + sizeof(uint32_t);
 	static int mcast_oids[4];
-	static int oifindex = -1;
-	uint8_t *mcast_addrs, *p;
-	size_t len;
-	int ifindex;
 
-	if ((ifindex = if_nametoindex(ifname)) == 0)
-		warn("Interface %s not found", ifname);
+	mc_print(ifname, sizeof(struct in6_addr), "net.inet6.multicast",
+	mcast_oids, (void (*)(const void *))ia6_print);
+}
+#endif
 
-	if (ifindex == oifindex)
-		return;
-	oifindex = ifindex;
+static void
+ia4_print(const struct in_addr *ia)
+{
+	printf("\n%25s %-17.17s ", "", routename4(ia->s_addr, nflag));
+}
 
-	if (mcast_oids[0] == 0) {
-		size_t oidlen = __arraycount(mcast_oids);
-		if (sysctlnametomib("net.inet.multicast", mcast_oids,
-		) == -1) {
-			warnx("net.inet.multicast not found");
-			return;
-		}
-		if (oidlen != 3) {
-			warnx("Wrong OID path for net.inet.multicast");
-			return;
-		}
-	}
-	mcast_oids[3] = ifindex;
+static void
+mc4_print(const char *ifname)

CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 18:19:11 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c main.c

Log Message:
use sysctl to print multicast addresses


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/netstat/main.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/if.c
diff -u src/usr.bin/netstat/if.c:1.84 src/usr.bin/netstat/if.c:1.85
--- src/usr.bin/netstat/if.c:1.84	Wed Jul 13 18:01:12 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 14:19:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.84 2016/07/13 22:01:12 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.84 2016/07/13 22:01:12 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,8 +84,8 @@ struct	iftot {
 };
 
 static void set_lines(void);
-static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *,
-struct ifnet *);
+static void print_addr(const char *, struct sockaddr *, struct sockaddr **,
+struct if_data *, struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
 
 static void iftot_banner(struct iftot *);
@@ -266,7 +266,7 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		print_addr(rti_info[rtax], rti_info, ifd, NULL);
+		print_addr(name, rti_info[rtax], rti_info, ifd, NULL);
 	}
 }
 
@@ -348,7 +348,8 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
-			print_addr(sa, (void *), _data, );
+			print_addr(name, sa, (void *), _data,
+			);
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -379,8 +380,110 @@ ia6_print(struct in6_addr *ia)
 }
 
 static void
-print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
-struct ifnet *ifnet)
+mc6_print(const char *ifname)
+{
+	static const size_t incr =
+	2 * sizeof(struct in6_addr) + sizeof(uint32_t);
+	static int mcast_oids[4];
+	static int oifindex = -1;
+	uint8_t *mcast_addrs, *p;
+	size_t len;
+	int ifindex;
+
+	if ((ifindex = if_nametoindex(ifname)) == 0)
+		warn("Interface %s not found", ifname);
+
+	if (ifindex == oifindex)
+		return;
+	oifindex = ifindex;
+
+	if (mcast_oids[0] == 0) {
+		size_t oidlen = __arraycount(mcast_oids);
+		if (sysctlnametomib("net.inet6.multicast", mcast_oids,
+		) == -1) {
+			warnx("net.inet6.multicast not found");
+			return;
+		}
+		if (oidlen != 3) {
+			warnx("Wrong OID path for net.inet6.multicast");
+			return;
+		}
+	}
+	mcast_oids[3] = ifindex;
+
+	mcast_addrs = asysctl(mcast_oids, 4, );
+	if (mcast_addrs == NULL && len != 0) {
+		warn("failed to read net.inet6.multicast");
+		return;
+	}
+	if (len) {
+		p = mcast_addrs;
+		while (len >= incr) {
+			ia6_print((void *)(p + sizeof(struct in6_addr)));
+			p += incr;
+			len -= incr;
+		}
+	}
+	free(mcast_addrs);
+}
+
+static void
+ia4_print(const struct in_addr *ia)
+{
+	printf("\n%25s %-17.17s ", "", routename4(ia->s_addr, nflag));
+}
+
+static void
+mc4_print(const char *ifname)
+{
+	static const size_t incr =
+	2 * sizeof(struct in_addr) + sizeof(uint32_t);
+	static int mcast_oids[4];
+	static int oifindex = -1;
+	uint8_t *mcast_addrs, *p;
+	size_t len;
+	int ifindex;
+
+	if ((ifindex = if_nametoindex(ifname)) == 0)
+		warn("Interface %s not found", ifname);
+
+	if (ifindex == oifindex)
+		return;
+	oifindex = ifindex;
+
+	if (mcast_oids[0] == 0) {
+		size_t oidlen = __arraycount(mcast_oids);
+		if (sysctlnametomib("net.inet.multicast", mcast_oids,
+		) == -1) {
+			warnx("net.inet.multicast not found");
+			return;
+		}
+		if (oidlen != 3) {
+			warnx("Wrong OID path for net.inet.multicast");
+			return;
+		}
+	}
+	mcast_oids[3] = ifindex;
+
+	mcast_addrs = asysctl(mcast_oids, 4, );
+	if (mcast_addrs == NULL && len != 0) {
+		warn("failed to read net.inet6.multicast");
+		return;
+	}
+	if (len) {
+		p = mcast_addrs;
+		while (len >= incr) {
+			ia4_print((void *)(p + sizeof(struct in_addr)));
+			p += incr;
+			len -= incr;
+		}
+	}
+	free(mcast_addrs);
+}
+
+static void
+print_addr(const char *name, struct sockaddr *sa, struct sockaddr **rtinfo,
+struct if_data *ifd, struct ifnet *ifnet)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = "%02x%c";	/* for hexprint */
@@ -427,19 +530,14 @@ print_addr(struct sockaddr *sa, struct s
 			struct in_multi inm;
 			union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
 
-			multiaddr = (u_long)
-			ifaddr->in.ia_multiaddrs.lh_first;
+			multiaddr = (u_long)ifaddr->in.ia_multiaddrs.lh_first;
 			while (multiaddr 

CVS commit: src/usr.bin/netstat

2016-07-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 13 22:01:12 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.83 src/usr.bin/netstat/if.c:1.84
--- src/usr.bin/netstat/if.c:1.83	Mon Feb 29 13:21:15 2016
+++ src/usr.bin/netstat/if.c	Wed Jul 13 18:01:12 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.83 2016/02/29 18:21:15 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.84 2016/07/13 22:01:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.83 2016/02/29 18:21:15 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.84 2016/07/13 22:01:12 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -177,6 +177,7 @@ intpr_sysctl(void)
 	struct sockaddr_dl *sdl;
 	uint64_t total = 0;
 	size_t len;
+	int did = 1, rtax = 0, n;
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
@@ -233,11 +234,13 @@ intpr_sysctl(void)
 if (total == 0)
 	continue;
 			}
-
-			printf("%-5s %-5" PRIu64, name, ifd->ifi_mtu);
-			print_addr(rti_info[RTAX_IFP], rti_info, ifd, NULL);
+			/* Skip the first one */
+			if (did) {
+did = 0;
+continue;
+			}
+			rtax = RTAX_IFP;
 			break;
-
 		case RTM_NEWADDR:
 			if (qflag && total == 0)
 continue;
@@ -251,11 +254,19 @@ intpr_sysctl(void)
 			sa = (struct sockaddr *)(ifam + 1);
 
 			get_rtaddrs(ifam->ifam_addrs, sa, rti_info);
-
-			printf("%-5s %-5" PRIu64, name, ifd->ifi_mtu);
-			print_addr(rti_info[RTAX_IFA], rti_info, ifd, NULL);
+			rtax = RTAX_IFA;
+			did = 1;
 			break;
+		default:
+			continue;
 		}
+		if (vflag)
+			n = strlen(name) < 5 ? 5 : strlen(name);
+		else
+			n = 5;
+
+		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
+		print_addr(rti_info[rtax], rti_info, ifd, NULL);
 	}
 }
 
@@ -345,6 +356,29 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
+ia6_print(struct in6_addr *ia)
+{
+	struct sockaddr_in6 as6;
+	char hbuf[NI_MAXHOST];		/* for getnameinfo() */
+	int n;
+
+	memset(, 0, sizeof(as6));
+	as6.sin6_len = sizeof(struct sockaddr_in6);
+	as6.sin6_family = AF_INET6;
+	as6.sin6_addr = *ia;
+	inet6_getscopeid(, INET6_IS_ADDR_MC_LINKLOCAL);
+	if (getnameinfo((struct sockaddr *), as6.sin6_len, hbuf,
+	sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
+		strlcpy(hbuf, "??", sizeof(hbuf));
+	}
+	if (vflag)
+		n = strlen(hbuf) < 17 ? 17 : strlen(hbuf);
+	else
+		n = 17;
+	printf("\n%25s %-*.*s ", "", n, n, hbuf);
+}
+
+static void
 print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
 struct ifnet *ifnet)
 {
@@ -386,7 +420,9 @@ print_addr(struct sockaddr *sa, struct s
 			n = 17;
 		printf("%-*.*s ", n, n, cp);
 
-		if (aflag && ifnet) {
+		if (!aflag)
+			break;
+		if (ifnet) {
 			u_long multiaddr;
 			struct in_multi inm;
 			union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
@@ -402,6 +438,8 @@ print_addr(struct sockaddr *sa, struct s
 multiaddr =
    (u_long)inm.inm_list.le_next;
 			}
+		} else {
+			// XXX: Sysctl/ioctl to get multicast addresses
 		}
 		break;
 #ifdef INET6
@@ -439,41 +477,21 @@ print_addr(struct sockaddr *sa, struct s
 			n = 17;
 		printf("%-*.*s ", n, n, cp);
 
-		if (aflag && ifnet) {
+		if (!aflag) 
+			break;
+		if (ifnet) {
 			u_long multiaddr;
 			struct in6_multi inm;
-			struct sockaddr_in6 as6;
 			union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
 		
-			multiaddr = (u_long)
-			ifaddr->in6.ia6_multiaddrs.lh_first;
+			multiaddr = (u_long)ifaddr->in6.ia6_multiaddrs.lh_first;
 			while (multiaddr != 0) {
-kread(multiaddr, (char *),
-   sizeof inm);
-memset(, 0, sizeof(as6));
-as6.sin6_len = sizeof(struct sockaddr_in6);
-as6.sin6_family = AF_INET6;
-as6.sin6_addr = inm.in6m_addr;
-inet6_getscopeid(,
-INET6_IS_ADDR_MC_LINKLOCAL);
-if (getnameinfo((struct sockaddr *),
-as6.sin6_len, hbuf,
-sizeof(hbuf), NULL, 0,
-niflag) != 0) {
-	strlcpy(hbuf, "??",
-	sizeof(hbuf));
-}
-cp = hbuf;
-if (vflag)
-n = strlen(cp) < 17
-	? 17 : strlen(cp);
-else
-n = 17;
-printf("\n%25s %-*.*s ", "",
-n, n, cp);
-multiaddr =
-   (u_long)inm.in6m_entry.le_next;
+kread(multiaddr, (char *), sizeof inm);
+ia6_print(_addr);
+multiaddr = (u_long)inm.in6m_entry.le_next;
 			}
+		} else {
+			// XXX: Sysctl/ioctl to get multicast addresses
 		}
 		break;
 #endif /*INET6*/



CVS commit: src/usr.bin/netstat

2016-07-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 13 21:57:02 UTC 2016

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Use sysctl for interface printing (-i), leave on for multicast address printing
(-ia) and comment in the code where this is missing?
XXX: should that be an ioctl or sysctl? provide getifmultiaddrs() via the
routing socket? I guess since this is just for netstat a simple sysctl or
ioctl would suffice. I lean towards sysctl.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.95 src/usr.bin/netstat/main.c:1.96
--- src/usr.bin/netstat/main.c:1.95	Tue Nov 11 22:34:59 2014
+++ src/usr.bin/netstat/main.c	Wed Jul 13 17:57:01 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.96 2016/07/13 21:57:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.96 2016/07/13 21:57:01 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -358,7 +358,7 @@ prepare(const char *nf, const char *mf, 
 		 */
 		use_sysctl = 0;
 	} else if (qflag ||
-		   iflag ||
+		   (iflag && aflag) ||	/* For multicast */
 #ifndef SMALL
 		   gflag ||
 #endif



CVS commit: src/usr.bin/netstat

2016-05-11 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May 12 03:44:11 UTC 2016

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Remove duplicate routing flag list

We alreay have it in route(8) and shouldn't have another one.
(Actually the removed list is forgot to be updated.)


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.72 src/usr.bin/netstat/netstat.1:1.73
--- src/usr.bin/netstat/netstat.1:1.72	Mon Mar 23 18:33:17 2015
+++ src/usr.bin/netstat/netstat.1	Thu May 12 03:44:11 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.72 2015/03/23 18:33:17 roy Exp $
+.\"	$NetBSD: netstat.1,v 1.73 2016/05/12 03:44:11 ozaki-r Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\"
-.Dd March 19, 2015
+.Dd May 12, 2016
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -367,26 +367,6 @@ detail in the
 and
 .Xr route 4
 manual pages.
-The mapping between letters and flags is:
-.Bl -column  RTF_BLACKHOLE
-.It 1	RTF_PROTO1	Protocol specific routing flag #1
-.It 2	RTF_PROTO2	Protocol specific routing flag #2
-.It B	RTF_BLACKHOLE	Just discard pkts (during updates)
-.It b	RTF_BROADCAST	Route represents a broadcast address
-.It C	RTF_CLONING	Generate new routes on use
-.It c	RTF_CLONED	Cloned routes (generated from RTF_CLONING)
-.It D	RTF_DYNAMIC	Created dynamically (by redirect)
-.It G	RTF_GATEWAY	Destination requires forwarding by intermediary
-.It H	RTF_HOST	Host entry (net otherwise)
-.It L	RTF_LLINFO	Valid protocol to link address translation.
-.It l	RTF_LOCAL	Route represents a local address
-.It M	RTF_MODIFIED	Modified dynamically (by redirect)
-.It p	RTF_ANNOUNCE	Link level proxy
-.It R	RTF_REJECT	Host or net unreachable
-.It S	RTF_STATIC	Manually added
-.It U	RTF_UP	Route usable
-.It X	RTF_XRESOLVE	External daemon translates proto to link address
-.El
 .Pp
 Direct routes are created for each
 interface attached to the local host;



CVS commit: src/usr.bin/netstat

2016-02-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 29 18:21:15 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
PR/50872: David Binderman: Use logical and instead of arithmetic


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.82 src/usr.bin/netstat/if.c:1.83
--- src/usr.bin/netstat/if.c:1.82	Sat Sep 19 20:30:04 2015
+++ src/usr.bin/netstat/if.c	Mon Feb 29 13:21:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $	*/
+/*	$NetBSD: if.c,v 1.83 2016/02/29 18:21:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $");
+__RCSID("$NetBSD: if.c,v 1.83 2016/02/29 18:21:15 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -144,7 +144,7 @@ static void
 intpr_header(void)
 {
 
-	if (!sflag & !pflag) {
+	if (!sflag && !pflag) {
 		if (bflag) {
 			printf("%-5.5s %-5.5s %-13.13s %-17.17s "
 			   "%10.10s %10.10s",



CVS commit: src/usr.bin/netstat

2016-02-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 29 18:19:46 UTC 2016

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
PR/50873: David Binderman: use logical or instead of arithmetic


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.8 src/usr.bin/netstat/vtw.c:1.9
--- src/usr.bin/netstat/vtw.c:1.8	Tue Jun 16 18:54:10 2015
+++ src/usr.bin/netstat/vtw.c	Mon Feb 29 13:19:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.8 2015/06/16 22:54:10 christos Exp $	*/
+/*	$NetBSD: vtw.c,v 1.9 2016/02/29 18:19:46 christos Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: vtw.c,v 1.8 2015/06/16 22:54:10 christos Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.9 2016/02/29 18:19:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -269,7 +269,7 @@ show_vtw_v4(void (*print)(const vtw_t *)
 		kbase = vtw_tcpv4[i].base.v4;
 		klim = vtw_tcpv4[i].lim.v4;
 
-		if (!kbase | !klim)
+		if (!kbase || !klim)
 			continue;
 
 		n = (klim - kbase + 1);
@@ -300,7 +300,7 @@ show_vtw_v4(void (*print)(const vtw_t *)
 	base = fat_tcpv4.base;
 	lim = fat_tcpv4.lim;
 
-	if (!base | !lim)
+	if (!base || !lim)
 		goto end;
 
 	mem += (lim - base + 1) * sizeof(*base);
@@ -369,7 +369,7 @@ show_vtw_v6(void (*print)(const vtw_t *)
 		kbase = vtw_tcpv6[i].base.v6;
 		klim = vtw_tcpv6[i].lim.v6;
 
-		if (!kbase | !klim)
+		if (!kbase || !klim)
 			continue;
 
 		n = (klim - kbase + 1);
@@ -399,7 +399,7 @@ show_vtw_v6(void (*print)(const vtw_t *)
 	base = fat_tcpv6.base;
 	lim = fat_tcpv6.lim;
 
-	if (!base | !lim)
+	if (!base || !lim)
 		goto end;
 
 	mem += (lim - base + 1) * sizeof(*base);



CVS commit: src/usr.bin/netstat

2015-09-19 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Sep 20 00:30:04 UTC 2015

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.81 src/usr.bin/netstat/if.c:1.82
--- src/usr.bin/netstat/if.c:1.81	Wed Jan  7 22:43:01 2015
+++ src/usr.bin/netstat/if.c	Sun Sep 20 00:30:04 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -44,6 +44,7 @@ __RCSID("$NetBSD: if.c,v 1.81 2015/01/07
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -82,6 +83,7 @@ struct	iftot {
 	int ift_dr;			/* drops */
 };
 
+static void set_lines(void);
 static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *,
 struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
@@ -100,6 +102,22 @@ static void intpr_kvm(u_long, void (*)(c
 struct iftot iftot[MAXIF], ip_cur, ip_old, sum_cur, sum_old;
 bool	signalled;			/* set if alarm goes off "early" */
 
+static unsigned redraw_lines = 21;
+
+static void
+set_lines(void)
+{
+	static bool first = true;
+	struct ttysize ts;
+
+	if (!first)
+		return;
+	first = false;
+	if (ioctl(STDOUT_FILENO, TIOCGSIZE, ) != -1 && ts.ts_lines)
+		redraw_lines = ts.ts_lines - 3;
+}
+
+
 /*
  * Print a description of the network interfaces.
  * NOTE: ifnetaddr is the location of the kernel global "ifnet",
@@ -613,7 +631,9 @@ __dead static void
 sidewaysintpr_sysctl(unsigned interval)
 {
 	sigset_t emptyset;
-	int line;
+	unsigned line;
+
+	set_lines();
 
 	fetchifs();
 	if (ip_cur.ift_name[0] == '\0') {
@@ -652,7 +672,7 @@ loop:
 		sigsuspend();
 	signalled = 0;
 	(void)alarm(interval);
-	if (line == 21)
+	if (line == redraw_lines)
 		goto banner;
 	goto loop;
 	/*NOTREACHED*/
@@ -665,11 +685,13 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	struct ifnet ifnet;
 	u_long firstifnet;
 	struct iftot *ip, *total;
-	int line;
+	unsigned line;
 	struct iftot *lastif, *sum, *interesting;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
 	int oldmask;
 
+	set_lines();
+
 	/*
 	 * Find the pointer to the first ifnet structure.  Replace
 	 * the pointer to the TAILQ_HEAD with the actual pointer
@@ -883,7 +905,7 @@ loop:
 	}
 	sigsetmask(oldmask);
 	signalled = false;
-	if (line == 21)
+	if (line == redraw_lines)
 		goto banner;
 	goto loop;
 	/*NOTREACHED*/



CVS commit: src/usr.bin/netstat

2015-07-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jul 28 19:46:42 UTC 2015

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
revert previous, will fix differently.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/netstat/mbuf.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/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.32 src/usr.bin/netstat/mbuf.c:1.33
--- src/usr.bin/netstat/mbuf.c:1.32	Tue Jul 28 15:32:07 2015
+++ src/usr.bin/netstat/mbuf.c	Tue Jul 28 15:46:42 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.32 2015/07/28 19:32:07 christos Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,12 +34,11 @@
 #if 0
 static char sccsid[] = from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93;
 #else
-__RCSID($NetBSD: mbuf.c,v 1.32 2015/07/28 19:32:07 christos Exp $);
+__RCSID($NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $);
 #endif
 #endif /* not lint */
 
 #define	__POOL_EXPOSE
-#include stdbool.h	// XXX: no sys/stdbool.h
 
 #include sys/param.h
 #include sys/protosw.h



CVS commit: src/usr.bin/netstat

2015-07-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jul 28 19:32:07 UTC 2015

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
fix build (stdbool lossage)


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/netstat/mbuf.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/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.31 src/usr.bin/netstat/mbuf.c:1.32
--- src/usr.bin/netstat/mbuf.c:1.31	Tue Mar 20 16:34:58 2012
+++ src/usr.bin/netstat/mbuf.c	Tue Jul 28 15:32:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.31 2012/03/20 20:34:58 matt Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.32 2015/07/28 19:32:07 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,11 +34,12 @@
 #if 0
 static char sccsid[] = from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93;
 #else
-__RCSID($NetBSD: mbuf.c,v 1.31 2012/03/20 20:34:58 matt Exp $);
+__RCSID($NetBSD: mbuf.c,v 1.32 2015/07/28 19:32:07 christos Exp $);
 #endif
 #endif /* not lint */
 
 #define	__POOL_EXPOSE
+#include stdbool.h	// XXX: no sys/stdbool.h
 
 #include sys/param.h
 #include sys/protosw.h
@@ -53,7 +54,6 @@ __RCSID($NetBSD: mbuf.c,v 1.31 2012/03/
 #include limits.h
 #include errno.h
 #include err.h
-#include stdbool.h
 #include netstat.h
 #include prog_ops.h
 



CVS commit: src/usr.bin/netstat

2015-06-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Jun  6 13:48:37 UTC 2015

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
Format-string related warnings work fine now with both GCC 4.8 and
Clang.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/netstat/Makefile

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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.42 src/usr.bin/netstat/Makefile:1.43
--- src/usr.bin/netstat/Makefile:1.42	Fri May 15 06:58:59 2015
+++ src/usr.bin/netstat/Makefile	Sat Jun  6 13:48:37 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.42 2015/05/15 06:58:59 ozaki-r Exp $
+#	$NetBSD: Makefile,v 1.43 2015/06/06 13:48:37 joerg Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -17,9 +17,6 @@ CPPFLAGS+= -DIPSEC -I${.CURDIR}
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
 CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
 
-CWARNFLAGS.clang+=	-Wno-format
-COPTS.show.c += -Wno-format-nonliteral
-
 .PATH:  ${.CURDIR}/../../lib/libc/gen
 .PATH:  ${.CURDIR}/../../lib/libc/net
 .PATH:  ${.CURDIR}/../../sbin/route



CVS commit: src/usr.bin/netstat

2015-06-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Jun  6 13:08:31 UTC 2015

Modified Files:
src/usr.bin/netstat: atalk.c

Log Message:
Drop assignment from uninitialized and otherwise unused variable.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/atalk.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/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.15 src/usr.bin/netstat/atalk.c:1.16
--- src/usr.bin/netstat/atalk.c:1.15	Fri Oct 18 20:26:45 2013
+++ src/usr.bin/netstat/atalk.c	Sat Jun  6 13:08:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $	*/
+/*	$NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from @(#)atalk.c	1.1 (Whistle) 6/6/96;
 #else
-__RCSID($NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $);
+__RCSID($NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $);
 #endif
 #endif /* not lint */
 
@@ -229,7 +229,6 @@ atalk_print2(const struct sockaddr *sa, 
 void
 atalkprotopr(u_long off, const char *name)
 {
-	struct ddpcb cb;
 	struct ddpcb *next;
 	struct ddpcb *initial;
 	int width = 22;
@@ -237,7 +236,6 @@ atalkprotopr(u_long off, const char *nam
 		return;
 	if (kread(off, (char *)initial, sizeof(struct ddpcb *))  0)
 		return;
-	ddpcb = cb;
 	for (next = initial; next != NULL;) {
 		u_long	ppcb = (u_long)next;
 



CVS commit: src/usr.bin/netstat

2015-05-24 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May 25 03:56:20 UTC 2015

Modified Files:
src/usr.bin/netstat: route.c

Log Message:
Make sure netstat builds with -DSMALL

src/usr.bin/netstat relies on code from src/sbin/route. WHen building
with -DSMALL, some functions such as mpls_ntoa() or p_rtrmx() are not
built in src/sbin/route. We therefore have to make sure they are not
used in src/usr.bin/netstat.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/netstat/route.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/route.c
diff -u src/usr.bin/netstat/route.c:1.83 src/usr.bin/netstat/route.c:1.84
--- src/usr.bin/netstat/route.c:1.83	Thu Nov  6 21:30:09 2014
+++ src/usr.bin/netstat/route.c	Mon May 25 03:56:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.83 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: route.c,v 1.84 2015/05/25 03:56:20 manu Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)route.c	8.3 (Berkeley) 3/9/94;
 #else
-__RCSID($NetBSD: route.c,v 1.83 2014/11/06 21:30:09 christos Exp $);
+__RCSID($NetBSD: route.c,v 1.84 2015/05/25 03:56:20 manu Exp $);
 #endif
 #endif /* not lint */
 
@@ -262,6 +262,7 @@ p_krtentry(struct rtentry *rt)
 		printf(%6s, -);
 	putchar((rt-rt_rmx.rmx_locks  RTV_MTU) ? 'L' : ' ');
 	if (tagflag == 1) {
+#ifndef SMALL
 		if (rt-rt_tag != NULL) {
 			const struct sockaddr *tagsa = kgetsa(rt-rt_tag);
 			char *tagstr;
@@ -276,6 +277,7 @@ p_krtentry(struct rtentry *rt)
 			else
 printf(%7s, -);
 		} else
+#endif
 			printf(%7s, -);
 	}
 	if (rt-rt_ifp) {
@@ -287,8 +289,10 @@ p_krtentry(struct rtentry *rt)
 			rt-rt_nodes[0].rn_dupedkey ?  = : );
 	}
 	putchar('\n');
+#ifndef SMALL
 	if (vflag)
 		p_rtrmx(rt-rt_rmx);
+#endif
 }
 
 /*



CVS commit: src/usr.bin/netstat

2015-02-26 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Feb 26 09:58:12 UTC 2015

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Document RTF_LOCAL


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.70 src/usr.bin/netstat/netstat.1:1.71
--- src/usr.bin/netstat/netstat.1:1.70	Sat Oct 11 09:23:32 2014
+++ src/usr.bin/netstat/netstat.1	Thu Feb 26 09:58:12 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.70 2014/10/11 09:23:32 wiz Exp $
+.\	$NetBSD: netstat.1,v 1.71 2015/02/26 09:58:12 roy Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\
 .\	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\
-.Dd October 19, 2013
+.Dd February 26, 2015
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -378,6 +378,7 @@ The mapping between letters and flags is
 .It G	RTF_GATEWAY	Destination requires forwarding by intermediary
 .It H	RTF_HOST	Host entry (net otherwise)
 .It L	RTF_LLINFO	Valid protocol to link address translation.
+.It l	RTF_LOCAL	Route represents a local address
 .It M	RTF_MODIFIED	Modified dynamically (by redirect)
 .It p	RTF_ANNOUNCE	Link level proxy
 .It R	RTF_REJECT	Host or net unreachable



CVS commit: src/usr.bin/netstat

2015-02-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb  8 15:09:45 UTC 2015

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

Log Message:
Allocate the right size for pcb blocks.
XXX: pullup-7!


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.67 -r1.68 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.105 src/usr.bin/netstat/inet.c:1.106
--- src/usr.bin/netstat/inet.c:1.105	Sat Feb  7 14:36:06 2015
+++ src/usr.bin/netstat/inet.c	Sun Feb  8 10:09:45 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.105 2015/02/07 19:36:06 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos 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.105 2015/02/07 19:36:06 christos Exp $);
+__RCSID($NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -286,7 +286,7 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size)) == NULL)
+	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
 		err(1, malloc);
 
 	i = 0;
@@ -317,7 +317,9 @@ getpcblist_kmem(u_long off, const char *
 		pcblist[i].ki_tstate = tcpcb.t_state;
 		pcblist[i].ki_pflags = inpcb.inp_flags;
 		if (i++ == size) {
-			struct kinfo_pcb *n = realloc(pcblist, size += 100);
+			size += 100;
+			struct kinfo_pcb *n = realloc(pcblist,
+			size * sizeof(*pcblist));
 			if (n == NULL)
 err(1, realloc);
 			pcblist = n;

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.67 src/usr.bin/netstat/inet6.c:1.68
--- src/usr.bin/netstat/inet6.c:1.67	Sat Feb  7 14:36:06 2015
+++ src/usr.bin/netstat/inet6.c	Sun Feb  8 10:09:45 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.67 2015/02/07 19:36:06 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos 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.67 2015/02/07 19:36:06 christos Exp $);
+__RCSID($NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -303,7 +303,7 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size)) == NULL)
+	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
 		err(1, malloc);
 
 	i = 0;
@@ -338,7 +338,9 @@ getpcblist_kmem(u_long off, const char *
 		memcpy(pcblist[i].ki_d, sin6, sizeof(sin6));
 		pcblist[i].ki_tstate = tcpcb.t_state;
 		if (i++ == size) {
-			struct kinfo_pcb *n = realloc(pcblist, size += 100);
+			size += 100;
+			struct kinfo_pcb *n = realloc(pcblist,
+			size * sizeof(*pcblist));
 			if (n == NULL)
 err(1, realloc);
 			pcblist = n;



CVS commit: src/usr.bin/netstat

2015-02-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb  7 19:36:06 UTC 2015

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

Log Message:
print the timer flags.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.66 -r1.67 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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.40 src/usr.bin/netstat/Makefile:1.41
--- src/usr.bin/netstat/Makefile:1.40	Thu Nov  6 16:30:09 2014
+++ src/usr.bin/netstat/Makefile	Sat Feb  7 14:36:06 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.40 2014/11/06 21:30:09 christos Exp $
+#	$NetBSD: Makefile,v 1.41 2015/02/07 19:36:06 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -11,8 +11,8 @@ SRCS=	atalk.c bpf.c fast_ipsec.c if.c in
 	unix.c vtw.c rtutil.c
 BINGRP=	kmem
 BINMODE=2555
-LDADD=	-lkvm
-DPADD=	${LIBKVM}
+LDADD=	-lutil -lkvm
+DPADD=	${LIBUTIL} ${LIBKVM}
 CPPFLAGS+= -DIPSEC -I${.CURDIR}
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
 CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.104 src/usr.bin/netstat/inet.c:1.105
--- src/usr.bin/netstat/inet.c:1.104	Sat Nov 23 17:01:12 2013
+++ src/usr.bin/netstat/inet.c	Sat Feb  7 14:36:06 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.104 2013/11/23 22:01:12 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.105 2015/02/07 19:36:06 christos 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.104 2013/11/23 22:01:12 christos Exp $);
+__RCSID($NetBSD: inet.c,v 1.105 2015/02/07 19:36:06 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -87,6 +87,7 @@ __RCSID($NetBSD: inet.c,v 1.104 2013/11
 #include unistd.h
 #include stdlib.h
 #include err.h
+#include util.h
 #include netstat.h
 #include vtw.h
 #include prog_ops.h
@@ -982,10 +983,14 @@ tcp_dump(u_long off, const char *name, u
 
 	printf(Timers:\n);
 	for (i = 0; i  TCPT_NTIMERS; i++) {
+		char buf[128];
 		ci = (callout_impl_t *)tcpcb.t_timer[i];
-		printf(\t%s: %d, tcptimers[i],
-		(ci-c_flags  CALLOUT_PENDING) ?
-		ci-c_time - hardticks : 0);
+		snprintb(buf, sizeof(buf), CALLOUT_FMT, ci-c_flags);
+		printf(\t%s\t%s, tcptimers[i], buf);
+		if (ci-c_flags  CALLOUT_PENDING)
+			printf(\t%d\n, ci-c_time - hardticks);
+		else
+			printf(\n);
 	}
 	printf(\n\n);
 

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.66 src/usr.bin/netstat/inet6.c:1.67
--- src/usr.bin/netstat/inet6.c:1.66	Sat Nov 23 17:01:12 2013
+++ src/usr.bin/netstat/inet6.c	Sat Feb  7 14:36:06 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.66 2013/11/23 22:01:12 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.67 2015/02/07 19:36:06 christos 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.66 2013/11/23 22:01:12 christos Exp $);
+__RCSID($NetBSD: inet6.c,v 1.67 2015/02/07 19:36:06 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -135,6 +135,7 @@ extern const char * const tcptimers[];
 #include stdlib.h
 #include string.h
 #include unistd.h
+#include util.h
 #include netstat.h
 #include vtw.h
 #include prog_ops.h
@@ -1468,10 +1469,14 @@ tcp6_dump(u_long off, const char *name, 
 	printf(TCP Protocol Control Block at 0x%08lx:\n\n, pcbaddr);
 	printf(Timers:\n);
 	for (i = 0; i  TCP6T_NTIMERS; i++) {
+		char buf[128];
 		ci = (callout_impl_t *)tcpcb.t_timer[i];
-		printf(\t%s: %d, tcptimers[i],
-		(ci-c_flags  CALLOUT_PENDING) ?
-		ci-c_time - hardticks : 0);
+		snprintb(buf, sizeof(buf), CALLOUT_FMT, ci-c_flags);
+		printf(\t%s\t%s, tcptimers[i], buf);
+		if (ci-c_flags  CALLOUT_PENDING)
+			printf(\t%d\n, ci-c_time - hardticks);
+		else
+			printf(\n);
 	}
 	printf(\n\n);
 



CVS commit: src/usr.bin/netstat

2015-01-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  7 22:43:01 UTC 2015

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
adjust to the netname4 prototype.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.80 src/usr.bin/netstat/if.c:1.81
--- src/usr.bin/netstat/if.c:1.80	Thu Nov  6 16:30:09 2014
+++ src/usr.bin/netstat/if.c	Wed Jan  7 17:43:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.80 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.80 2014/11/06 21:30:09 christos Exp $);
+__RCSID($NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -337,7 +337,7 @@ print_addr(struct sockaddr *sa, struct s
 	const int niflag = NI_NUMERICHOST;
 	struct sockaddr_in6 *sin6, *netmask6;
 #endif
-	in_addr_t netmask;
+	struct sockaddr_in netmask;
 	struct sockaddr_in *sin;
 	char *cp;
 	int n, m;
@@ -349,24 +349,13 @@ print_addr(struct sockaddr *sa, struct s
 		break;
 	case AF_INET:
 		sin = (struct sockaddr_in *)sa;
-#ifdef notdef
-		/*
-		 * can't use inet_makeaddr because kernel
-		 * keeps nets unshifted.
-		 */
-		in = inet_makeaddr(ifaddr.in.ia_subnet,
-			INADDR_ANY);
-		cp = netname4(in.s_addr,
-			ifaddr.in.ia_subnetmask, nflag);
-#else
 		if (use_sysctl) {
-			netmask = ((struct sockaddr_in *)rtinfo[RTAX_NETMASK])-sin_addr.s_addr;
+			netmask = *((struct sockaddr_in *)rtinfo[RTAX_NETMASK]);
 		} else {
 			struct in_ifaddr *ifaddr_in = (void *)rtinfo;
-			netmask = ifaddr_in-ia_subnetmask;
+			netmask.sin_addr.s_addr = ifaddr_in-ia_subnetmask;
 		}
-		cp = netname4(sin-sin_addr.s_addr, netmask, nflag);
-#endif
+		cp = netname4(sin, netmask, nflag);
 		if (vflag)
 			n = strlen(cp)  13 ? 13 : strlen(cp);
 		else



CVS commit: src/usr.bin/netstat

2014-11-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 12 03:34:59 UTC 2014

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
PR/47704: Takahiro HAYASHI: Fix -L flag


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.94 src/usr.bin/netstat/main.c:1.95
--- src/usr.bin/netstat/main.c:1.94	Fri Nov  7 07:42:27 2014
+++ src/usr.bin/netstat/main.c	Tue Nov 11 22:34:59 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.94 2014/11/07 12:42:27 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.94 2014/11/07 12:42:27 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.95 2014/11/12 03:34:59 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -454,7 +454,7 @@ main(int argc, char *argv[])
 			iflag = 1;
 			break;
 		case 'L':
-			Lflag = 1;
+			Lflag = RT_LFLAG;
 			break;
 		case 'l':
 			lflag = 1;
@@ -639,7 +639,7 @@ main(int argc, char *argv[])
 			else {
 if (use_sysctl)
 	p_rttables(af,
-	nflag|tagflag|vflag, 0, ~0);
+	nflag|tagflag|vflag|Lflag, 0, ~0);
 else
 	routepr(nl[N_RTREE].n_value);
 			}



CVS commit: src/usr.bin/netstat

2014-11-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov  7 12:42:27 UTC 2014

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
fix A,v,T with route display.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.93 src/usr.bin/netstat/main.c:1.94
--- src/usr.bin/netstat/main.c:1.93	Thu Nov  6 16:30:09 2014
+++ src/usr.bin/netstat/main.c	Fri Nov  7 07:42:27 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.93 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.94 2014/11/07 12:42:27 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.93 2014/11/06 21:30:09 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.94 2014/11/07 12:42:27 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -421,7 +421,7 @@ main(int argc, char *argv[])
 	AabBdf:ghI:LliM:mN:nP:p:qrsStTuVvw:X)) != -1)
 		switch (ch) {
 		case 'A':
-			Aflag = 1;
+			Aflag = RT_AFLAG;
 			break;
 		case 'a':
 			aflag = 1;
@@ -501,7 +501,7 @@ main(int argc, char *argv[])
 			tflag = 1;
 			break;
 		case 'T':
-			tagflag = 1;
+			tagflag = RT_TFLAG;
 			break;
 		case 'u':
 			af = AF_LOCAL;
@@ -510,7 +510,7 @@ main(int argc, char *argv[])
 			Vflag++;
 			break;
 		case 'v':
-			vflag++;
+			vflag = RT_VFLAG;
 			break;
 		case 'w':
 			interval = atoi(optarg);
@@ -638,7 +638,8 @@ main(int argc, char *argv[])
 rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
 			else {
 if (use_sysctl)
-	p_rttables(af, nflag, 0, ~0);
+	p_rttables(af,
+	nflag|tagflag|vflag, 0, ~0);
 else
 	routepr(nl[N_RTREE].n_value);
 			}



CVS commit: src/usr.bin/netstat

2014-11-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov  6 21:30:10 UTC 2014

Modified Files:
src/usr.bin/netstat: Makefile if.c main.c mroute.c mroute6.c netstat.h
route.c
Removed Files:
src/usr.bin/netstat: show.c

Log Message:
use the common code from route.c


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.20 -r0 src/usr.bin/netstat/show.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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.39 src/usr.bin/netstat/Makefile:1.40
--- src/usr.bin/netstat/Makefile:1.39	Fri Mar  1 13:26:11 2013
+++ src/usr.bin/netstat/Makefile	Thu Nov  6 16:30:09 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.39 2013/03/01 18:26:11 joerg Exp $
+#	$NetBSD: Makefile,v 1.40 2014/11/06 21:30:09 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -7,20 +7,22 @@ USE_FORT?= yes	# setgid
 
 RUMPPRG=netstat
 SRCS=	atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c \
-	main.c mbuf.c mroute.c mroute6.c pfkey.c pfsync.c show.c route.c \
-	unix.c vtw.c
+	main.c mbuf.c mroute.c mroute6.c pfkey.c pfsync.c route.c \
+	unix.c vtw.c rtutil.c
 BINGRP=	kmem
 BINMODE=2555
 LDADD=	-lkvm
 DPADD=	${LIBKVM}
-CPPFLAGS+= -DIPSEC
+CPPFLAGS+= -DIPSEC -I${.CURDIR}
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
+CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
 
 CWARNFLAGS.clang+=	-Wno-format
 COPTS.show.c += -Wno-format-nonliteral
 
 .PATH:  ${.CURDIR}/../../lib/libc/gen
 .PATH:  ${.CURDIR}/../../lib/libc/net
+.PATH:  ${.CURDIR}/../../sbin/route
 CPPFLAGS+= -DRUMP_ACTION
 RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c
 RUMPSRCS+= if_indextoname.c getifaddrs.c

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.79 src/usr.bin/netstat/if.c:1.80
--- src/usr.bin/netstat/if.c:1.79	Sat Oct 19 11:56:06 2013
+++ src/usr.bin/netstat/if.c	Thu Nov  6 16:30:09 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.79 2013/10/19 15:56:06 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.80 2014/11/06 21:30:09 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.79 2013/10/19 15:56:06 christos Exp $);
+__RCSID($NetBSD: if.c,v 1.80 2014/11/06 21:30:09 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -63,6 +63,7 @@ __RCSID($NetBSD: if.c,v 1.79 2013/10/19
 #include err.h
 
 #include netstat.h
+#include rtutil.h
 #include prog_ops.h
 
 #define	MAXIF	100
@@ -356,7 +357,7 @@ print_addr(struct sockaddr *sa, struct s
 		in = inet_makeaddr(ifaddr.in.ia_subnet,
 			INADDR_ANY);
 		cp = netname4(in.s_addr,
-			ifaddr.in.ia_subnetmask);
+			ifaddr.in.ia_subnetmask, nflag);
 #else
 		if (use_sysctl) {
 			netmask = ((struct sockaddr_in *)rtinfo[RTAX_NETMASK])-sin_addr.s_addr;
@@ -364,14 +365,14 @@ print_addr(struct sockaddr *sa, struct s
 			struct in_ifaddr *ifaddr_in = (void *)rtinfo;
 			netmask = ifaddr_in-ia_subnetmask;
 		}
-		cp = netname4(sin-sin_addr.s_addr, netmask);
+		cp = netname4(sin-sin_addr.s_addr, netmask, nflag);
 #endif
 		if (vflag)
 			n = strlen(cp)  13 ? 13 : strlen(cp);
 		else
 			n = 13;
 		printf(%-*.*s , n, n, cp);
-		cp = routename4(sin-sin_addr.s_addr);
+		cp = routename4(sin-sin_addr.s_addr, nflag);
 		if (vflag)
 			n = strlen(cp)  17 ? 17 : strlen(cp);
 		else
@@ -390,7 +391,7 @@ print_addr(struct sockaddr *sa, struct s
    sizeof inm);
 printf(\n%25s %-17.17s , ,
    routename4(
-  inm.inm_addr.s_addr));
+  inm.inm_addr.s_addr, nflag));
 multiaddr =
    (u_long)inm.inm_list.le_next;
 			}
@@ -412,7 +413,7 @@ print_addr(struct sockaddr *sa, struct s
 			netmask6 = ifaddr_in6-ia_prefixmask;
 		}
 
-		cp = netname6(sin6, netmask6);
+		cp = netname6(sin6, netmask6, nflag);
 		if (vflag)
 			n = strlen(cp)  13 ? 13 : strlen(cp);
 		else

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.92 src/usr.bin/netstat/main.c:1.93
--- src/usr.bin/netstat/main.c:1.92	Thu Oct  9 19:45:47 2014
+++ src/usr.bin/netstat/main.c	Thu Nov  6 16:30:09 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.92 2014/10/09 23:45:47 enami Exp $	*/
+/*	$NetBSD: main.c,v 1.93 2014/11/06 21:30:09 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.92 2014/10/09 23:45:47 enami Exp $);
+__RCSID($NetBSD: main.c,v 1.93 2014/11/06 21:30:09 

CVS commit: src/usr.bin/netstat

2014-10-11 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Sat Oct 11 06:25:32 UTC 2014

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
- Explicitly describe that kvm(3) is used when -M/-N option is used since
  nowadays sysctl(3) is the default information retrieval method.
- Fix description about default value for -N; it is no longer a single value
  these days, so just say see kvm_openfiles(3) rahter than repeating
  several lines description here.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.68 src/usr.bin/netstat/netstat.1:1.69
--- src/usr.bin/netstat/netstat.1:1.68	Thu Oct  9 23:52:47 2014
+++ src/usr.bin/netstat/netstat.1	Sat Oct 11 06:25:32 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.68 2014/10/09 23:52:47 enami Exp $
+.\	$NetBSD: netstat.1,v 1.69 2014/10/11 06:25:32 enami Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -223,15 +223,36 @@ and
 .Qq Group
 columns.
 .It Fl M
-Extract values associated with the name list from the specified core
-instead of the default
-.Pa /dev/mem .
+Use
+.Xr kvm 3
+instead of
+.Xr sysctl 3
+to retrieve information and
+extract values associated with the name list from the specified core.
+If
+.Fl M
+option is not given but
+.Fl N
+option is given, the default
+.Pa /dev/mem
+is used.
 .It Fl m
 Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
 .It Fl N
-Extract the name list from the specified system instead of the default
-.Pa /netbsd .
+Use
+.Xr kvm 3
+instead of
+.Xr sysctl 3
+to retrieve information and extract the name list from the specified system.
+For the default behavior when only
+.Fl M
+option is given, see the description about when
+.Fa execfile
+is
+.Dv NULL
+in
+.Xr kvm_openfiles 3 .
 .It Fl n
 Show network addresses and ports as numbers (normally
 .Nm



CVS commit: src/usr.bin/netstat

2014-10-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Oct 11 09:23:32 UTC 2014

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Give flag argument in description. Add two articles.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.69 src/usr.bin/netstat/netstat.1:1.70
--- src/usr.bin/netstat/netstat.1:1.69	Sat Oct 11 06:25:32 2014
+++ src/usr.bin/netstat/netstat.1	Sat Oct 11 09:23:32 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.69 2014/10/11 06:25:32 enami Exp $
+.\	$NetBSD: netstat.1,v 1.70 2014/10/11 09:23:32 wiz Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -222,16 +222,16 @@ option, display wider fields for the IPv
 and
 .Qq Group
 columns.
-.It Fl M
+.It Fl M Ar core
 Use
 .Xr kvm 3
 instead of
 .Xr sysctl 3
 to retrieve information and
 extract values associated with the name list from the specified core.
-If
+If the
 .Fl M
-option is not given but
+option is not given but the
 .Fl N
 option is given, the default
 .Pa /dev/mem
@@ -239,7 +239,7 @@ is used.
 .It Fl m
 Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
-.It Fl N
+.It Fl N Ar system
 Use
 .Xr kvm 3
 instead of



CVS commit: src/usr.bin/netstat

2014-10-09 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Thu Oct  9 23:45:47 UTC 2014

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Fix a bug introduced in rev. 1.62; it fails to negate (a  b).


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.91 src/usr.bin/netstat/main.c:1.92
--- src/usr.bin/netstat/main.c:1.91	Fri May 30 01:44:21 2014
+++ src/usr.bin/netstat/main.c	Thu Oct  9 23:45:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.91 2014/05/30 01:44:21 rmind Exp $	*/
+/*	$NetBSD: main.c,v 1.92 2014/10/09 23:45:47 enami Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.91 2014/05/30 01:44:21 rmind Exp $);
+__RCSID($NetBSD: main.c,v 1.92 2014/10/09 23:45:47 enami Exp $);
 #endif
 #endif /* not lint */
 
@@ -344,12 +344,17 @@ prepare(const char *nf, const char *mf, 
 	/*
 	 * Try to figure out if we can use sysctl or not.
 	 */
-	if (nf != NULL  mf != NULL) {
+	if (nf != NULL || mf != NULL) {
 		/* Of course, we can't use sysctl with dumps. */
 		if (force_sysctl)
 			errx(EXIT_FAILURE, can't use sysctl with dumps);
 
-		/* If we have -M and -N, we're not dealing with live memory. */
+		/*
+		 * If we have -M or -N, we're not dealing with live memory
+		 * or want to use kvm interface explicitly.  It is sometimes
+		 * useful to dig inside of kernel without extending
+		 * sysctl interface (i.e., without rebuilding kernel).
+		 */
 		use_sysctl = 0;
 	} else if (qflag ||
 		   iflag ||



CVS commit: src/usr.bin/netstat

2014-10-09 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Thu Oct  9 23:52:47 UTC 2014

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
As described in kvm_openfiles(3), default core file is not /dev/kmem
but /dev/mem.  Actually, passing /dev/kmem to -M doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.67 src/usr.bin/netstat/netstat.1:1.68
--- src/usr.bin/netstat/netstat.1:1.67	Fri Oct 18 22:18:14 2013
+++ src/usr.bin/netstat/netstat.1	Thu Oct  9 23:52:47 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.67 2013/10/18 22:18:14 bad Exp $
+.\	$NetBSD: netstat.1,v 1.68 2014/10/09 23:52:47 enami Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -225,7 +225,7 @@ columns.
 .It Fl M
 Extract values associated with the name list from the specified core
 instead of the default
-.Pa /dev/kmem .
+.Pa /dev/mem .
 .It Fl m
 Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
@@ -443,10 +443,10 @@ command appeared in
 .Bx 4.2 .
 IPv6 support was added by WIDE/KAME project.
 .\ .Sh FILES
-.\ .Bl -tag -width /dev/kmem -compact
+.\ .Bl -tag -width /dev/mem -compact
 .\ .It Pa /netbsd
 .\ default kernel namelist
-.\ .It Pa /dev/kmem
+.\ .It Pa /dev/mem
 .\ default memory file
 .\ .El
 .Sh BUGS



CVS commit: src/usr.bin/netstat

2014-07-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jul 27 04:26:23 UTC 2014

Modified Files:
src/usr.bin/netstat: show.c

Log Message:
Fix snprintf usage; from Henning Petersen in PR 47976.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/show.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/show.c
diff -u src/usr.bin/netstat/show.c:1.19 src/usr.bin/netstat/show.c:1.20
--- src/usr.bin/netstat/show.c:1.19	Mon Apr 28 15:41:15 2014
+++ src/usr.bin/netstat/show.c	Sun Jul 27 04:26:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.19 2014/04/28 15:41:15 christos Exp $	*/
+/*	$NetBSD: show.c,v 1.20 2014/07/27 04:26:23 dholland Exp $	*/
 /*	$OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $	*/
 
 /*
@@ -705,6 +705,7 @@ char *
 mpls_ntoa(const struct sockaddr *sa)
 {
 	static char obuf[16];
+	size_t olen;
 	const union mpls_shim *pms;
 	union mpls_shim ms;
 	int psize = sizeof(struct sockaddr_mpls);
@@ -717,7 +718,8 @@ mpls_ntoa(const struct sockaddr *sa)
 	while(psize  sa-sa_len) {
 		pms++;
 		ms.s_addr = ntohl(pms-s_addr);
-		snprintf(obuf, sizeof(obuf), %s,%u, obuf,
+		olen = strlen(obuf);
+		snprintf(obuf + olen, sizeof(obuf) - olen, ,%u,
 		ms.shim.label);
 		psize+=sizeof(ms);
 	}



CVS commit: src/usr.bin/netstat

2014-04-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 28 15:41:15 UTC 2014

Modified Files:
src/usr.bin/netstat: main.c netstat.h route.c show.c

Log Message:
use the same for the route metrics part, both in the sysctl and kmem paths.
From Takahiro HAYASHI


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/netstat/show.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/main.c
diff -u src/usr.bin/netstat/main.c:1.89 src/usr.bin/netstat/main.c:1.90
--- src/usr.bin/netstat/main.c:1.89	Thu Apr 24 10:56:29 2014
+++ src/usr.bin/netstat/main.c	Mon Apr 28 11:41:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.89 2014/04/24 14:56:29 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.90 2014/04/28 15:41:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.89 2014/04/24 14:56:29 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.90 2014/04/28 15:41:15 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -356,7 +356,6 @@ prepare(const char *nf, const char *mf, 
 #ifndef SMALL
 		   gflag ||
 #endif
-		   (rflag  vflag) ||
 		   (pflag  tp-pr_sindex == N_PIMSTAT) ||
 		   Pflag) {
 		/* These flags are not yet supported via sysctl(3). */

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.49 src/usr.bin/netstat/netstat.h:1.50
--- src/usr.bin/netstat/netstat.h:1.49	Thu Apr 24 10:54:51 2014
+++ src/usr.bin/netstat/netstat.h	Mon Apr 28 11:41:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.49 2014/04/24 14:54:51 christos Exp $	*/
+/*	$NetBSD: netstat.h,v 1.50 2014/04/28 15:41:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -116,6 +116,8 @@ void	impstats(u_long, u_long);
 
 void	pr_rthdr(int, int);
 void	pr_family(int);
+struct rt_metrics;
+void	pr_rtrmx(struct rt_metrics *);
 void	rt_stats(u_long);
 char	*ns_phost(struct sockaddr *);
 

Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.81 src/usr.bin/netstat/route.c:1.82
--- src/usr.bin/netstat/route.c:1.81	Thu Apr 24 10:56:29 2014
+++ src/usr.bin/netstat/route.c	Mon Apr 28 11:41:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.81 2014/04/24 14:56:29 christos Exp $	*/
+/*	$NetBSD: route.c,v 1.82 2014/04/28 15:41:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)route.c	8.3 (Berkeley) 3/9/94;
 #else
-__RCSID($NetBSD: route.c,v 1.81 2014/04/24 14:56:29 christos Exp $);
+__RCSID($NetBSD: route.c,v 1.82 2014/04/28 15:41:15 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -286,27 +286,26 @@ p_krtentry(struct rtentry *rt)
 			rt-rt_nodes[0].rn_dupedkey ?  = : );
 	}
 	putchar('\n');
- 	if (vflag) {
- 		printf(\texpire   %10PRId64%c  recvpipe %10PRIu64%c  
-		   sendpipe %10PRIu64%c\n,
- 			(int64_t)rt-rt_rmx.rmx_expire, 
- 			(rt-rt_rmx.rmx_locks  RTV_EXPIRE) ? 'L' : ' ',
- 			rt-rt_rmx.rmx_recvpipe,
- 			(rt-rt_rmx.rmx_locks  RTV_RPIPE) ? 'L' : ' ',
- 			rt-rt_rmx.rmx_sendpipe,
- 			(rt-rt_rmx.rmx_locks  RTV_SPIPE) ? 'L' : ' ');
- 		printf(\tssthresh %10PRIu64%c  rtt  %10PRIu64%c  
-		   rttvar   %10PRIu64%c\n,
- 			rt-rt_rmx.rmx_ssthresh, 
- 			(rt-rt_rmx.rmx_locks  RTV_SSTHRESH) ? 'L' : ' ',
- 			rt-rt_rmx.rmx_rtt, 
- 			(rt-rt_rmx.rmx_locks  RTV_RTT) ? 'L' : ' ',
- 			rt-rt_rmx.rmx_rttvar, 
-			(rt-rt_rmx.rmx_locks  RTV_RTTVAR) ? 'L' : ' ');
- 		printf(\thopcount %10PRIu64%c\n,
- 			rt-rt_rmx.rmx_hopcount, 
-			(rt-rt_rmx.rmx_locks  RTV_HOPCOUNT) ? 'L' : ' ');
- 	}
+	if (vflag)
+		pr_rtrmx(rt-rt_rmx);
+}
+
+void
+pr_rtrmx(struct rt_metrics *rmx)
+{
+	printf(\texpire   %10PRId64%c  recvpipe %10PRIu64%c  
+	sendpipe %10PRIu64%c\n,
+	(int64_t)rmx-rmx_expire, 
+	(rmx-rmx_locks  RTV_EXPIRE) ? 'L' : ' ', rmx-rmx_recvpipe,
+	(rmx-rmx_locks  RTV_RPIPE) ? 'L' : ' ', rmx-rmx_sendpipe,
+	(rmx-rmx_locks  RTV_SPIPE) ? 'L' : ' ');
+	printf(\tssthresh %10PRIu64%c  rtt  %10PRIu64%c  
+	rttvar   %10PRIu64%c\n, rmx-rmx_ssthresh, 
+	(rmx-rmx_locks  RTV_SSTHRESH) ? 'L' : ' ',
+	rmx-rmx_rtt, (rmx-rmx_locks  RTV_RTT) ? 'L' : ' ',
+	rmx-rmx_rttvar, (rmx-rmx_locks  RTV_RTTVAR) ? 'L' : ' ');
+	printf(\thopcount %10PRIu64%c\n,
+	rmx-rmx_hopcount, (rmx-rmx_locks  RTV_HOPCOUNT) ? 'L' : ' ');
 }
 
 /*

Index: src/usr.bin/netstat/show.c
diff -u src/usr.bin/netstat/show.c:1.18 src/usr.bin/netstat/show.c:1.19
--- src/usr.bin/netstat/show.c:1.18	Sat Oct 19 11:56:06 2013
+++ src/usr.bin/netstat/show.c	Mon Apr 28 11:41:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.18 2013/10/19 15:56:06 christos Exp $	*/
+/*	$NetBSD: show.c,v 1.19 2014/04/28 

CVS commit: src/usr.bin/netstat

2013-11-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov 23 22:01:12 UTC 2013

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

Log Message:
Update for new pcb tailq's.
While here fix ipv6 pcb printing by making tcp6_dump with tcp.
XXX: Merge the inet and the inet6 code. It is silly to need to specify
-p tcp6 to print a tcp6 pcb, we already know what it is.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/netstat/netstat.h

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.103 src/usr.bin/netstat/inet.c:1.104
--- src/usr.bin/netstat/inet.c:1.103	Thu Jun 20 06:43:18 2013
+++ src/usr.bin/netstat/inet.c	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.103 2013/06/20 10:43:18 martin Exp $	*/
+/*	$NetBSD: inet.c,v 1.104 2013/11/23 22:01:12 christos 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.103 2013/06/20 10:43:18 martin Exp $);
+__RCSID($NetBSD: inet.c,v 1.104 2013/11/23 22:01:12 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -265,7 +265,7 @@ getpcblist_sysctl(const char *name, size
 static struct kinfo_pcb *
 getpcblist_kmem(u_long off, const char *name, size_t *len) {
 	struct inpcbtable table;
-	struct inpcb *head, *next, *prev;
+	struct inpcb_hdr *next, *prev;
 	struct inpcb inpcb;
 	struct tcpcb tcpcb;
 	struct socket sockb;
@@ -273,6 +273,7 @@ getpcblist_kmem(u_long off, const char *
 	struct kinfo_pcb *pcblist;
 	size_t size = 100, i;
 	struct sockaddr_in sin; 
+	struct inpcbqueue *head;
 
 	if (off == 0) {
 		*len = 0;
@@ -280,22 +281,18 @@ getpcblist_kmem(u_long off, const char *
 	}
 
 	kread(off, (char *)table, sizeof table);
-	prev = head =
-	(struct inpcb *)((struct inpcbtable *)off)-inpt_queue.cqh_first;
-	next = (struct inpcb *)table.inpt_queue.cqh_first;
+	head = table.inpt_queue;
+	next = TAILQ_FIRST(head);
+	prev = TAILQ_END(head);
 
 	if ((pcblist = malloc(size)) == NULL)
 		err(1, malloc);
 
 	i = 0;
-	while (next != head) {
+	while (next != TAILQ_END(head)) {
 		kread((u_long)next, (char *)inpcb, sizeof inpcb);
-		if ((struct inpcb *)inpcb.inp_queue.cqe_prev != prev) {
-			warnx(bad pcb);
-			break;
-		}
 		prev = next;
-		next = (struct inpcb *)inpcb.inp_queue.cqe_next;
+		next = TAILQ_NEXT(inpcb, inp_queue);
 
 		if (inpcb.inp_af != AF_INET)
 			continue;
@@ -305,7 +302,7 @@ getpcblist_kmem(u_long off, const char *
 			kread((u_long)inpcb.inp_ppcb,
 			(char *)tcpcb, sizeof (tcpcb));
 		}
-		pcblist[i].ki_ppcbaddr = 
+		pcblist[i].ki_ppcbaddr =
 		istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
 		pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
 		pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.65 src/usr.bin/netstat/inet6.c:1.66
--- src/usr.bin/netstat/inet6.c:1.65	Sat Oct 19 11:56:06 2013
+++ src/usr.bin/netstat/inet6.c	Sat Nov 23 17:01:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.65 2013/10/19 15:56:06 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.66 2013/11/23 22:01:12 christos Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,10 +64,12 @@
 #if 0
 static char sccsid[] = @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
-__RCSID($NetBSD: inet6.c,v 1.65 2013/10/19 15:56:06 christos Exp $);
+__RCSID($NetBSD: inet6.c,v 1.66 2013/11/23 22:01:12 christos Exp $);
 #endif
 #endif /* not lint */
 
+#define _CALLOUT_PRIVATE
+
 #include sys/param.h
 #include sys/socket.h
 #include sys/socketvar.h
@@ -90,22 +92,26 @@ __RCSID($NetBSD: inet6.c,v 1.65 2013/10
 #include netinet6/in6_pcb.h
 #include netinet6/in6_var.h
 #ifdef TCP6
-#include netinet6/tcp6.h
-#include netinet6/tcp6_seq.h
+#include netinet/tcp6.h
+#include netinet/tcp6_seq.h
 #define TCP6STATES
-#include netinet6/tcp6_fsm.h
+#include netinet/tcp6_fsm.h
 #define TCP6TIMERS
-#include netinet6/tcp6_timer.h
-#include netinet6/tcp6_var.h
-#include netinet6/tcp6_debug.h
+#include netinet/tcp6_timer.h
+#include netinet/tcp6_var.h
+#include netinet/tcp6_debug.h
 #else
+#define TCP6T_NTIMERS	TCPT_NTIMERS
+#define tcp6timers tcptimers
+#define tcp6states tcpstates
+#define TCP6_NSTATES	TCP_NSTATES
+#define tcp6cb tcpcb
 #include netinet/tcp.h
 #include netinet/tcpip.h
 #include netinet/tcp_seq.h
-/*#define TCPSTATES*/
 #include netinet/tcp_fsm.h
 extern const char * const tcpstates[];
-/*#define	TCPTIMERS*/
+extern const char * const tcptimers[];
 #include netinet/tcp_timer.h
 #include netinet/tcp_var.h
 #include netinet/tcp_debug.h
@@ -280,33 +286,30 @@ static struct kinfo_pcb *
 getpcblist_kmem(u_long 

CVS commit: src/usr.bin/netstat

2013-10-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 18 20:26:45 UTC 2013

Modified Files:
src/usr.bin/netstat: atalk.c if.c inet6.c mroute6.c show.c vtw.c

Log Message:
- avoid pointer gymnastics
- remove unused variables


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/show.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/netstat/vtw.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/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.14 src/usr.bin/netstat/atalk.c:1.15
--- src/usr.bin/netstat/atalk.c:1.14	Sun Apr 12 12:08:37 2009
+++ src/usr.bin/netstat/atalk.c	Fri Oct 18 16:26:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.14 2009/04/12 16:08:37 lukem Exp $	*/
+/*	$NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from @(#)atalk.c	1.1 (Whistle) 6/6/96;
 #else
-__RCSID($NetBSD: atalk.c,v 1.14 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: atalk.c,v 1.15 2013/10/18 20:26:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -229,17 +229,16 @@ atalk_print2(const struct sockaddr *sa, 
 void
 atalkprotopr(u_long off, const char *name)
 {
-	struct ddpcbcb;
-	struct ddpcb *prev, *next;
-	struct ddpcb   *initial;
+	struct ddpcb cb;
+	struct ddpcb *next;
+	struct ddpcb *initial;
 	int width = 22;
 	if (off == 0)
 		return;
 	if (kread(off, (char *)initial, sizeof(struct ddpcb *))  0)
 		return;
 	ddpcb = cb;
-	prev = (struct ddpcb *)off;
-	for (next = initial; next != NULL; prev = next) {
+	for (next = initial; next != NULL;) {
 		u_long	ppcb = (u_long)next;
 
 		if (kread((u_long)next, (char *)ddpcb, sizeof(ddpcb))  0)

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.76 src/usr.bin/netstat/if.c:1.77
--- src/usr.bin/netstat/if.c:1.76	Fri Mar  1 13:26:11 2013
+++ src/usr.bin/netstat/if.c	Fri Oct 18 16:26:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.76 2013/03/01 18:26:11 joerg Exp $	*/
+/*	$NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.76 2013/03/01 18:26:11 joerg Exp $);
+__RCSID($NetBSD: if.c,v 1.77 2013/10/18 20:26:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -401,9 +401,10 @@ print_addr(struct sockaddr *sa, struct s
 		sin6 = (struct sockaddr_in6 *)sa;
 #ifdef __KAME__
 		if (IN6_IS_ADDR_LINKLOCAL(sin6-sin6_addr)) {
-			sin6-sin6_scope_id =
-ntohs(*(u_int16_t *)
-  sin6-sin6_addr.s6_addr[2]);
+			uint16_t scope;
+			memcpy(scope, sin6-sin6_addr.s6_addr[2],
+			sizeof(scope));
+			sin6-sin6_scope_id = ntohs(scope);
 			/* too little width */
 			if (!vflag)
 sin6-sin6_scope_id = 0;
@@ -455,9 +456,11 @@ print_addr(struct sockaddr *sa, struct s
 as6.sin6_addr = inm.in6m_addr;
 #ifdef __KAME__
 if (IN6_IS_ADDR_MC_LINKLOCAL(as6.sin6_addr)) {
-	as6.sin6_scope_id =
-	ntohs(*(u_int16_t *)
-		as6.sin6_addr.s6_addr[2]);
+	uint16_t scope;
+	memcpy(scope,
+	sin6-sin6_addr.s6_addr[2],
+	sizeof(scope));
+	as6.sin6_scope_id = ntohs(scope);
 	as6.sin6_addr.s6_addr[2] = 0;
 	as6.sin6_addr.s6_addr[3] = 0;
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.62 src/usr.bin/netstat/inet6.c:1.63
--- src/usr.bin/netstat/inet6.c:1.62	Thu Jun 20 06:43:18 2013
+++ src/usr.bin/netstat/inet6.c	Fri Oct 18 16:26:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.62 2013/06/20 10:43:18 martin Exp $	*/
+/*	$NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos 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.62 2013/06/20 10:43:18 martin Exp $);
+__RCSID($NetBSD: inet6.c,v 1.63 2013/10/18 20:26:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -1423,8 +1423,10 @@ inet6name(const struct in6_addr *in6p)
 #ifdef __KAME__
 		if (IN6_IS_ADDR_LINKLOCAL(in6p) ||
 		IN6_IS_ADDR_MC_LINKLOCAL(in6p)) {
-			sin6.sin6_scope_id =
-			ntohs(*(const u_int16_t *)in6p-s6_addr[2]);
+			uint16_t scope;
+			memcpy(scope, sin6.sin6_addr.s6_addr[2],
+			sizeof(scope));
+			sin6.sin6_scope_id = ntohs(scope);
 			sin6.sin6_addr.s6_addr[2] = 0;
 			sin6.sin6_addr.s6_addr[3] = 0;
 		}

Index: src/usr.bin/netstat/mroute6.c
diff -u src/usr.bin/netstat/mroute6.c:1.13 src/usr.bin/netstat/mroute6.c:1.14
--- src/usr.bin/netstat/mroute6.c:1.13	Tue Mar 20 16:34:58 2012
+++ src/usr.bin/netstat/mroute6.c	Fri Oct 18 16:26:45 2013
@@ -1,4 +1,4 @@

CVS commit: src/usr.bin/netstat

2013-10-18 Thread Christoph Badura
Module Name:src
Committed By:   bad
Date:   Fri Oct 18 22:18:14 UTC 2013

Modified Files:
src/usr.bin/netstat: main.c netstat.1

Log Message:
Make the -f option accept multiple address families.
Bump man page date.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/netstat/netstat.1

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/main.c
diff -u src/usr.bin/netstat/main.c:1.86 src/usr.bin/netstat/main.c:1.87
--- src/usr.bin/netstat/main.c:1.86	Wed Jun 19 21:12:03 2013
+++ src/usr.bin/netstat/main.c	Fri Oct 18 22:18:14 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.86 2013/06/19 21:12:03 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.87 2013/10/18 22:18:14 bad Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.86 2013/06/19 21:12:03 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.87 2013/10/18 22:18:14 bad Exp $);
 #endif
 #endif /* not lint */
 
@@ -395,6 +395,7 @@ main(int argc, char *argv[])
 	struct protox *tp;	/* for printing cblocks  stats */
 	int ch;
 	char *cp;
+	char *afname, *afnames;
 	u_long pcbaddr;
 
 	if (prog_init) {
@@ -407,6 +408,7 @@ main(int argc, char *argv[])
 	(void)setegid(getgid());
 	tp = NULL;
 	af = AF_UNSPEC;
+	afnames = NULL;
 	pcbaddr = 0;
 
 	while ((ch = getopt(argc, argv,
@@ -428,24 +430,7 @@ main(int argc, char *argv[])
 			dflag = 1;
 			break;
 		case 'f':
-			if (strcmp(optarg, inet) == 0)
-af = AF_INET;
-			else if (strcmp(optarg, inet6) == 0)
-af = AF_INET6;
-			else if (strcmp(optarg, arp) == 0)
-af = AF_ARP;
-			else if (strcmp(optarg, pfkey) == 0)
-af = PF_KEY;
-			else if (strcmp(optarg, unix) == 0
-			|| strcmp(optarg, local) == 0)
-af = AF_LOCAL;
-			else if (strcmp(optarg, atalk) == 0)
-af = AF_APPLETALK;
-			else if (strcmp(optarg, mpls) == 0)
-af = AF_MPLS;
-			else
-errx(1, %s: unknown address family,
-optarg);
+			afnames = optarg;
 			break;
 #ifndef SMALL
 		case 'g':
@@ -603,91 +588,124 @@ main(int argc, char *argv[])
 	 */
 	sethostent(1);
 	setnetent(1);
-	if (iflag) {
-		if (af != AF_UNSPEC)
-			goto protostat;
+	/*
+	 * If -f was used afnames != NULL, loop over the address families.
+	 * Otherwise do this at least once (with af == AF_UNSPEC).
+	 */
+	afname = NULL;
+	do {
+		if (afnames != NULL) {
+			afname = strsep(afnames, ,);
+			if (afname == NULL)
+break;		/* Exit early */
+			if (strcmp(afname, inet) == 0)
+af = AF_INET;
+			else if (strcmp(afname, inet6) == 0)
+af = AF_INET6;
+			else if (strcmp(afname, arp) == 0)
+af = AF_ARP;
+			else if (strcmp(afname, pfkey) == 0)
+af = PF_KEY;
+			else if (strcmp(afname, unix) == 0
+			|| strcmp(afname, local) == 0)
+af = AF_LOCAL;
+			else if (strcmp(afname, atalk) == 0)
+af = AF_APPLETALK;
+			else if (strcmp(afname, mpls) == 0)
+af = AF_MPLS;
+			else {
+warnx(%s: unknown address family,
+afname);
+continue;
+			}
+		}
 
-		intpr(interval, nl[N_IFNET].n_value, NULL);
-		exit(0);
-	}
-	if (rflag) {
-		if (sflag)
-			rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
-		else {
-			if (!use_sysctl)
-err(1, -r is not supported 
-for post-mortem analysis.);
-			p_rttables(af);
+		if (iflag) {
+			if (af != AF_UNSPEC)
+goto protostat;
+
+			intpr(interval, nl[N_IFNET].n_value, NULL);
+			break;
+		}
+		if (rflag) {
+			if (sflag)
+rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
+			else {
+if (!use_sysctl)
+	err(1, -r is not supported 
+	for post-mortem analysis.);
+p_rttables(af);
+			}
+			break;
 		}
-		exit(0);
-	}
 #ifndef SMALL
-	if (gflag) {
-		if (sflag) {
-			if (af == AF_INET || af == AF_UNSPEC)
-mrt_stats(nl[N_MRTPROTO].n_value,
-	  nl[N_MRTSTAT].n_value);
+		if (gflag) {
+			if (sflag) {
+if (af == AF_INET || af == AF_UNSPEC)
+	mrt_stats(nl[N_MRTPROTO].n_value,
+		  nl[N_MRTSTAT].n_value);
 #ifdef INET6
-			if (af == AF_INET6 || af == AF_UNSPEC)
-mrt6_stats(nl[N_MRT6PROTO].n_value,
-	   nl[N_MRT6STAT].n_value);
+if (af == AF_INET6 || af == AF_UNSPEC)
+	mrt6_stats(nl[N_MRT6PROTO].n_value,
+		   nl[N_MRT6STAT].n_value);
 #endif
-		}
-		else {
-			if (af == AF_INET || af == AF_UNSPEC)
-mroutepr(nl[N_MRTPROTO].n_value,
-	 nl[N_MFCHASHTBL].n_value,
-	 nl[N_MFCHASH].n_value,
-	 nl[N_VIFTABLE].n_value);
+			}
+			else {
+if (af == AF_INET || af == AF_UNSPEC)
+	mroutepr(nl[N_MRTPROTO].n_value,
+		 nl[N_MFCHASHTBL].n_value,
+		 nl[N_MFCHASH].n_value,
+		 nl[N_VIFTABLE].n_value);
 #ifdef INET6
-			if (af == AF_INET6 || af == AF_UNSPEC)
-mroute6pr(nl[N_MRT6PROTO].n_value,
-	  nl[N_MF6CTABLE].n_value,
-	  nl[N_MIF6TABLE].n_value);

CVS commit: src/usr.bin/netstat

2013-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 20 10:43:18 UTC 2013

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

Log Message:
Not all pointers are 64bit - use uintptr_t instead of uint64_t.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.61 -r1.62 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.102 src/usr.bin/netstat/inet.c:1.103
--- src/usr.bin/netstat/inet.c:1.102	Wed Jun 19 21:12:03 2013
+++ src/usr.bin/netstat/inet.c	Thu Jun 20 10:43:18 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.102 2013/06/19 21:12:03 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.103 2013/06/20 10:43:18 martin 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.102 2013/06/19 21:12:03 christos Exp $);
+__RCSID($NetBSD: inet.c,v 1.103 2013/06/20 10:43:18 martin Exp $);
 #endif
 #endif /* not lint */
 
@@ -306,7 +306,7 @@ getpcblist_kmem(u_long off, const char *
 			(char *)tcpcb, sizeof (tcpcb));
 		}
 		pcblist[i].ki_ppcbaddr = 
-		istcp ? (uint64_t) inpcb.inp_ppcb : (uint64_t) prev;
+		istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev;
 		pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
 		pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
 

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.61 src/usr.bin/netstat/inet6.c:1.62
--- src/usr.bin/netstat/inet6.c:1.61	Wed Jun 19 21:12:03 2013
+++ src/usr.bin/netstat/inet6.c	Thu Jun 20 10:43:18 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.61 2013/06/19 21:12:03 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.62 2013/06/20 10:43:18 martin 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.61 2013/06/19 21:12:03 christos Exp $);
+__RCSID($NetBSD: inet6.c,v 1.62 2013/06/20 10:43:18 martin Exp $);
 #endif
 #endif /* not lint */
 
@@ -323,7 +323,7 @@ getpcblist_kmem(u_long off, const char *
 #endif
 		}
 		pcblist[i].ki_ppcbaddr = 
-		istcp ? (uint64_t) in6pcb.in6p_ppcb : (uint64_t) prev;
+		istcp ? (uintptr_t) in6pcb.in6p_ppcb : (uintptr_t) prev;
 		pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc;
 		pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc;
 		sin6.sin6_addr = in6pcb.in6p_laddr;



CVS commit: src/usr.bin/netstat

2013-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun 19 21:12:03 UTC 2013

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

Log Message:
Don't use -P as a kmem printer, verify that the address points to a pcb first!


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/netstat/netstat.h

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.101 src/usr.bin/netstat/inet.c:1.102
--- src/usr.bin/netstat/inet.c:1.101	Sat Dec 24 15:18:35 2011
+++ src/usr.bin/netstat/inet.c	Wed Jun 19 17:12:03 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.101 2011/12/24 20:18:35 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.102 2013/06/19 21:12:03 christos 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.101 2011/12/24 20:18:35 christos Exp $);
+__RCSID($NetBSD: inet.c,v 1.102 2013/06/19 21:12:03 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -226,96 +226,72 @@ print_vtw_v4(const vtw_t *vtw)
 		 TCPS_TIME_WAIT, tcp, 0, vtw-expire);
 }
 
-void
-protopr(u_long off, const char *name)
-{
-	struct inpcbtable table;
-	struct inpcb *head, *next, *prev;
-	struct inpcb inpcb;
-	struct tcpcb tcpcb;
-	struct socket sockb;
-	int istcp = strcmp(name, tcp) == 0;
-	static int first = 1;
-
-	compact = 0;
-	if (Aflag) {
-		if (!numeric_addr)
-			width = 18;
-		else {
-			width = 21;
-			compact = 1;
-		}
-	} else
-		width = 22;
-
-	if (use_sysctl) {
-		struct kinfo_pcb *pcblist;
-		int mib[8];
-		size_t namelen = 0, size = 0, i;
-		char *mibname = NULL;
-
-		memset(mib, 0, sizeof(mib));
+struct kinfo_pcb *
+getpcblist_sysctl(const char *name, size_t *len) {
+	int mib[8];
+	size_t namelen = 0, size = 0;
+	char *mibname = NULL;
+	struct kinfo_pcb *pcblist;
 
-		if (asprintf(mibname, net.inet.%s.pcblist, name) == -1)
-			err(1, asprintf);
+	memset(mib, 0, sizeof(mib));
 
-		/* get dynamic pcblist node */
-		if (sysctlnametomib(mibname, mib, namelen) == -1)
-			err(1, sysctlnametomib: %s, mibname);
+	if (asprintf(mibname, net.inet%s.%s.pcblist, name + 3, name) == -1)
+		err(1, asprintf);
 
-		if (prog_sysctl(mib, __arraycount(mib),
-		NULL, size, NULL, 0) == -1)
-			err(1, sysctl (query));
+	/* get dynamic pcblist node */
+	if (sysctlnametomib(mibname, mib, namelen) == -1)
+		err(1, sysctlnametomib: %s, mibname);
 
-		if ((pcblist = malloc(size)) == NULL)
-			err(1, malloc);
-		memset(pcblist, 0, size);
+	free(mibname);
 
-	mib[6] = sizeof(*pcblist);
-	mib[7] = size / sizeof(*pcblist);
+	if (prog_sysctl(mib, __arraycount(mib), NULL, size, NULL, 0) == -1)
+		err(1, sysctl (query));
 
-		if (prog_sysctl(mib, __arraycount(mib),
-		pcblist, size, NULL, 0) == -1)
-			err(1, sysctl (copy));
+	if ((pcblist = malloc(size)) == NULL)
+		err(1, malloc);
+	memset(pcblist, 0, size);
 
-		for (i = 0; i  size / sizeof(*pcblist); i++) {
-			struct sockaddr_in src, dst;
+	mib[6] = sizeof(*pcblist);
+	mib[7] = size / sizeof(*pcblist);
 
-			memcpy(src, pcblist[i].ki_s, sizeof(src));
-			memcpy(dst, pcblist[i].ki_d, sizeof(dst));
+	if (prog_sysctl(mib, __arraycount(mib), pcblist, size, NULL, 0) == -1)
+		err(1, sysctl (copy));
 
-			if (!aflag 
-			inet_lnaof(dst.sin_addr) == INADDR_ANY)
-continue;
+	*len = size / sizeof(*pcblist);
+	return pcblist;
 
-			if (first) {
-protoprhdr();
-first = 0;
-			}
-
-	protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
- pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
- src.sin_addr, src.sin_port,
- dst.sin_addr, dst.sin_port,
- pcblist[i].ki_tstate, name,
- pcblist[i].ki_pflags, NULL);
-		}
+}
 
-		free(pcblist);
-		goto end;
+static struct kinfo_pcb *
+getpcblist_kmem(u_long off, const char *name, size_t *len) {
+	struct inpcbtable table;
+	struct inpcb *head, *next, *prev;
+	struct inpcb inpcb;
+	struct tcpcb tcpcb;
+	struct socket sockb;
+	int istcp = strcmp(name, tcp) == 0;
+	struct kinfo_pcb *pcblist;
+	size_t size = 100, i;
+	struct sockaddr_in sin; 
+
+	if (off == 0) {
+		*len = 0;
+		return NULL;
 	}
 
-	if (off == 0)
-		return;
 	kread(off, (char *)table, sizeof table);
 	prev = head =
 	(struct inpcb *)((struct inpcbtable *)off)-inpt_queue.cqh_first;
 	next = (struct inpcb *)table.inpt_queue.cqh_first;
 
+	if ((pcblist = malloc(size)) == NULL)
+		err(1, malloc);
+
+	i = 0;
 	while (next != head) {
 		kread((u_long)next, (char *)inpcb, sizeof inpcb);
 		if ((struct inpcb *)inpcb.inp_queue.cqe_prev != prev) {
-			printf(???\n);
+			warnx(bad pcb);
 			break;
 		}
 		prev = next;
@@ -324,28 +300,83 @@ protopr(u_long off, const char *name)
 		if (inpcb.inp_af != 

CVS commit: src/usr.bin/netstat

2013-04-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr 15 21:20:39 UTC 2013

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
PR/47744: Frank Kardel: netstat -s stops output prematurely when ipsec is not
compiled.
If the first sysctl fails return silently.
XXX: pullup-6


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/fast_ipsec.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/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.19 src/usr.bin/netstat/fast_ipsec.c:1.20
--- src/usr.bin/netstat/fast_ipsec.c:1.19	Thu Mar 22 16:34:43 2012
+++ src/usr.bin/netstat/fast_ipsec.c	Mon Apr 15 17:20:39 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.19 2012/03/22 20:34:43 drochner Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.20 2013/04/15 21:20:39 christos Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include sys/cdefs.h
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID($NetBSD: fast_ipsec.c,v 1.19 2012/03/22 20:34:43 drochner Exp $);
+__RCSID($NetBSD: fast_ipsec.c,v 1.20 2013/04/15 21:20:39 christos Exp $);
 #endif
 #endif /* not lint*/
 
@@ -152,8 +152,12 @@ fast_ipsec_stats(u_long off, const char 
 	slen = sizeof(ipsecstats);
 	status = sysctlbyname(net.inet.ipsec.ipsecstats, ipsecstats, slen,
 			  NULL, 0);
-	if (status  0  errno != ENOMEM)
-		err(1, net.inet.ipsec.ipsecstats);
+	if (status  0) {
+		if (errno == ENOENT)
+			return;
+		if (errno != ENOMEM)
+			err(1, net.inet.ipsec.ipsecstats);
+	}
 
 	slen = sizeof (ahstats);
 	status = sysctlbyname(net.inet.ah.ah_stats, ahstats, slen, NULL, 0);



CVS commit: src/usr.bin/netstat

2013-01-28 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Jan 28 13:49:09 UTC 2013

Modified Files:
src/usr.bin/netstat: main.c netstat.h route.c

Log Message:
Use sysctl based code netstat -r. Remove support for post-mortem
analysis.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/route.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/main.c
diff -u src/usr.bin/netstat/main.c:1.83 src/usr.bin/netstat/main.c:1.84
--- src/usr.bin/netstat/main.c:1.83	Thu Mar 22 20:34:43 2012
+++ src/usr.bin/netstat/main.c	Mon Jan 28 13:49:08 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.83 2012/03/22 20:34:43 drochner Exp $	*/
+/*	$NetBSD: main.c,v 1.84 2013/01/28 13:49:08 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT(@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.83 2012/03/22 20:34:43 drochner Exp $);
+__RCSID($NetBSD: main.c,v 1.84 2013/01/28 13:49:08 joerg Exp $);
 #endif
 #endif /* not lint */
 
@@ -393,7 +393,6 @@ prepare(const char *nf, const char *mf, 
 		/* If we have -M and -N, we're not dealing with live memory. */
 		use_sysctl = 0;
 	} else if (qflag ||
-		   rflag ||
 		   iflag ||
 #ifndef SMALL
 		   gflag ||
@@ -661,10 +660,10 @@ main(int argc, char *argv[])
 		if (sflag)
 			rt_stats(use_sysctl ? 0 : nl[N_RTSTAT].n_value);
 		else {
-			if (use_sysctl)
-p_rttables(af);
-			else
-routepr(nl[N_RTREE].n_value);
+			if (!use_sysctl)
+err(1, -r is not supported 
+for post-mortem analysis.);
+			p_rttables(af);
 		}
 		exit(0);
 	}

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.44 src/usr.bin/netstat/netstat.h:1.45
--- src/usr.bin/netstat/netstat.h:1.44	Thu Mar 22 20:34:43 2012
+++ src/usr.bin/netstat/netstat.h	Mon Jan 28 13:49:08 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.44 2012/03/22 20:34:43 drochner Exp $	*/
+/*	$NetBSD: netstat.h,v 1.45 2013/01/28 13:49:08 joerg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -118,7 +118,6 @@ void	pr_rthdr __P((int, int));
 void	pr_family __P((int));
 void	rt_stats __P((u_long));
 char	*ns_phost __P((struct sockaddr *));
-void	upHex __P((char *));
 
 void	p_rttables(int);
 void	p_flags(int, const char *);
@@ -139,7 +138,6 @@ const char *atalk_print __P((const struc
 const char *atalk_print2 __P((const struct sockaddr *, const struct sockaddr *,
 int));
 char	*ns_print __P((struct sockaddr *));
-void	routepr __P((u_long));
 
 void	nsprotopr __P((u_long, const char *));
 void	spp_stats __P((u_long, const char *));

Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.79 src/usr.bin/netstat/route.c:1.80
--- src/usr.bin/netstat/route.c:1.79	Tue Mar 20 20:34:58 2012
+++ src/usr.bin/netstat/route.c	Mon Jan 28 13:49:08 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.79 2012/03/20 20:34:58 matt Exp $	*/
+/*	$NetBSD: route.c,v 1.80 2013/01/28 13:49:08 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -30,287 +30,15 @@
  */
 
 #include sys/cdefs.h
-#ifndef lint
-#if 0
-static char sccsid[] = from: @(#)route.c	8.3 (Berkeley) 3/9/94;
-#else
-__RCSID($NetBSD: route.c,v 1.79 2012/03/20 20:34:58 matt Exp $);
-#endif
-#endif /* not lint */
 
-#include stdbool.h
-#include sys/param.h
-#include sys/protosw.h
-#include sys/socket.h
-#include sys/mbuf.h
-#include sys/un.h
-
-#include net/if.h
-#include net/if_dl.h
-#include net/if_types.h
-#include net/route.h
-#include netinet/in.h
-#include netatalk/at.h
-#include netiso/iso.h
-#include netmpls/mpls.h
+__RCSID($NetBSD: route.c,v 1.80 2013/01/28 13:49:08 joerg Exp $);
 
 #include sys/sysctl.h
-
-#include arpa/inet.h
-
+#include net/route.h
 #include err.h
-#include kvm.h
-#include netdb.h
-#include stdio.h
-#include stdlib.h
-#include string.h
-#include unistd.h
 
 #include netstat.h
 
-#define kget(p, d) (kread((u_long)(p), (char *)(d), sizeof (d)))
-
-/*
- * XXX we put all of the sockaddr types in here to force the alignment
- * to be correct.
- */
-static union sockaddr_union {
-	struct	sockaddr u_sa;
-	struct	sockaddr_in u_in;
-	struct	sockaddr_un u_un;
-	struct	sockaddr_iso u_iso;
-	struct	sockaddr_at u_at;
-	struct	sockaddr_dl u_dl;
-	u_short	u_data[128];
-	int u_dummy;		/* force word-alignment */
-} pt_u;
-
-int	do_rtent = 0;
-struct	rtentry rtentry;
-struct	radix_node rnode;
-struct	radix_mask rmask;
-
-static struct sockaddr *kgetsa(const struct sockaddr *);
-static void p_tree(struct radix_node *);
-static void p_rtnode(void);
-static void p_krtentry(struct rtentry *);
-
-/*
- * Print routing tables.
- */
-void
-routepr(u_long rtree)
-{
-	struct radix_node_head *rnh, head;
-	struct radix_node_head *rt_nodes[AF_MAX+1];
-	int i;
-
-	printf(Routing tables\n);
-

CVS commit: src/usr.bin/netstat

2012-12-14 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Dec 14 08:15:44 UTC 2012

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
Fix memory leak.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/netstat/bpf.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/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.10 src/usr.bin/netstat/bpf.c:1.11
--- src/usr.bin/netstat/bpf.c:1.10	Mon Dec 13 21:15:30 2010
+++ src/usr.bin/netstat/bpf.c	Fri Dec 14 08:15:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.10 2010/12/13 21:15:30 pooka Exp $	*/
+/*	$NetBSD: bpf.c,v 1.11 2012/12/14 08:15:44 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -167,6 +167,7 @@ bpf_dump(const char *bpfif)
 printf(%s\n, p.p_comm);
 #undef BPFEXT
 		}
+		free(v);
 	} else {
 /* XXX */
 errx(1, bpf_dump not implemented using kvm);



CVS commit: src/usr.bin/netstat

2012-10-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 19 19:50:19 UTC 2012

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Line up total numbers again (for -b case and -X case).


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.74 src/usr.bin/netstat/if.c:1.75
--- src/usr.bin/netstat/if.c:1.74	Tue Mar 20 20:34:58 2012
+++ src/usr.bin/netstat/if.c	Fri Oct 19 19:50:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.74 2012/03/20 20:34:58 matt Exp $	*/
+/*	$NetBSD: if.c,v 1.75 2012/10/19 19:50:19 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.74 2012/03/20 20:34:58 matt Exp $);
+__RCSID($NetBSD: if.c,v 1.75 2012/10/19 19:50:19 msaitoh Exp $);
 #endif
 #endif /* not lint */
 
@@ -601,11 +601,11 @@ static void
 iftot_print(struct iftot *cur, struct iftot *old)
 {
 	if (bflag)
-		printf(%10 PRIu64 %8.8s %10 PRIu64 %5.5s,
+		printf(%10 PRIu64  %8.8s %10 PRIu64  %5.5s,
 		cur-ift_ib - old-ift_ib,  ,
 		cur-ift_ob - old-ift_ob,  );
 	else
-		printf(%8 PRIu64 %5 PRIu64 %8 PRIu64 %5 PRIu64 %5 PRIu64,
+		printf(%8 PRIu64  %5 PRIu64  %8 PRIu64  %5 PRIu64  %5 PRIu64,
 		cur-ift_ip - old-ift_ip,
 		cur-ift_ie - old-ift_ie,
 		cur-ift_op - old-ift_op,
@@ -621,11 +621,11 @@ static void
 iftot_print_sum(struct iftot *cur, struct iftot *old)
 {
 	if (bflag)
-		printf(  %10 PRIu64 %8.8s %10 PRIu64 %5.5s,
+		printf(  %10 PRIu64  %8.8s %10 PRIu64  %5.5s,
 		cur-ift_ib - old-ift_ib,  ,
 		cur-ift_ob - old-ift_ob,  );
 	else
-		printf(  %8 PRIu64 %5 PRIu64 %8 PRIu64 %5 PRIu64 %5 PRIu64,
+		printf(  %8 PRIu64  %5 PRIu64  %8 PRIu64  %5 PRIu64  %5 PRIu64,
 		cur-ift_ip - old-ift_ip,
 		cur-ift_ie - old-ift_ie,
 		cur-ift_op - old-ift_op,



CVS commit: src/usr.bin/netstat

2012-10-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 19 20:43:31 UTC 2012

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Add note about -l option. Fixes PR#47085 reported by Julian Fagir.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.63 src/usr.bin/netstat/netstat.1:1.64
--- src/usr.bin/netstat/netstat.1:1.63	Tue Sep 25 14:16:27 2012
+++ src/usr.bin/netstat/netstat.1	Fri Oct 19 20:43:31 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.63 2012/09/25 14:16:27 pgoyette Exp $
+.\	$NetBSD: netstat.1,v 1.64 2012/10/19 20:43:31 msaitoh Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\
 .\	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\
-.Dd June 29, 2010
+.Dd October 20, 2012
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Nm
-.Op Fl bdghiLmnqrSsTv
+.Op Fl bdghilLmnqrSsTv
 .Op Fl f Ar address_family
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -216,6 +216,14 @@ or
 respectively.
 .It Fl L
 Don't show link-level routes (e.g., IPv4 ARP or IPv6 neighbour cache).
+.It Fl l
+With the
+.Fl g
+option, display wider fields for the IPv6 multicast routing table
+.Qq Origin
+and
+.Qq Group
+columns.
 .It Fl M
 Extract values associated with the name list from the specified core
 instead of the default



CVS commit: src/usr.bin/netstat

2012-10-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 19 20:46:06 UTC 2012

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Add -t flag.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.64 src/usr.bin/netstat/netstat.1:1.65
--- src/usr.bin/netstat/netstat.1:1.64	Fri Oct 19 20:43:31 2012
+++ src/usr.bin/netstat/netstat.1	Fri Oct 19 20:46:06 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.64 2012/10/19 20:43:31 msaitoh Exp $
+.\	$NetBSD: netstat.1,v 1.65 2012/10/19 20:46:06 msaitoh Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -42,7 +42,7 @@
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Nm
-.Op Fl bdghilLmnqrSsTv
+.Op Fl bdghiLlmnqrSsTtv
 .Op Fl f Ar address_family
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -279,6 +279,10 @@ If this option is repeated, counters wit
 Show MPLS Tags for the routing tables.
 If multiple tags exists, they will
 be comma separated, first tag being the BoS one.
+.It Fl t
+With the
+.Fl i
+option, display the current value of the watchdog timer function.
 .It Fl v
 Show extra (verbose) detail for the routing tables
 .Pq Fl r ,



CVS commit: src/usr.bin/netstat

2012-09-25 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Sep 25 14:16:27 UTC 2012

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Sort -h option properly (not between -I and -i)

XXX Should the date be updated?


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.62 src/usr.bin/netstat/netstat.1:1.63
--- src/usr.bin/netstat/netstat.1:1.62	Fri Nov 11 15:09:33 2011
+++ src/usr.bin/netstat/netstat.1	Tue Sep 25 14:16:27 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.62 2011/11/11 15:09:33 gdt Exp $
+.\	$NetBSD: netstat.1,v 1.63 2012/09/25 14:16:27 pgoyette Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -166,6 +166,14 @@ By default, show the IP Multicast virtua
 If the
 .Fl s
 option is also present, show multicast routing statistics.
+.It Fl h
+When used with
+.Fl b
+in combination with either
+.Fl i
+or
+.Fl I ,
+output human-readable byte counts.
 .It Fl I Ar interface
 Show information about the specified interface;
 used with a
@@ -184,14 +192,6 @@ for the specified
 or
 .Ar protocol ,
 respectively.
-.It Fl h
-When used with
-.Fl b
-in combination with either
-.Fl i
-or
-.Fl I ,
-output human-readable byte counts.
 .It Fl i
 Show the state of interfaces which have been auto-configured
 (interfaces statically configured into a system, but not



CVS commit: src/usr.bin/netstat

2012-02-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb 12 19:11:33 UTC 2012

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.72 src/usr.bin/netstat/if.c:1.73
--- src/usr.bin/netstat/if.c:1.72	Fri Sep 16 11:39:27 2011
+++ src/usr.bin/netstat/if.c	Sun Feb 12 14:11:33 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.72 2011/09/16 15:39:27 joerg Exp $	*/
+/*	$NetBSD: if.c,v 1.73 2012/02/12 19:11:33 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.72 2011/09/16 15:39:27 joerg Exp $);
+__RCSID($NetBSD: if.c,v 1.73 2012/02/12 19:11:33 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -83,7 +83,8 @@ struct	iftot {
 	int ift_dr;			/* drops */
 };
 
-static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *);
+static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *,
+struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
 
 static void iftot_banner(struct iftot *);
@@ -220,7 +221,7 @@ intpr_sysctl(void)
 			}
 
 			printf(%-5s %-5 PRIu64, name, ifd-ifi_mtu);
-			print_addr(rti_info[RTAX_IFP], rti_info, ifd);
+			print_addr(rti_info[RTAX_IFP], rti_info, ifd, NULL);
 			break;
 
 		case RTM_NEWADDR:
@@ -238,24 +239,26 @@ intpr_sysctl(void)
 			get_rtaddrs(ifam-ifam_addrs, sa, rti_info);
 
 			printf(%-5s %-5 PRIu64, name, ifd-ifi_mtu);
-			print_addr(rti_info[RTAX_IFA], rti_info, ifd);
+			print_addr(rti_info[RTAX_IFA], rti_info, ifd, NULL);
 			break;
 		}
 	}
 }
 
+union ifaddr_u {
+	struct ifaddr ifa;
+	struct in_ifaddr in;
+#ifdef INET6
+	struct in6_ifaddr in6;
+#endif /* INET6 */
+	struct iso_ifaddr iso;
+};
+
 static void
 intpr_kvm(u_long ifnetaddr, void (*pfunc)(const char *))
 {
 	struct ifnet ifnet;
-	union {
-		struct ifaddr ifa;
-		struct in_ifaddr in;
-#ifdef INET6
-		struct in6_ifaddr in6;
-#endif /* INET6 */
-		struct iso_ifaddr iso;
-	} ifaddr;
+	union ifaddr_u ifaddr;
 	u_long ifaddraddr;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
@@ -321,7 +324,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP(ifaddr);
 			sa = (struct sockaddr *)cp;
-			print_addr(sa, (void *)ifaddr, ifnet.if_data);
+			print_addr(sa, (void *)ifaddr, ifnet.if_data, ifnet);
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -329,7 +332,8 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
-print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd)
+print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
+struct ifnet *ifnet)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = %02x%c;	/* for hexprint */
@@ -380,13 +384,13 @@ print_addr(struct sockaddr *sa, struct s
 			n = 17;
 		printf(%-*.*s , n, n, cp);
 
-#if 0 /* XXX-elad */
-		if (aflag) {
+		if (aflag  ifnet) {
 			u_long multiaddr;
 			struct in_multi inm;
+			union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
 
 			multiaddr = (u_long)
-			ifaddr.in.ia_multiaddrs.lh_first;
+			ifaddr-in.ia_multiaddrs.lh_first;
 			while (multiaddr != 0) {
 kread(multiaddr, (char *)inm,
    sizeof inm);
@@ -397,7 +401,6 @@ print_addr(struct sockaddr *sa, struct s
    (u_long)inm.inm_list.le_next;
 			}
 		}
-#endif /* 0 */
 		break;
 #ifdef INET6
 	case AF_INET6:
@@ -441,14 +444,14 @@ print_addr(struct sockaddr *sa, struct s
 			n = 17;
 		printf(%-*.*s , n, n, cp);
 
-#if 0 /* XXX-elad */
-		if (aflag) {
+		if (aflag  ifnet) {
 			u_long multiaddr;
 			struct in6_multi inm;
 			struct sockaddr_in6 as6;
+			union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
 		
 			multiaddr = (u_long)
-			ifaddr.in6.ia6_multiaddrs.lh_first;
+			ifaddr-in6.ia6_multiaddrs.lh_first;
 			while (multiaddr != 0) {
 kread(multiaddr, (char *)inm,
    sizeof inm);
@@ -484,7 +487,6 @@ print_addr(struct sockaddr *sa, struct s
    (u_long)inm.in6m_entry.le_next;
 			}
 		}
-#endif /* 0 */
 		break;
 #endif /*INET6*/
 #ifndef SMALL
@@ -548,9 +550,9 @@ print_addr(struct sockaddr *sa, struct s
 			(unsigned long long)ifd-ifi_collisions);
 	}
 	if (tflag)
-		printf( %4d, 0 /* XXX-elad ifnet.if_timer */);
+		printf( %4d, ifnet ? ifnet-if_timer : 0);
 	if (dflag)
-		printf( %5d, 0 /* XXX-elad ifnet.if_snd.ifq_drops */);
+		printf( %5d, ifnet ? ifnet-if_snd.ifq_drops : 0);
 	putchar('\n');
 }
 



CVS commit: src/usr.bin/netstat

2012-01-06 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Fri Jan  6 14:21:17 UTC 2012

Modified Files:
src/usr.bin/netstat: Makefile ipsec.c
Added Files:
src/usr.bin/netstat: pfkey.c

Log Message:
split the ipsec.c source file into the pfkey part which is shared
with FAST_IPSEC and KAME specific IPSEC statistics


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/ipsec.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/netstat/pfkey.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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.36 src/usr.bin/netstat/Makefile:1.37
--- src/usr.bin/netstat/Makefile:1.36	Tue Aug 16 12:03:31 2011
+++ src/usr.bin/netstat/Makefile	Fri Jan  6 14:21:16 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.36 2011/08/16 12:03:31 christos Exp $
+#	$NetBSD: Makefile,v 1.37 2012/01/06 14:21:16 drochner Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -7,8 +7,8 @@ USE_FORT?= yes	# setgid
 
 RUMPPRG=netstat
 SRCS=	atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c ipsec.c iso.c \
-	main.c mbuf.c mroute.c mroute6.c pfsync.c show.c route.c tp_astring.c \
-	unix.c vtw.c
+	main.c mbuf.c mroute.c mroute6.c pfkey.c pfsync.c show.c route.c \
+	tp_astring.c unix.c vtw.c
 .PATH:	${NETBSDSRCDIR}/sys/netiso 
 BINGRP=	kmem
 BINMODE=2555

Index: src/usr.bin/netstat/ipsec.c
diff -u src/usr.bin/netstat/ipsec.c:1.15 src/usr.bin/netstat/ipsec.c:1.16
--- src/usr.bin/netstat/ipsec.c:1.15	Sun Apr 12 16:08:37 2009
+++ src/usr.bin/netstat/ipsec.c	Fri Jan  6 14:21:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.c,v 1.15 2009/04/12 16:08:37 lukem Exp $	*/
+/*	$NetBSD: ipsec.c,v 1.16 2012/01/06 14:21:16 drochner Exp $	*/
 /*	$KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $	*/
 
 /*
@@ -65,7 +65,7 @@
 static char sccsid[] = from: @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
 #ifdef __NetBSD__
-__RCSID($NetBSD: ipsec.c,v 1.15 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: ipsec.c,v 1.16 2012/01/06 14:21:16 drochner Exp $);
 #endif
 #endif
 #endif /* not lint */
@@ -79,7 +79,6 @@ __RCSID($NetBSD: ipsec.c,v 1.15 2009/04
 
 #ifdef IPSEC
 #include netinet6/ipsec.h
-#include netkey/keysock.h
 #endif
 
 #include err.h
@@ -130,18 +129,9 @@ static struct val2str ipsec_compnames[] 
 	{ -1, NULL },
 };
 
-static const char *pfkey_msgtypenames[] = {
-	reserved, getspi, update, add, delete,
-	get, acquire, register, expire, flush,
-	dump, x_promisc, x_pchange, x_spdupdate, x_spdadd,
-	x_spddelete, x_spdget, x_spdacquire, x_spddump, x_spdflush,
-	x_spdsetidx, x_spdexpire, x_spddelete2
-};
-
 static uint64_t ipsecstat[IPSEC_NSTATS];
 
 static void print_ipsecstats(void);
-static const char *pfkey_msgtype_names(int);
 static void ipsec_hist(const u_quad_t *, int, const struct val2str *,
 	size_t, const char *);
 
@@ -240,84 +230,4 @@ ipsec_stats(u_long off, const char *name
 	print_ipsecstats();
 }
 
-static const char *
-pfkey_msgtype_names(int x)
-{
-	const int max =
-	sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
-	static char buf[20];
-
-	if (x  max  pfkey_msgtypenames[x])
-		return pfkey_msgtypenames[x];
-	snprintf(buf, sizeof(buf), #%d, x);
-	return buf;
-}
-
-void
-pfkey_stats(u_long off, const char *name)
-{
-	uint64_t pfkeystat[PFKEY_NSTATS];
-	int first, type;
-
-	if (use_sysctl) {
-		size_t size = sizeof(pfkeystat);
-
-		if (sysctlbyname(net.key.stats, pfkeystat, size,
- NULL, 0) == -1)
-			return;
-	} else {
-		warnx(%s stats not available via KVM., name);
-		return;
-	}
-
-	printf (%s:\n, name);
-
-#define	p(f, m) if (pfkeystat[f] || sflag = 1) \
-printf(m, (unsigned long long)pfkeystat[f], plural(pfkeystat[f]))
-
-	/* userland - kernel */
-	p(PFKEY_STAT_OUT_TOTAL, \t%llu request%s sent from userland\n);
-	p(PFKEY_STAT_OUT_BYTES, \t%llu byte%s sent from userland\n);
-	for (first = 1, type = 0; type  256; type++) {
-		if (pfkeystat[PFKEY_STAT_OUT_MSGTYPE + type] == 0)
-			continue;
-		if (first) {
-			printf(\thistogram by message type:\n);
-			first = 0;
-		}
-		printf(\t\t%s: %llu\n, pfkey_msgtype_names(type),
-		(unsigned long long)pfkeystat[PFKEY_STAT_OUT_MSGTYPE + type]);
-	}
-	p(PFKEY_STAT_OUT_INVLEN, \t%llu message%s with invalid length field\n);
-	p(PFKEY_STAT_OUT_INVVER, \t%llu message%s with invalid version field\n);
-	p(PFKEY_STAT_OUT_INVMSGTYPE, \t%llu message%s with invalid message type field\n);
-	p(PFKEY_STAT_OUT_TOOSHORT, \t%llu message%s too short\n);
-	p(PFKEY_STAT_OUT_NOMEM, \t%llu message%s with memory allocation failure\n);
-	p(PFKEY_STAT_OUT_DUPEXT, \t%llu message%s with duplicate extension\n);
-	p(PFKEY_STAT_OUT_INVEXTTYPE, \t%llu message%s with invalid extension type\n);
-	p(PFKEY_STAT_OUT_INVSATYPE, \t%llu message%s with invalid sa type\n);
-	p(PFKEY_STAT_OUT_INVADDR, \t%llu message%s with invalid address extension\n);
-
-	/* kernel - userland 

CVS commit: src/usr.bin/netstat

2011-10-04 Thread Sergey Svishchev
Module Name:src
Committed By:   shattered
Date:   Tue Oct  4 21:12:40 UTC 2011

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

Log Message:
PR/43968 -- add 'segqlen' of TCPCB to 'netstat -P'.

OK by wiz@


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/inet.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.99 src/usr.bin/netstat/inet.c:1.100
--- src/usr.bin/netstat/inet.c:1.99	Wed May 11 22:21:59 2011
+++ src/usr.bin/netstat/inet.c	Tue Oct  4 21:12:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.99 2011/05/11 22:21:59 dyoung Exp $	*/
+/*	$NetBSD: inet.c,v 1.100 2011/10/04 21:12:40 shattered 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.99 2011/05/11 22:21:59 dyoung Exp $);
+__RCSID($NetBSD: inet.c,v 1.100 2011/10/04 21:12:40 shattered Exp $);
 #endif
 #endif /* not lint */
 
@@ -976,8 +976,8 @@ tcp_dump(u_long pcbaddr)
 
 	printf(rxtshift %d, rxtcur %d, dupacks %d\n, tcpcb.t_rxtshift,
 	tcpcb.t_rxtcur, tcpcb.t_dupacks);
-	printf(peermss %u, ourmss %u, segsz %u\n\n, tcpcb.t_peermss,
-	tcpcb.t_ourmss, tcpcb.t_segsz);
+printf(peermss %u, ourmss %u, segsz %u, segqlen %u\n\n,
+	tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
 
 	printf(snd_una %u, snd_nxt %u, snd_up %u\n,
 	tcpcb.snd_una, tcpcb.snd_nxt, tcpcb.snd_up);



CVS commit: src/usr.bin/netstat

2011-08-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 16 12:03:32 UTC 2011

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
document non-literal format strings


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/Makefile

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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.35 src/usr.bin/netstat/Makefile:1.36
--- src/usr.bin/netstat/Makefile:1.35	Thu May 26 08:56:33 2011
+++ src/usr.bin/netstat/Makefile	Tue Aug 16 08:03:31 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.35 2011/05/26 12:56:33 joerg Exp $
+#	$NetBSD: Makefile,v 1.36 2011/08/16 12:03:31 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -18,6 +18,8 @@
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
 
 CWARNFLAGS.clang+=	-Wno-format
+COPTS.iso.c += -Wno-format-nonliteral
+COPTS.show.c += -Wno-format-nonliteral
 
 .PATH:  ${.CURDIR}/../../lib/libc/gen
 .PATH:  ${.CURDIR}/../../lib/libc/net



CVS commit: src/usr.bin/netstat

2011-07-17 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Sun Jul 17 10:22:08 UTC 2011

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Use errx() to display kvm_openfiles error message, the provided buffer
already has it.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.79 src/usr.bin/netstat/main.c:1.80
--- src/usr.bin/netstat/main.c:1.79	Wed May  4 01:13:35 2011
+++ src/usr.bin/netstat/main.c	Sun Jul 17 10:22:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.79 2011/05/04 01:13:35 dyoung Exp $	*/
+/*	$NetBSD: main.c,v 1.80 2011/07/17 10:22:07 njoly Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.79 2011/05/04 01:13:35 dyoung Exp $);
+__RCSID($NetBSD: main.c,v 1.80 2011/07/17 10:22:07 njoly Exp $);
 #endif
 #endif /* not lint */
 
@@ -363,7 +363,7 @@
 	if (kvmd != NULL)
 		return kvmd;
 	if ((kvmd = prepare_kvmd(nlistf, memf, buf)) == NULL)
-		err(1, kvm error: %s, buf);
+		errx(1, kvm error: %s, buf);
 	return kvmd;
 }
 
@@ -423,7 +423,7 @@
 	if (!use_sysctl) {
 
 		if (kvmd == NULL)
-			err(1, kvm error: %s, buf);
+			errx(1, kvm error: %s, buf);
 		if (kvm_nlist(kvmd, nl)  0 || nl[0].n_type == 0) {
 			if (nf)
 errx(1, %s: no namelist, nf);



CVS commit: src/usr.bin/netstat

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jun 21 19:46:36 UTC 2011

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
add a sentence regarding multiple tags


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.59 src/usr.bin/netstat/netstat.1:1.60
--- src/usr.bin/netstat/netstat.1:1.59	Mon Dec  6 09:28:38 2010
+++ src/usr.bin/netstat/netstat.1	Tue Jun 21 19:46:36 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.59 2010/12/06 09:28:38 pooka Exp $
+.\	$NetBSD: netstat.1,v 1.60 2011/06/21 19:46:36 kefren Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -268,7 +268,8 @@
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
 .It Fl T
-Show MPLS Tags for the routing tables.
+Show MPLS Tags for the routing tables. If multiple tags exists, they will
+be comma separated, first tag being the BoS one.
 .It Fl v
 Show extra (verbose) detail for the routing tables
 .Pq Fl r ,



CVS commit: src/usr.bin/netstat

2011-06-21 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jun 21 20:51:27 UTC 2011

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.60 src/usr.bin/netstat/netstat.1:1.61
--- src/usr.bin/netstat/netstat.1:1.60	Tue Jun 21 19:46:36 2011
+++ src/usr.bin/netstat/netstat.1	Tue Jun 21 20:51:27 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.60 2011/06/21 19:46:36 kefren Exp $
+.\	$NetBSD: netstat.1,v 1.61 2011/06/21 20:51:27 wiz Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -268,7 +268,8 @@
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
 .It Fl T
-Show MPLS Tags for the routing tables. If multiple tags exists, they will
+Show MPLS Tags for the routing tables.
+If multiple tags exists, they will
 be comma separated, first tag being the BoS one.
 .It Fl v
 Show extra (verbose) detail for the routing tables



CVS commit: src/usr.bin/netstat

2011-05-23 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Mon May 23 14:29:56 UTC 2011

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
report aes-ctr statistic counter by name


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/fast_ipsec.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/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.14 src/usr.bin/netstat/fast_ipsec.c:1.15
--- src/usr.bin/netstat/fast_ipsec.c:1.14	Thu May  5 17:49:47 2011
+++ src/usr.bin/netstat/fast_ipsec.c	Mon May 23 14:29:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.14 2011/05/05 17:49:47 drochner Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.15 2011/05/23 14:29:55 drochner Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include sys/cdefs.h
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID($NetBSD: fast_ipsec.c,v 1.14 2011/05/05 17:49:47 drochner Exp $);
+__RCSID($NetBSD: fast_ipsec.c,v 1.15 2011/05/23 14:29:55 drochner Exp $);
 #endif
 #endif /* not lint*/
 
@@ -127,6 +127,7 @@
 	{ SADB_X_EALG_BLOWFISHCBC, blowfish-cbc, },
 	{ SADB_X_EALG_RIJNDAELCBC, aes-cbc, },
 	{ SADB_X_EALG_CAMELLIACBC, camellia-cbc, },
+	{ SADB_X_EALG_AESCTR,	aes-ctr, },
 };
 static const struct alg ipcompalgs[] = {
 	{ SADB_X_CALG_NONE,	none, },



CVS commit: src/usr.bin/netstat

2011-05-11 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May 11 22:21:59 UTC 2011

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

Log Message:
Suppress whitespace at EOL to fix lib/librumphijack/t_tcpip.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.57 -r1.58 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.98 src/usr.bin/netstat/inet.c:1.99
--- src/usr.bin/netstat/inet.c:1.98	Wed May 11 15:08:59 2011
+++ src/usr.bin/netstat/inet.c	Wed May 11 22:21:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.98 2011/05/11 15:08:59 drochner Exp $	*/
+/*	$NetBSD: inet.c,v 1.99 2011/05/11 22:21:59 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.98 2011/05/11 15:08:59 drochner Exp $);
+__RCSID($NetBSD: inet.c,v 1.99 2011/05/11 22:21:59 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -116,11 +116,13 @@
 	putchar('\n');
 	if (Aflag)
 		printf(%-8.8s , PCB);
-	printf(%-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %-13.13s%s\n,
+	printf(
+	Vflag ? %-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %-13.13s Expires\n
+	  : %-5.5s %-6.6s %-6.6s %s%-*.*s %-*.*s %s\n,
 		Proto, Recv-Q, Send-Q, compact ?  :  ,
 		width, width, Local Address,
 		width, width, Foreign Address,
-		State, Vflag ?  Expires : );
+		State);
 }
 
 static void

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.57 src/usr.bin/netstat/inet6.c:1.58
--- src/usr.bin/netstat/inet6.c:1.57	Wed May 11 15:08:59 2011
+++ src/usr.bin/netstat/inet6.c	Wed May 11 22:21:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.57 2011/05/11 15:08:59 drochner Exp $	*/
+/*	$NetBSD: inet6.c,v 1.58 2011/05/11 22:21:59 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.57 2011/05/11 15:08:59 drochner Exp $);
+__RCSID($NetBSD: inet6.c,v 1.58 2011/05/11 22:21:59 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -173,11 +173,12 @@
 		printf(%-8.8s , PCB);
 		width = 18;
 	}
-	printf( %-5.5s %-6.6s %-6.6s  %*.*s %*.*s %-13.13s%s\n,
+	printf(
+	Vflag ? %-5.5s %-6.6s %-6.6s  %*.*s %*.*s %-13.13s Expires\n
+	  : %-5.5s %-6.6s %-6.6s  %*.*s %*.*s %s\n,
 	Proto, Recv-Q, Send-Q,
 	-width, width, Local Address,
-	-width, width, Foreign Address,
-	(state), Vflag ?  Expires : );
+	-width, width, Foreign Address, (state));
 }
 
 static void



CVS commit: src/usr.bin/netstat

2011-05-09 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Tue May 10 04:40:16 UTC 2011

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Use ptrdiff_t to hold pointer difference to avoid coredump on LP64 system.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.4 src/usr.bin/netstat/vtw.c:1.5
--- src/usr.bin/netstat/vtw.c:1.4	Wed May  4 03:43:30 2011
+++ src/usr.bin/netstat/vtw.c	Tue May 10 04:40:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.4 2011/05/04 03:43:30 pgoyette Exp $	*/
+/*	$NetBSD: vtw.c,v 1.5 2011/05/10 04:40:16 enami Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = from: @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
-__RCSID($NetBSD: vtw.c,v 1.4 2011/05/04 03:43:30 pgoyette Exp $);
+__RCSID($NetBSD: vtw.c,v 1.5 2011/05/10 04:40:16 enami Exp $);
 #endif
 #endif /* not lint */
 
@@ -251,7 +251,7 @@
 	for (i = 0; i  VTW_NCLASS; ++i) {
 		vtw_v4_t *kbase, *klim;
 		vtw_v4_t *ubase, *ulim;
-		int delta;
+		ptrdiff_t delta;
 
 		kbase = vtw_tcpv4[i].base.v4;
 		klim = vtw_tcpv4[i].lim.v4;
@@ -354,7 +354,7 @@
 	for (i = 0; i  VTW_NCLASS; ++i) {
 		vtw_v6_t *kbase, *klim;
 		vtw_v6_t *ubase, *ulim;
-		int delta;
+		ptrdiff_t delta;
 
 		kbase = vtw_tcpv6[i].base.v6;
 		klim = vtw_tcpv6[i].lim.v6;



CVS commit: src/usr.bin/netstat

2011-05-05 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Thu May  5 17:49:48 UTC 2011

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
decode camellia-cbc in stats histogram


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/fast_ipsec.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/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.13 src/usr.bin/netstat/fast_ipsec.c:1.14
--- src/usr.bin/netstat/fast_ipsec.c:1.13	Tue Apr 19 18:34:39 2011
+++ src/usr.bin/netstat/fast_ipsec.c	Thu May  5 17:49:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.13 2011/04/19 18:34:39 drochner Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.14 2011/05/05 17:49:47 drochner Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include sys/cdefs.h
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID($NetBSD: fast_ipsec.c,v 1.13 2011/04/19 18:34:39 drochner Exp $);
+__RCSID($NetBSD: fast_ipsec.c,v 1.14 2011/05/05 17:49:47 drochner Exp $);
 #endif
 #endif /* not lint*/
 
@@ -126,6 +126,7 @@
 	{ SADB_X_EALG_CAST128CBC, cast128-cbc, },
 	{ SADB_X_EALG_BLOWFISHCBC, blowfish-cbc, },
 	{ SADB_X_EALG_RIJNDAELCBC, aes-cbc, },
+	{ SADB_X_EALG_CAMELLIACBC, camellia-cbc, },
 };
 static const struct alg ipcompalgs[] = {
 	{ SADB_X_CALG_NONE,	none, },



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
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)



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  4 00:55:20 UTC 2011

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

Log Message:
Don't use type qualifier 'register'.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.55 src/usr.bin/netstat/inet6.c:1.56
--- src/usr.bin/netstat/inet6.c:1.55	Tue May  3 23:36:26 2011
+++ src/usr.bin/netstat/inet6.c	Wed May  4 00:55:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.55 2011/05/03 23:36:26 dyoung Exp $	*/
+/*	$NetBSD: inet6.c,v 1.56 2011/05/04 00:55:19 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.55 2011/05/03 23:36:26 dyoung Exp $);
+__RCSID($NetBSD: inet6.c,v 1.56 2011/05/04 00:55:19 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -1123,7 +1123,7 @@
 icmp6_stats(u_long off, const char *name)
 {
 	uint64_t icmp6stat[ICMP6_NSTATS];
-	register int i, first;
+	int i, first;
 
 	if (use_sysctl) {
 		size_t size = sizeof(icmp6stat);
@@ -1386,7 +1386,7 @@
 char *
 inet6name(const struct in6_addr *in6p)
 {
-	register char *cp;
+	char *cp;
 	static char line[NI_MAXHOST];
 	struct hostent *hp;
 	static char domain[MAXHOSTNAMELEN + 1];



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  4 01:11:29 UTC 2011

Modified Files:
src/usr.bin/netstat: unix.c

Log Message:
Access the kvm_t using get_kvmd(), only.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/netstat/unix.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/unix.c
diff -u src/usr.bin/netstat/unix.c:1.31 src/usr.bin/netstat/unix.c:1.32
--- src/usr.bin/netstat/unix.c:1.31	Mon Dec 13 21:15:30 2010
+++ src/usr.bin/netstat/unix.c	Wed May  4 01:11:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix.c,v 1.31 2010/12/13 21:15:30 pooka Exp $	*/
+/*	$NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)unix.c	8.1 (Berkeley) 6/6/93;
 #else
-__RCSID($NetBSD: unix.c,v 1.31 2010/12/13 21:15:30 pooka Exp $);
+__RCSID($NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -73,7 +73,6 @@
 
 static struct	file *file, *fileNFILE;
 static int	ns_nfiles;
-extern	kvm_t *kvmd;
 
 static void
 unixdomainprhdr(void)
@@ -210,9 +209,9 @@
 			goto again;
 		}
 	} else {
-		filebuf = (char *)kvm_getfiles(kvmd, KERN_FILE, 0, ns_nfiles);
+		filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, 0, ns_nfiles);
 		if (filebuf == 0) {
-			printf(file table read error: %s, kvm_geterr(kvmd));
+			printf(file table read error: %s, kvm_geterr(get_kvmd()));
 			return;
 		}
 		file = (struct file *)(filebuf + sizeof(fp));



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  4 01:13:35 UTC 2011

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Always try to open kmem, do not always set use_sysctl to 1, and do not
fail if opening kmem fails unless !use_sysctl.  Fixes netstat(1) options
such as -s.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/netstat/main.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/main.c
diff -u src/usr.bin/netstat/main.c:1.78 src/usr.bin/netstat/main.c:1.79
--- src/usr.bin/netstat/main.c:1.78	Tue May  3 18:28:46 2011
+++ src/usr.bin/netstat/main.c	Wed May  4 01:13:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.78 2011/05/03 18:28:46 dyoung Exp $	*/
+/*	$NetBSD: main.c,v 1.79 2011/05/04 01:13:35 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.78 2011/05/03 18:28:46 dyoung Exp $);
+__RCSID($NetBSD: main.c,v 1.79 2011/05/04 01:13:35 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -348,9 +348,9 @@
 static struct protox *name2protox __P((const char *));
 static struct protox *knownname __P((const char *));
 static void prepare(const char *, const char *, struct protox *tp);
-static kvm_t *prepare_kvmd(const char *, const char *);
+static kvm_t *prepare_kvmd(const char *, const char *, char *);
 
-kvm_t *kvmd = NULL;
+static kvm_t *kvmd = NULL;
 gid_t egid;
 int interval;	/* repeat interval for i/f stats */
 static const char *nlistf = NULL, *memf = NULL;
@@ -358,27 +358,30 @@
 kvm_t *
 get_kvmd(void)
 {
-	return prepare_kvmd(nlistf, memf);
+	char buf[_POSIX2_LINE_MAX];
+
+	if (kvmd != NULL)
+		return kvmd;
+	if ((kvmd = prepare_kvmd(nlistf, memf, buf)) == NULL)
+		err(1, kvm error: %s, buf);
+	return kvmd;
 }
 
 static kvm_t *
-prepare_kvmd(const char *nf, const char *mf)
+prepare_kvmd(const char *nf, const char *mf, char *errbuf)
 {
-	char buf[_POSIX2_LINE_MAX];
+	kvm_t *k;
 
-	if (kvmd != NULL)
-		return kvmd;
 	(void)setegid(egid);
-	kvmd = kvm_openfiles(nf, mf, NULL, O_RDONLY, buf);
+	k = kvm_openfiles(nf, mf, NULL, O_RDONLY, errbuf);
 	(void)setgid(getgid());
-	if (kvmd == NULL)
-		err(1, kvm error: %s, buf);
-	return kvmd;
+	return k;
 }
 
 void
 prepare(const char *nf, const char *mf, struct protox *tp)
 {
+	char buf[_POSIX2_LINE_MAX];
 	/*
 	 * Try to figure out if we can use sysctl or not.
 	 */
@@ -389,7 +392,7 @@
 
 		/* If we have -M and -N, we're not dealing with live memory. */
 		use_sysctl = 0;
-	} else if (true || qflag ||
+	} else if (qflag ||
 		   rflag ||
 		   iflag ||
 #ifndef SMALL
@@ -415,9 +418,12 @@
 		use_sysctl = 1;
 	}
 
+	kvmd = prepare_kvmd(nf, mf, buf);
+
 	if (!use_sysctl) {
-		kvmd = prepare_kvmd(nf, mf);
 
+		if (kvmd == NULL)
+			err(1, kvm error: %s, buf);
 		if (kvm_nlist(kvmd, nl)  0 || nl[0].n_type == 0) {
 			if (nf)
 errx(1, %s: no namelist, nf);



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  4 01:30:01 UTC 2011

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Use %zu format for size_t instead of %x.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.1 src/usr.bin/netstat/vtw.c:1.2
--- src/usr.bin/netstat/vtw.c:1.1	Tue May  3 18:28:46 2011
+++ src/usr.bin/netstat/vtw.c	Wed May  4 01:30:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.1 2011/05/03 18:28:46 dyoung Exp $	*/
+/*	$NetBSD: vtw.c,v 1.2 2011/05/04 01:30:01 dyoung Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = from: @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
-__RCSID($NetBSD: vtw.c,v 1.1 2011/05/03 18:28:46 dyoung Exp $);
+__RCSID($NetBSD: vtw.c,v 1.2 2011/05/04 01:30:01 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,7 @@
 	cc = kvm_read(get_kvmd(), (unsigned long) addr, buf, len);
 
 	if (cc != len) {
-		warnx(%s: short read at %p, len %x cc %x\n, __func__, addr,
+		warnx(%s: short read at %p, len %x cc %zu\n, __func__, addr,
 		len, cc);
 	}
 }



CVS commit: src/usr.bin/netstat

2011-05-03 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  4 01:31:40 UTC 2011

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
On second thought, make a more conservative change: use %zx instead of
%x for size_t.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.2 src/usr.bin/netstat/vtw.c:1.3
--- src/usr.bin/netstat/vtw.c:1.2	Wed May  4 01:30:01 2011
+++ src/usr.bin/netstat/vtw.c	Wed May  4 01:31:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.2 2011/05/04 01:30:01 dyoung Exp $	*/
+/*	$NetBSD: vtw.c,v 1.3 2011/05/04 01:31:40 dyoung Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = from: @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
-__RCSID($NetBSD: vtw.c,v 1.2 2011/05/04 01:30:01 dyoung Exp $);
+__RCSID($NetBSD: vtw.c,v 1.3 2011/05/04 01:31:40 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,7 @@
 	cc = kvm_read(get_kvmd(), (unsigned long) addr, buf, len);
 
 	if (cc != len) {
-		warnx(%s: short read at %p, len %x cc %zu\n, __func__, addr,
+		warnx(%s: short read at %p, len %x cc %zx\n, __func__, addr,
 		len, cc);
 	}
 }



CVS commit: src/usr.bin/netstat

2011-05-03 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed May  4 03:43:30 UTC 2011

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Use %zx for _both_ size_t formats!


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/vtw.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/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.3 src/usr.bin/netstat/vtw.c:1.4
--- src/usr.bin/netstat/vtw.c:1.3	Wed May  4 01:31:40 2011
+++ src/usr.bin/netstat/vtw.c	Wed May  4 03:43:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.3 2011/05/04 01:31:40 dyoung Exp $	*/
+/*	$NetBSD: vtw.c,v 1.4 2011/05/04 03:43:30 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = from: @(#)inet.c	8.4 (Berkeley) 4/20/94;
 #else
-__RCSID($NetBSD: vtw.c,v 1.3 2011/05/04 01:31:40 dyoung Exp $);
+__RCSID($NetBSD: vtw.c,v 1.4 2011/05/04 03:43:30 pgoyette Exp $);
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,7 @@
 	cc = kvm_read(get_kvmd(), (unsigned long) addr, buf, len);
 
 	if (cc != len) {
-		warnx(%s: short read at %p, len %x cc %zx\n, __func__, addr,
+		warnx(%s: short read at %p, len %zx cc %zx\n, __func__, addr,
 		len, cc);
 	}
 }



CVS commit: src/usr.bin/netstat

2011-04-19 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Tue Apr 19 18:34:39 UTC 2011

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
fix some labels for ipcomp counters which didn't make sense at all


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/fast_ipsec.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/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.12 src/usr.bin/netstat/fast_ipsec.c:1.13
--- src/usr.bin/netstat/fast_ipsec.c:1.12	Sun Apr 12 16:08:37 2009
+++ src/usr.bin/netstat/fast_ipsec.c	Tue Apr 19 18:34:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.12 2009/04/12 16:08:37 lukem Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.13 2011/04/19 18:34:39 drochner Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include sys/cdefs.h
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID($NetBSD: fast_ipsec.c,v 1.12 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: fast_ipsec.c,v 1.13 2011/04/19 18:34:39 drochner Exp $);
 #endif
 #endif /* not lint*/
 
@@ -309,14 +309,14 @@
 
 	IPCOMP(ipcs[IPCOMP_STAT_HDROPS],packets too short for header length);
 	IPCOMP(ipcs[IPCOMP_STAT_NOPF],	protocol family not supported);
-	IPCOMP(ipcs[IPCOMP_STAT_NOTDB],	not db);
+	IPCOMP(ipcs[IPCOMP_STAT_NOTDB],	packets with no SA);
 	IPCOMP(ipcs[IPCOMP_STAT_BADKCR],packets dropped by crypto returning NULL mbuf);
 	IPCOMP(ipcs[IPCOMP_STAT_QFULL],	queue full);
 IPCOMP(ipcs[IPCOMP_STAT_NOXFORM],no support for transform);
 	IPCOMP(ipcs[IPCOMP_STAT_WRAP],  packets dropped for replay counter wrap);
 	IPCOMP(ipcs[IPCOMP_STAT_INPUT],	input IPcomp packets);
 	IPCOMP(ipcs[IPCOMP_STAT_OUTPUT],output IPcomp packets);
-	IPCOMP(ipcs[IPCOMP_STAT_INVALID],specified an invalid TDB);
+	IPCOMP(ipcs[IPCOMP_STAT_INVALID],packets with an invalid SA);
 	IPCOMP(ipcs[IPCOMP_STAT_TOOBIG],packets decompressed as too big);
 	IPCOMP(ipcs[IPCOMP_STAT_MINLEN], packets too short to be compressed);
 	IPCOMP(ipcs[IPCOMP_STAT_USELESS],packet for which compression was useless);



CVS commit: src/usr.bin/netstat

2011-03-02 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed Mar  2 19:52:04 UTC 2011

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

Log Message:
Use __arraycount() and PRIu64.  Delete unnecessary casts to unsigned
long long.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/netstat/inet.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.94 src/usr.bin/netstat/inet.c:1.95
--- src/usr.bin/netstat/inet.c:1.94	Tue Mar  1 19:01:59 2011
+++ src/usr.bin/netstat/inet.c	Wed Mar  2 19:52:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.94 2011/03/01 19:01:59 dyoung Exp $	*/
+/*	$NetBSD: inet.c,v 1.95 2011/03/02 19:52:03 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.94 2011/03/01 19:01:59 dyoung Exp $);
+__RCSID($NetBSD: inet.c,v 1.95 2011/03/02 19:52:03 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -193,7 +193,7 @@
 		if (sysctlnametomib(mibname, mib, namelen) == -1)
 			err(1, sysctlnametomib: %s, mibname);
 
-		if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+		if (prog_sysctl(mib, __arraycount(mib),
 		NULL, size, NULL, 0) == -1)
 			err(1, sysctl (query));
 
@@ -204,7 +204,7 @@
 	mib[6] = sizeof(*pcblist);
 	mib[7] = size / sizeof(*pcblist);
 
-		if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+		if (prog_sysctl(mib, __arraycount(mib),
 		pcblist, size, NULL, 0) == -1)
 			err(1, sysctl (copy));
 
@@ -299,102 +299,102 @@
 	printf (%s:\n, name);
 
 #define	ps(f, m) if (tcpstat[f] || sflag = 1) \
-printf(m, (unsigned long long)tcpstat[f])
+printf(m, tcpstat[f])
 #define	p(f, m) if (tcpstat[f] || sflag = 1) \
-printf(m, (unsigned long long)tcpstat[f], plural(tcpstat[f]))
+printf(m, tcpstat[f], plural(tcpstat[f]))
 #define	p2(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag = 1) \
-printf(m, (unsigned long long)tcpstat[f1], plural(tcpstat[f1]), \
-(unsigned long long)tcpstat[f2], plural(tcpstat[f2]))
+printf(m, tcpstat[f1], plural(tcpstat[f1]), \
+tcpstat[f2], plural(tcpstat[f2]))
 #define	p2s(f1, f2, m) if (tcpstat[f1] || tcpstat[f2] || sflag = 1) \
-printf(m, (unsigned long long)tcpstat[f1], plural(tcpstat[f1]), \
-(unsigned long long)tcpstat[f2])
+printf(m, tcpstat[f1], plural(tcpstat[f1]), \
+tcpstat[f2])
 #define	p3(f, m) if (tcpstat[f] || sflag = 1) \
-printf(m, (unsigned long long)tcpstat[f], plurales(tcpstat[f]))
+printf(m, tcpstat[f], plurales(tcpstat[f]))
 
-	p(TCP_STAT_SNDTOTAL, \t%llu packet%s sent\n);
+	p(TCP_STAT_SNDTOTAL, \t% PRIu64  packet%s sent\n);
 	p2(TCP_STAT_SNDPACK,TCP_STAT_SNDBYTE,
-		\t\t%llu data packet%s (%llu byte%s)\n);
+		\t\t% PRIu64  data packet%s (% PRIu64  byte%s)\n);
 	p2(TCP_STAT_SNDREXMITPACK, TCP_STAT_SNDREXMITBYTE,
-		\t\t%llu data packet%s (%llu byte%s) retransmitted\n);
+		\t\t% PRIu64  data packet%s (% PRIu64  byte%s) retransmitted\n);
 	p2s(TCP_STAT_SNDACKS, TCP_STAT_DELACK,
-		\t\t%llu ack-only packet%s (%llu delayed)\n);
-	p(TCP_STAT_SNDURG, \t\t%llu URG only packet%s\n);
-	p(TCP_STAT_SNDPROBE, \t\t%llu window probe packet%s\n);
-	p(TCP_STAT_SNDWINUP, \t\t%llu window update packet%s\n);
-	p(TCP_STAT_SNDCTRL, \t\t%llu control packet%s\n);
+		\t\t% PRIu64  ack-only packet%s (% PRIu64  delayed)\n);
+	p(TCP_STAT_SNDURG, \t\t% PRIu64  URG only packet%s\n);
+	p(TCP_STAT_SNDPROBE, \t\t% PRIu64  window probe packet%s\n);
+	p(TCP_STAT_SNDWINUP, \t\t% PRIu64  window update packet%s\n);
+	p(TCP_STAT_SNDCTRL, \t\t% PRIu64  control packet%s\n);
 	p(TCP_STAT_SELFQUENCH,
-	\t\t%llu send attempt%s resulted in self-quench\n);
-	p(TCP_STAT_RCVTOTAL, \t%llu packet%s received\n);
+	\t\t% PRIu64  send attempt%s resulted in self-quench\n);
+	p(TCP_STAT_RCVTOTAL, \t% PRIu64  packet%s received\n);
 	p2(TCP_STAT_RCVACKPACK, TCP_STAT_RCVACKBYTE,
-		\t\t%llu ack%s (for %llu byte%s)\n);
-	p(TCP_STAT_RCVDUPACK, \t\t%llu duplicate ack%s\n);
-	p(TCP_STAT_RCVACKTOOMUCH, \t\t%llu ack%s for unsent data\n);
+		\t\t% PRIu64  ack%s (for % PRIu64  byte%s)\n);
+	p(TCP_STAT_RCVDUPACK, \t\t% PRIu64  duplicate ack%s\n);
+	p(TCP_STAT_RCVACKTOOMUCH, \t\t% PRIu64  ack%s for unsent data\n);
 	p2(TCP_STAT_RCVPACK, TCP_STAT_RCVBYTE,
-		\t\t%llu packet%s (%llu byte%s) received in-sequence\n);
+		\t\t% PRIu64  packet%s (% PRIu64  byte%s) received in-sequence\n);
 	p2(TCP_STAT_RCVDUPPACK, TCP_STAT_RCVDUPBYTE,
-		\t\t%llu completely duplicate packet%s (%llu byte%s)\n);
-	p(TCP_STAT_PAWSDROP, \t\t%llu old duplicate packet%s\n);
+		\t\t% PRIu64  completely duplicate packet%s (% PRIu64  byte%s)\n);
+	p(TCP_STAT_PAWSDROP, \t\t% PRIu64  old duplicate packet%s\n);
 	p2(TCP_STAT_RCVPARTDUPPACK, TCP_STAT_RCVPARTDUPBYTE,
-		\t\t%llu packet%s with some dup. data (%llu byte%s duped)\n);
+		\t\t% PRIu64  packet%s with 

CVS commit: src/usr.bin/netstat

2011-03-01 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Tue Mar  1 19:01:59 UTC 2011

Modified Files:
src/usr.bin/netstat: Makefile inet.c
Added Files:
src/usr.bin/netstat: pfsync.c

Log Message:
Pull pfsync_stats() out of inet.c and into pfsync.c so that inet.c does
not have to #include PF header files that pollute the global namespace
by #defining v4 and v6 (sheesh).


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/netstat/inet.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/netstat/pfsync.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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.32 src/usr.bin/netstat/Makefile:1.33
--- src/usr.bin/netstat/Makefile:1.32	Wed Dec 15 11:22:41 2010
+++ src/usr.bin/netstat/Makefile	Tue Mar  1 19:01:59 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.32 2010/12/15 11:22:41 pooka Exp $
+#	$NetBSD: Makefile,v 1.33 2011/03/01 19:01:59 dyoung Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -7,7 +7,7 @@
 
 RUMPPRG=netstat
 SRCS=	atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c ipsec.c iso.c \
-	main.c mbuf.c mroute.c mroute6.c show.c route.c tp_astring.c \
+	main.c mbuf.c mroute.c mroute6.c pfsync.c show.c route.c tp_astring.c \
 	unix.c
 .PATH:	${NETBSDSRCDIR}/sys/netiso 
 BINGRP=	kmem

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.93 src/usr.bin/netstat/inet.c:1.94
--- src/usr.bin/netstat/inet.c:1.93	Mon Dec 13 21:15:30 2010
+++ src/usr.bin/netstat/inet.c	Tue Mar  1 19:01:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.93 2010/12/13 21:15:30 pooka Exp $	*/
+/*	$NetBSD: inet.c,v 1.94 2011/03/01 19:01:59 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.93 2010/12/13 21:15:30 pooka Exp $);
+__RCSID($NetBSD: inet.c,v 1.94 2011/03/01 19:01:59 dyoung Exp $);
 #endif
 #endif /* not lint */
 
@@ -76,8 +76,6 @@
 #include netinet/udp.h
 #include netinet/ip_carp.h
 #include netinet/udp_var.h
-#include net/pfvar.h
-#include net/if_pfsync.h
 
 #include arpa/inet.h
 #include kvm.h
@@ -690,52 +688,6 @@
 }
 
 /*
- * Dump PFSYNC statistics structure.
- */
-void
-pfsync_stats(u_long off, const char *name)
-{
-	uint64_t pfsyncstat[PFSYNC_NSTATS];
-
-	if (use_sysctl) {
-		size_t size = sizeof(pfsyncstat);
-
-		if (sysctlbyname(net.inet.pfsync.stats, pfsyncstat, size,
- NULL, 0) == -1)
-			return;
-	} else {
-		warnx(%s stats not available via KVM., name);
-		return;
-	}
-
-	printf(%s:\n, name);
-
-#define p(f, m) if (pfsyncstat[f] || sflag = 1) \
-	printf(m, pfsyncstat[f], plural(pfsyncstat[f]))
-#define p2(f, m) if (pfsyncstat[f] || sflag = 1) \
-	printf(m, pfsyncstat[f])
-
-	p(PFSYNC_STAT_IPACKETS, \t% PRIu64  packet%s received (IPv4)\n);
-	p(PFSYNC_STAT_IPACKETS6,\t% PRIu64  packet%s received (IPv6)\n);
-	p(PFSYNC_STAT_BADIF, \t\t% PRIu64  packet%s discarded for bad interface\n);
-	p(PFSYNC_STAT_BADTTL, \t\t% PRIu64  packet%s discarded for bad ttl\n);
-	p(PFSYNC_STAT_HDROPS, \t\t% PRIu64  packet%s shorter than header\n);
-	p(PFSYNC_STAT_BADVER, \t\t% PRIu64  packet%s discarded for bad version\n);
-	p(PFSYNC_STAT_BADAUTH, \t\t% PRIu64  packet%s discarded for bad HMAC\n);
-	p(PFSYNC_STAT_BADACT,\t\t% PRIu64  packet%s discarded for bad action\n);
-	p(PFSYNC_STAT_BADLEN, \t\t% PRIu64  packet%s discarded for short packet\n);
-	p(PFSYNC_STAT_BADVAL, \t\t% PRIu64  state%s discarded for bad values\n);
-	p(PFSYNC_STAT_STALE, \t\t% PRIu64  stale state%s\n);
-	p(PFSYNC_STAT_BADSTATE, \t\t% PRIu64  failed state lookup/insert%s\n);
-	p(PFSYNC_STAT_OPACKETS, \t% PRIu64  packet%s sent (IPv4)\n);
-	p(PFSYNC_STAT_OPACKETS6, \t% PRIu64  packet%s sent (IPv6)\n);
-	p2(PFSYNC_STAT_ONOMEM, \t\t% PRIu64  send failed due to mbuf memory error\n);
-	p2(PFSYNC_STAT_OERRORS, \t\t% PRIu64  send error\n);
-#undef p
-#undef p2
-}
-
-/*
  * Dump PIM statistics structure.
  */
 void

Added files:

Index: src/usr.bin/netstat/pfsync.c
diff -u /dev/null src/usr.bin/netstat/pfsync.c:1.1
--- /dev/null	Tue Mar  1 19:01:59 2011
+++ src/usr.bin/netstat/pfsync.c	Tue Mar  1 19:01:59 2011
@@ -0,0 +1,119 @@
+/*	$NetBSD: pfsync.c,v 1.1 2011/03/01 19:01:59 dyoung Exp $	*/
+
+/*
+ * Copyright (c) 1983, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other 

CVS commit: src/usr.bin/netstat

2010-12-15 Thread Havard Eidnes
Module Name:src
Committed By:   he
Date:   Wed Dec 15 09:15:05 UTC 2010

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
Make this build with CRUNCHEDPROG defined, and default to the sysctl()
method of fetching information.  Apparently we can't simply not define
the prog_ops struct in this program.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/netstat/Makefile

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/Makefile
diff -u src/usr.bin/netstat/Makefile:1.30 src/usr.bin/netstat/Makefile:1.31
--- src/usr.bin/netstat/Makefile:1.30	Mon Dec 13 21:15:30 2010
+++ src/usr.bin/netstat/Makefile	Wed Dec 15 09:15:05 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.30 2010/12/13 21:15:30 pooka Exp $
+#	$NetBSD: Makefile,v 1.31 2010/12/15 09:15:05 he Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include bsd.own.mk
@@ -23,6 +23,10 @@
 RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c
 RUMPSRCS+= if_indextoname.c getifaddrs.c
 
+.if defined(CRUNCHEDPROG)
+SRCS+=	netstat_hostops.c
+.endif
+
 .if (${USE_INET6} != no)
 CPPFLAGS+= -DINET6
 .endif



CVS commit: src/usr.bin/netstat

2010-12-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Dec  6 09:28:38 UTC 2010

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Insert word mbuf to description of -m (so you can search for it).
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.58 src/usr.bin/netstat/netstat.1:1.59
--- src/usr.bin/netstat/netstat.1:1.58	Wed Jun 30 07:30:16 2010
+++ src/usr.bin/netstat/netstat.1	Mon Dec  6 09:28:38 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.58 2010/06/30 07:30:16 wiz Exp $
+.\	$NetBSD: netstat.1,v 1.59 2010/12/06 09:28:38 pooka Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -221,7 +221,7 @@
 instead of the default
 .Pa /dev/kmem .
 .It Fl m
-Show statistics recorded by the memory management routines
+Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
 .It Fl N
 Extract the name list from the specified system instead of the default



CVS commit: src/usr.bin/netstat

2010-07-09 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Fri Jul  9 07:04:31 UTC 2010

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Line up total numbers again.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.68 src/usr.bin/netstat/if.c:1.69
--- src/usr.bin/netstat/if.c:1.68	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/if.c	Fri Jul  9 07:04:30 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.68 2010/02/24 11:00:27 pooka Exp $	*/
+/*	$NetBSD: if.c,v 1.69 2010/07/09 07:04:30 enami Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.68 2010/02/24 11:00:27 pooka Exp $);
+__RCSID($NetBSD: if.c,v 1.69 2010/07/09 07:04:30 enami Exp $);
 #endif
 #endif /* not lint */
 
@@ -869,9 +869,9 @@
 			if (hflag  humanize_number(humbuf,
 			sizeof(humbuf), sum-ift_ib - total-ift_ib, ,
 			HN_AUTOSCALE, HN_NOSPACE | HN_B)  0)
-printf(%10s %8.8s , humbuf,  );
+printf(  %10s %8.8s , humbuf,  );
 			else
-printf(%10llu %8.8s , 
+printf(  %10llu %8.8s , 
 (unsigned long long)
 (sum-ift_ib - total-ift_ib),  );
 



CVS commit: src/usr.bin/netstat

2010-06-30 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun 30 07:30:16 UTC 2010

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Bump date for previous (mpls).


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.57 src/usr.bin/netstat/netstat.1:1.58
--- src/usr.bin/netstat/netstat.1:1.57	Tue Jun 29 12:38:12 2010
+++ src/usr.bin/netstat/netstat.1	Wed Jun 30 07:30:16 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.57 2010/06/29 12:38:12 kefren Exp $
+.\	$NetBSD: netstat.1,v 1.58 2010/06/30 07:30:16 wiz Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\
 .\	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\
-.Dd February 24, 2009
+.Dd June 29, 2010
 .Dt NETSTAT 1
 .Os
 .Sh NAME



CVS commit: src/usr.bin/netstat

2010-06-27 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sun Jun 27 06:52:38 UTC 2010

Modified Files:
src/usr.bin/netstat: main.c netstat.1 netstat.h route.c show.c

Log Message:
Add -T flag, that shows tags in route output


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/netstat/main.c \
src/usr.bin/netstat/route.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/netstat/netstat.1
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/netstat/show.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/main.c
diff -u src/usr.bin/netstat/main.c:1.74 src/usr.bin/netstat/main.c:1.75
--- src/usr.bin/netstat/main.c:1.74	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/main.c	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $	*/
+/*	$NetBSD: main.c,v 1.75 2010/06/27 06:52:37 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = from: @(#)main.c	8.4 (Berkeley) 3/1/94;
 #else
-__RCSID($NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $);
+__RCSID($NetBSD: main.c,v 1.75 2010/06/27 06:52:37 kefren Exp $);
 #endif
 #endif /* not lint */
 
@@ -429,7 +429,7 @@
 	pcbaddr = 0;
 
 	while ((ch = getopt(argc, argv,
-	AabBdf:ghI:LliM:mN:nP:p:qrsStuvw:X)) != -1)
+	AabBdf:ghI:LliM:mN:nP:p:qrsStTuvw:X)) != -1)
 		switch (ch) {
 		case 'A':
 			Aflag = 1;
@@ -528,6 +528,9 @@
 		case 't':
 			tflag = 1;
 			break;
+		case 'T':
+			tagflag = 1;
+			break;
 		case 'u':
 			af = AF_LOCAL;
 			break;
Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.74 src/usr.bin/netstat/route.c:1.75
--- src/usr.bin/netstat/route.c:1.74	Thu Apr 22 14:32:30 2010
+++ src/usr.bin/netstat/route.c	Sun Jun 27 06:52:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $	*/
+/*	$NetBSD: route.c,v 1.75 2010/06/27 06:52:38 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)route.c	8.3 (Berkeley) 3/9/94;
 #else
-__RCSID($NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $);
+__RCSID($NetBSD: route.c,v 1.75 2010/06/27 06:52:38 kefren Exp $);
 #endif
 #endif /* not lint */
 
@@ -52,6 +52,7 @@
 #include netinet/in.h
 #include netatalk/at.h
 #include netiso/iso.h
+#include netmpls/mpls.h
 
 #include sys/sysctl.h
 
@@ -272,6 +273,21 @@
 	else
 		printf(%6s, -);
 	putchar((rt-rt_rmx.rmx_locks  RTV_MTU) ? 'L' : ' ');
+	if (tagflag == 1) {
+		if (rt-rt_tag != NULL) {
+			const struct sockaddr_mpls *sampls = 
+			(const struct sockaddr_mpls*)kgetsa(rt-rt_tag);
+			union mpls_shim shim;
+
+			if (sampls-smpls_family == AF_MPLS) {
+shim.s_addr = ntohl(sampls-smpls_addr.s_addr);
+printf(%7d, shim.shim.label);
+			}
+			else
+printf(%7s, -);
+		} else
+			printf(%7s, -);
+	}
 	if (rt-rt_ifp) {
 		if (rt-rt_ifp != lastif) {
 			kget(rt-rt_ifp, ifnet);

Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.55 src/usr.bin/netstat/netstat.1:1.56
--- src/usr.bin/netstat/netstat.1:1.55	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/netstat.1	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.55 2010/02/24 11:00:27 pooka Exp $
+.\	$NetBSD: netstat.1,v 1.56 2010/06/27 06:52:37 kefren Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -42,7 +42,7 @@
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Nm
-.Op Fl bdghiLmnqrSsv
+.Op Fl bdghiLmnqrSsTv
 .Op Fl f Ar address_family
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -264,6 +264,8 @@
 .It Fl s
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
+.It Fl T
+Show MPLS Tags for the routing tables.
 .It Fl v
 Show extra (verbose) detail for the routing tables
 .Pq Fl r ,

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.40 src/usr.bin/netstat/netstat.h:1.41
--- src/usr.bin/netstat/netstat.h:1.40	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/netstat.h	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.40 2010/02/24 11:00:27 pooka Exp $	*/
+/*	$NetBSD: netstat.h,v 1.41 2010/06/27 06:52:37 kefren Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -54,6 +54,7 @@
 int	qflag;		/* show softintrq */
 int	rflag;		/* show routing tables (or routing stats) */
 int	sflag;		/* show protocol statistics */
+int	tagflag;	/* show route tags */
 int	tflag;		/* show i/f watchdog timers */
 int	vflag;		/* verbose route information or don't truncate names */
 

Index: src/usr.bin/netstat/show.c
diff -u src/usr.bin/netstat/show.c:1.9 src/usr.bin/netstat/show.c:1.10
--- src/usr.bin/netstat/show.c:1.9	Sat Jun 26 14:30:31 2010
+++ src/usr.bin/netstat/show.c	Sun Jun 27 06:52:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.9 2010/06/26 14:30:31 

CVS commit: src/usr.bin/netstat

2010-06-26 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat Jun 26 14:30:31 UTC 2010

Modified Files:
src/usr.bin/netstat: show.c

Log Message:
add MPLS clue for showing routes


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/netstat/show.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/show.c
diff -u src/usr.bin/netstat/show.c:1.8 src/usr.bin/netstat/show.c:1.9
--- src/usr.bin/netstat/show.c:1.8	Sun Sep 13 02:53:17 2009
+++ src/usr.bin/netstat/show.c	Sat Jun 26 14:30:31 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.8 2009/09/13 02:53:17 elad Exp $	*/
+/*	$NetBSD: show.c,v 1.9 2010/06/26 14:30:31 kefren Exp $	*/
 /*	$OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $	*/
 
 /*
@@ -44,6 +44,7 @@
 #include net/route.h
 #include netinet/in.h
 #include netinet/if_ether.h
+#include netmpls/mpls.h
 #include arpa/inet.h
 
 #include err.h
@@ -59,6 +60,7 @@
 
 char	*any_ntoa(const struct sockaddr *);
 char	*link_print(struct sockaddr *);
+char	*mpls_ntoa(const struct sockaddr *); 
 
 #define ROUNDUP(a) \
 	((a)  0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
@@ -288,6 +290,9 @@
 	case AF_APPLETALK:
 		afname = AppleTalk;
 		break;
+	case AF_MPLS:
+		afname = MPLS;
+		break;
 	default:
 		afname = NULL;
 		break;
@@ -420,6 +425,9 @@
 	case AF_LINK:
 		return (link_print(sa));
 
+	case AF_MPLS:
+		return mpls_ntoa(sa);
+
 #if 0 /* XXX-elad */
 	case AF_UNSPEC:
 		if (sa-sa_len == sizeof(struct sockaddr_rtlabel)) {
@@ -684,3 +692,19 @@
 		return (link_ntoa(sdl));
 	}
 }
+
+char *
+mpls_ntoa(const struct sockaddr *sa)
+{
+	static char obuf[100];
+	const struct sockaddr_mpls *sm;
+	union mpls_shim ms;
+
+	sm = (const struct sockaddr_mpls*)sa;
+	ms.s_addr = ntohl(sm-smpls_addr.s_addr);
+
+	snprintf(obuf, sizeof(obuf), %u,
+	 ms.shim.label);
+
+	return obuf;
+}



CVS commit: src/usr.bin/netstat

2010-04-22 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu Apr 22 14:32:30 UTC 2010

Modified Files:
src/usr.bin/netstat: route.c

Log Message:
it is not [any longer] necessary to #define _KERNEL while including
net/route.h so remove it.

This fixes a build problem with pcc which is not as clever as gcc
when optimising away unused static inline functions which refer to
unknown symbols (eg sockaddr_dup).


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/route.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/route.c
diff -u src/usr.bin/netstat/route.c:1.73 src/usr.bin/netstat/route.c:1.74
--- src/usr.bin/netstat/route.c:1.73	Sun Apr 12 16:08:37 2009
+++ src/usr.bin/netstat/route.c	Thu Apr 22 14:32:30 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.73 2009/04/12 16:08:37 lukem Exp $	*/
+/*	$NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)route.c	8.3 (Berkeley) 3/9/94;
 #else
-__RCSID($NetBSD: route.c,v 1.73 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $);
 #endif
 #endif /* not lint */
 
@@ -48,9 +48,7 @@
 #include net/if.h
 #include net/if_dl.h
 #include net/if_types.h
-#define _KERNEL
 #include net/route.h
-#undef _KERNEL
 #include netinet/in.h
 #include netatalk/at.h
 #include netiso/iso.h



CVS commit: src/usr.bin/netstat

2010-04-22 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Thu Apr 22 14:37:06 UTC 2010

Modified Files:
src/usr.bin/netstat: unix.c

Log Message:
no need to forward declare struct uio and proc before including
sys/file.h as it does that internally, and don't continue the
_KERNEL definition afterwards as it causes some other problems
with pcc relating to unreferenced symbols in unused static
inline functions which gcc optimises away.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/netstat/unix.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/unix.c
diff -u src/usr.bin/netstat/unix.c:1.29 src/usr.bin/netstat/unix.c:1.30
--- src/usr.bin/netstat/unix.c:1.29	Sun Apr 12 16:08:37 2009
+++ src/usr.bin/netstat/unix.c	Thu Apr 22 14:37:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix.c,v 1.29 2009/04/12 16:08:37 lukem Exp $	*/
+/*	$NetBSD: unix.c,v 1.30 2010/04/22 14:37:06 plunky Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)unix.c	8.1 (Berkeley) 6/6/93;
 #else
-__RCSID($NetBSD: unix.c,v 1.29 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: unix.c,v 1.30 2010/04/22 14:37:06 plunky Exp $);
 #endif
 #endif /* not lint */
 
@@ -53,9 +53,8 @@
 #include sys/un.h
 #include sys/unpcb.h
 #define _KERNEL
-struct uio;
-struct proc;
 #include sys/file.h
+#undef _KERNEL
 
 #include netinet/in.h
 



CVS commit: src/usr.bin/netstat

2009-12-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec  7 18:48:45 UTC 2009

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

Log Message:
PR/42243: Yasuoka Masahiko: Add support for net.inet.icmp.bmcastecho support.
Print the current status.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/netstat/inet.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.91 src/usr.bin/netstat/inet.c:1.92
--- src/usr.bin/netstat/inet.c:1.91	Mon Sep 14 06:36:50 2009
+++ src/usr.bin/netstat/inet.c	Mon Dec  7 13:48:45 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.91 2009/09/14 10:36:50 degroote Exp $	*/
+/*	$NetBSD: inet.c,v 1.92 2009/12/07 18:48:45 christos 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.91 2009/09/14 10:36:50 degroote Exp $);
+__RCSID($NetBSD: inet.c,v 1.92 2009/12/07 18:48:45 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -582,6 +582,8 @@
 	p(ICMP_STAT_TOOSHORT, \t%llu message%s  minimum length\n);
 	p(ICMP_STAT_CHECKSUM, \t%llu bad checksum%s\n);
 	p(ICMP_STAT_BADLEN, \t%llu message%s with bad length\n);
+	p(ICMP_STAT_BMCASTECHO, \t%llu multicast echo request%s ignored\n);
+	p(ICMP_STAT_BMCASTTSTAMP, \t%llu multicast timestamp request%s ignored\n);
 	for (first = 1, i = 0; i  ICMP_MAXTYPE + 1; i++)
 		if (icmpstat[ICMP_STAT_INHIST + i] != 0) {
 			if (first) {



CVS commit: src/usr.bin/netstat

2009-09-13 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Sep 13 09:17:26 UTC 2009

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Fix section for sysctl xref (it is 3, not 2).


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/netstat/netstat.1

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/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.53 src/usr.bin/netstat/netstat.1:1.54
--- src/usr.bin/netstat/netstat.1:1.53	Sun Sep 13 02:53:17 2009
+++ src/usr.bin/netstat/netstat.1	Sun Sep 13 09:17:26 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: netstat.1,v 1.53 2009/09/13 02:53:17 elad Exp $
+.\	$NetBSD: netstat.1,v 1.54 2009/09/13 09:17:26 wiz Exp $
 .\
 .\ Copyright (c) 1983, 1990, 1992, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -266,12 +266,12 @@
 seconds.
 .It Fl X
 Force use of
-.Xr sysctl 2
+.Xr sysctl 3
 when retrieving information.
 Some features of
 .Nm
 may not be (fully) supported when using
-.Xr sysctl 2 .
+.Xr sysctl 3 .
 This flag forces the use of the latter regardless, and emits a message if a
 not yet fully supported feature is used in conjunction with it.
 This flag might be removed at any time; do not rely on its presence.



CVS commit: src/usr.bin/netstat

2009-09-13 Thread Elad Efrat
Module Name:src
Committed By:   elad
Date:   Sun Sep 13 19:04:29 UTC 2009

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.64 src/usr.bin/netstat/if.c:1.65
--- src/usr.bin/netstat/if.c:1.64	Sun Sep 13 02:53:17 2009
+++ src/usr.bin/netstat/if.c	Sun Sep 13 19:04:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.64 2009/09/13 02:53:17 elad Exp $	*/
+/*	$NetBSD: if.c,v 1.65 2009/09/13 19:04:29 elad Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.64 2009/09/13 02:53:17 elad Exp $);
+__RCSID($NetBSD: if.c,v 1.65 2009/09/13 19:04:29 elad Exp $);
 #endif
 #endif /* not lint */
 
@@ -590,15 +590,15 @@
 {
 	if (bflag)
 		printf(%10llu %8.8s %10llu %5.5s,
-		cur-ift_ib - old-ift_ib,  ,
-		cur-ift_ob - old-ift_ob,  );
+		(unsigned long long)(cur-ift_ib - old-ift_ib),  ,
+		(unsigned long long)(cur-ift_ob - old-ift_ob),  );
 	else
 		printf(%8llu %5llu %8llu %5llu %5llu,
-		cur-ift_ip - old-ift_ip,
-		cur-ift_ie - old-ift_ie,
-		cur-ift_op - old-ift_op,
-		cur-ift_oe - old-ift_oe,
-		cur-ift_co - old-ift_co);
+		(unsigned long long)(cur-ift_ip - old-ift_ip),
+		(unsigned long long)(cur-ift_ie - old-ift_ie),
+		(unsigned long long)(cur-ift_op - old-ift_op),
+		(unsigned long long)(cur-ift_oe - old-ift_oe),
+		(unsigned long long)(cur-ift_co - old-ift_co));
 	if (dflag)
 		printf( %5llu,
 		/* XXX ifnet.if_snd.ifq_drops - ip-ift_dr); */
@@ -610,15 +610,15 @@
 {
 	if (bflag)
 		printf(  %10llu %8.8s %10llu %5.5s,
-		cur-ift_ib - old-ift_ib,  ,
-		cur-ift_ob - old-ift_ob,  );
+		(unsigned long long)(cur-ift_ib - old-ift_ib),  ,
+		(unsigned long long)(cur-ift_ob - old-ift_ob),  );
 	else
 		printf(  %8llu %5llu %8llu %5llu %5llu,
-		cur-ift_ip - old-ift_ip,
-		cur-ift_ie - old-ift_ie,
-		cur-ift_op - old-ift_op,
-		cur-ift_oe - old-ift_oe,
-		cur-ift_co - old-ift_co);
+		(unsigned long long)(cur-ift_ip - old-ift_ip),
+		(unsigned long long)(cur-ift_ie - old-ift_ie),
+		(unsigned long long)(cur-ift_op - old-ift_op),
+		(unsigned long long)(cur-ift_oe - old-ift_oe),
+		(unsigned long long)(cur-ift_co - old-ift_co));
 
 	if (dflag)
 		printf( %5llu, (unsigned long long)(cur-ift_dr - old-ift_dr));



CVS commit: src/usr.bin/netstat

2009-09-13 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Sep 13 21:46:23 UTC 2009

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Use PRIu64 for printf'ing stuff.  Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/netstat/if.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/if.c
diff -u src/usr.bin/netstat/if.c:1.65 src/usr.bin/netstat/if.c:1.66
--- src/usr.bin/netstat/if.c:1.65	Sun Sep 13 19:04:29 2009
+++ src/usr.bin/netstat/if.c	Sun Sep 13 21:46:23 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.65 2009/09/13 19:04:29 elad Exp $	*/
+/*	$NetBSD: if.c,v 1.66 2009/09/13 21:46:23 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.65 2009/09/13 19:04:29 elad Exp $);
+__RCSID($NetBSD: if.c,v 1.66 2009/09/13 21:46:23 pgoyette Exp $);
 #endif
 #endif /* not lint */
 
@@ -216,7 +216,7 @@
 	continue;
 			}
 
-			printf(%-5s %-5qu , name, ifd-ifi_mtu);
+			printf(%-5s %-5 PRIu64, name, ifd-ifi_mtu);
 			print_addr(rti_info[RTAX_IFP], rti_info, ifd);
 			break;
 
@@ -234,7 +234,7 @@
 
 			get_rtaddrs(ifam-ifam_addrs, sa, rti_info);
 
-			printf(%-5s %-5qu , name, ifd-ifi_mtu);
+			printf(%-5s %-5 PRIu64, name, ifd-ifi_mtu);
 			print_addr(rti_info[RTAX_IFA], rti_info, ifd);
 			break;
 		}
@@ -589,16 +589,16 @@
 iftot_print(struct iftot *cur, struct iftot *old)
 {
 	if (bflag)
-		printf(%10llu %8.8s %10llu %5.5s,
-		(unsigned long long)(cur-ift_ib - old-ift_ib),  ,
-		(unsigned long long)(cur-ift_ob - old-ift_ob),  );
+		printf(%10 PRIu64 %8.8s %10 PRIu64 %5.5s,
+		cur-ift_ib - old-ift_ib,  ,
+		cur-ift_ob - old-ift_ob,  );
 	else
-		printf(%8llu %5llu %8llu %5llu %5llu,
-		(unsigned long long)(cur-ift_ip - old-ift_ip),
-		(unsigned long long)(cur-ift_ie - old-ift_ie),
-		(unsigned long long)(cur-ift_op - old-ift_op),
-		(unsigned long long)(cur-ift_oe - old-ift_oe),
-		(unsigned long long)(cur-ift_co - old-ift_co));
+		printf(%8 PRIu64 %5 PRIu64 %8 PRIu64 %5 PRIu64 %5 PRIu64,
+		cur-ift_ip - old-ift_ip,
+		cur-ift_ie - old-ift_ie,
+		cur-ift_op - old-ift_op,
+		cur-ift_oe - old-ift_oe,
+		cur-ift_co - old-ift_co);
 	if (dflag)
 		printf( %5llu,
 		/* XXX ifnet.if_snd.ifq_drops - ip-ift_dr); */
@@ -609,16 +609,16 @@
 iftot_print_sum(struct iftot *cur, struct iftot *old)
 {
 	if (bflag)
-		printf(  %10llu %8.8s %10llu %5.5s,
-		(unsigned long long)(cur-ift_ib - old-ift_ib),  ,
-		(unsigned long long)(cur-ift_ob - old-ift_ob),  );
+		printf(  %10 PRIu64 %8.8s %10 PRIu64 %5.5s,
+		cur-ift_ib - old-ift_ib,  ,
+		cur-ift_ob - old-ift_ob,  );
 	else
-		printf(  %8llu %5llu %8llu %5llu %5llu,
-		(unsigned long long)(cur-ift_ip - old-ift_ip),
-		(unsigned long long)(cur-ift_ie - old-ift_ie),
-		(unsigned long long)(cur-ift_op - old-ift_op),
-		(unsigned long long)(cur-ift_oe - old-ift_oe),
-		(unsigned long long)(cur-ift_co - old-ift_co));
+		printf(  %8 PRIu64 %5 PRIu64 %8 PRIu64 %5 PRIu64 %5 PRIu64,
+		cur-ift_ip - old-ift_ip,
+		cur-ift_ie - old-ift_ie,
+		cur-ift_op - old-ift_op,
+		cur-ift_oe - old-ift_oe,
+		cur-ift_co - old-ift_co);
 
 	if (dflag)
 		printf( %5llu, (unsigned long long)(cur-ift_dr - old-ift_dr));



CVS commit: src/usr.bin/netstat

2009-09-12 Thread Elad Efrat
Module Name:src
Committed By:   elad
Date:   Sun Sep 13 02:53:17 UTC 2009

Modified Files:
src/usr.bin/netstat: if.c main.c netstat.1 netstat.h show.c

Log Message:
Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/netstat/netstat.1
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/netstat/show.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/if.c
diff -u src/usr.bin/netstat/if.c:1.63 src/usr.bin/netstat/if.c:1.64
--- src/usr.bin/netstat/if.c:1.63	Sun Apr 12 16:08:37 2009
+++ src/usr.bin/netstat/if.c	Sun Sep 13 02:53:17 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.63 2009/04/12 16:08:37 lukem Exp $	*/
+/*	$NetBSD: if.c,v 1.64 2009/09/13 02:53:17 elad Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,18 +34,21 @@
 #if 0
 static char sccsid[] = from: @(#)if.c	8.2 (Berkeley) 2/21/94;
 #else
-__RCSID($NetBSD: if.c,v 1.63 2009/04/12 16:08:37 lukem Exp $);
+__RCSID($NetBSD: if.c,v 1.64 2009/09/13 02:53:17 elad Exp $);
 #endif
 #endif /* not lint */
 
+#include sys/param.h
 #include sys/types.h
 #include sys/protosw.h
 #include sys/socket.h
 #include sys/time.h
+#include sys/sysctl.h
 
 #include net/if.h
 #include net/if_dl.h
 #include net/if_types.h
+#include net/route.h
 #include netinet/in.h
 #include netinet/in_var.h
 #include netiso/iso.h
@@ -59,14 +62,40 @@
 #include string.h
 #include unistd.h
 #include netdb.h
+#include err.h
 
 #include netstat.h
 
-#define	YES	1
-#define	NO	0
+#define	MAXIF	100
+
+struct	iftot {
+	char ift_name[IFNAMSIZ];	/* interface name */
+	u_quad_t ift_ip;		/* input packets */
+	u_quad_t ift_ib;		/* input bytes */
+	u_quad_t ift_ie;		/* input errors */
+	u_quad_t ift_op;		/* output packets */
+	u_quad_t ift_ob;		/* output bytes */
+	u_quad_t ift_oe;		/* output errors */
+	u_quad_t ift_co;		/* collisions */
+	int ift_dr;			/* drops */
+};
+
+static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *);
+static void sidewaysintpr(u_int, u_long);
+
+static void iftot_banner(struct iftot *);
+static void iftot_print_sum(struct iftot *, struct iftot *);
+static void iftot_print(struct iftot *, struct iftot *);
 
-static void sidewaysintpr __P((u_int, u_long));
 static void catchalarm __P((int));
+static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
+static void fetchifs(void);
+
+static void intpr_sysctl(void);
+static void intpr_kvm(u_long, void (*)(const char *));
+
+struct iftot iftot[MAXIF], ip_cur, ip_old, sum_cur, sum_old;
+bool	signalled;			/* set if alarm goes off early */
 
 /*
  * Print a description of the network interfaces.
@@ -79,6 +108,142 @@
 	u_long ifnetaddr;
 	void (*pfunc)(const char *);
 {
+
+	if (interval) {
+		sidewaysintpr((unsigned)interval, ifnetaddr);
+		return;
+	}
+
+	if (use_sysctl) {
+		intpr_sysctl();
+	} else {
+		intpr_kvm(ifnetaddr, pfunc);
+	}
+
+}
+
+static void
+intpr_header(void)
+{
+
+	if (!sflag  !pflag) {
+		if (bflag) {
+			printf(%-5.5s %-5.5s %-13.13s %-17.17s 
+			   %10.10s %10.10s,
+			   Name, Mtu, Network, Address, 
+			   Ibytes, Obytes);
+		} else {
+			printf(%-5.5s %-5.5s %-13.13s %-17.17s 
+			   %8.8s %5.5s %8.8s %5.5s %5.5s,
+			   Name, Mtu, Network, Address, Ipkts, Ierrs,
+			   Opkts, Oerrs, Colls);
+		}
+		if (tflag)
+			printf( %4.4s, Time);
+		if (dflag)
+			printf( %5.5s, Drops);
+		putchar('\n');
+	}
+}
+
+static void
+intpr_sysctl(void)
+{
+	struct if_msghdr *ifm;
+	int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
+	char *buf = NULL, *next, *lim, *cp;
+	struct rt_msghdr *rtm;
+	struct ifa_msghdr *ifam;
+	struct if_data *ifd = NULL;
+	struct sockaddr *sa, *rti_info[RTAX_MAX];
+	struct sockaddr_dl *sdl;
+	uint64_t total = 0;
+	size_t len;
+	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+
+	if (sysctl(mib, 6, NULL, len, NULL, 0) == -1)
+		err(1, sysctl);
+	if ((buf = malloc(len)) == NULL)
+		err(1, NULL);
+	if (sysctl(mib, 6, buf, len, NULL, 0) == -1)
+		err(1, sysctl);
+
+	intpr_header();
+
+	lim = buf + len;
+	for (next = 

  1   2   >