CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

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

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.35 src/usr.bin/netstat/mbuf.c:1.36
--- src/usr.bin/netstat/mbuf.c:1.35	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/mbuf.c	Sat Feb 24 09:53:26 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -225,7 +225,7 @@ dump_drain:
 
 	for (mo = (void *) data, lines = 0; len >= sizeof(*mo);
 	len -= sizeof(*mo), mo++) {
-		char buf[32];
+		char buf[34];
 		if (vflag == 1 &&
 		mo->mo_counter[MOWNER_COUNTER_CLAIMS] == 0 &&
 		mo->mo_counter[MOWNER_COUNTER_EXT_CLAIMS] == 0 &&
@@ -239,7 +239,7 @@ dump_drain:
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
 			continue;
-		snprintf(buf, sizeof(buf), "%16.16s %-13s",
+		snprintf(buf, sizeof(buf), "%16.16s %-13.16s",
 		mo->mo_name, mo->mo_descr);
 		if ((lines % 24) == 0 || lines > 24) {
 			printf("%30s %-8s %10s %10s %10s\n",



CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

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

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.



CVS commit: src/usr.bin/netstat

2023-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug 18 13:18:17 UTC 2023

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

Log Message:
Rename local bpf_* functions to nsbpf_* to avoid conflicts with
new libpcap bpf_* functions


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.53 -r1.54 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/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.17 src/usr.bin/netstat/bpf.c:1.18
--- src/usr.bin/netstat/bpf.c:1.17	Sat Nov 19 08:56:20 2022
+++ src/usr.bin/netstat/bpf.c	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.17 2022/11/19 08:56:20 yamt Exp $	*/
+/*	$NetBSD: bpf.c,v 1.18 2023/08/18 13:18:17 martin Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
 #include "prog_ops.h"
 
 void
-bpf_stats(void)
+nsbpf_stats(void)
 {
 	struct bpf_stat bpf_s;
 	size_t len = sizeof(bpf_s);
@@ -69,7 +69,7 @@ bpf_stats(void)
 }
 
 void
-bpf_dump(const char *bpfif)
+nsbpf_dump(const char *bpfif)
 {
 	struct bpf_d_ext *dpe;
 

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.104 src/usr.bin/netstat/main.c:1.105
--- src/usr.bin/netstat/main.c:1.104	Mon Oct 24 08:11:25 2022
+++ src/usr.bin/netstat/main.c	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.104 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: main.c,v 1.105 2023/08/18 13:18:17 martin 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.104 2022/10/24 08:11:25 msaitoh Exp $");
+__RCSID("$NetBSD: main.c,v 1.105 2023/08/18 13:18:17 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -560,9 +560,9 @@ main(int argc, char *argv[])
 #ifndef SMALL
 	if (Bflag) {
 		if (sflag)
-			bpf_stats();
+			nsbpf_stats();
 		else
-			bpf_dump(interface);
+			nsbpf_dump(interface);
 		exit(0);
 	}
 #endif

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.53 src/usr.bin/netstat/netstat.h:1.54
--- src/usr.bin/netstat/netstat.h:1.53	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/netstat.h	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.53 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: netstat.h,v 1.54 2023/08/18 13:18:17 martin Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -137,8 +137,8 @@ void	routepr(u_long);
 void	mroutepr(u_long, u_long, u_long, u_long);
 void	mrt_stats(u_long, u_long);
 
-void	bpf_stats(void);
-void	bpf_dump(const char *);
+void	nsbpf_stats(void);
+void	nsbpf_dump(const char *);
 
 kvm_t *get_kvmd(void);
 



CVS commit: src/usr.bin/netstat

2023-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug 18 13:18:17 UTC 2023

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

Log Message:
Rename local bpf_* functions to nsbpf_* to avoid conflicts with
new libpcap bpf_* functions


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.53 -r1.54 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.



CVS commit: src/usr.bin/netstat

2022-12-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 28 18:34:33 UTC 2022

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

Log Message:
if not given an interface to monitor by default, pick the one
with the most bytes in/out the first time and keep using it.

in addition to picking the most likely intersting interface,
this actually fixes a bug where interfaces coming/going in
the middle of eg, "netstat -b -w 1", may end up showing the
data for another interface on any output line (including the
the header declaring the interface!)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.108 src/usr.bin/netstat/if.c:1.109
--- src/usr.bin/netstat/if.c:1.108	Mon Dec 12 05:09:33 2022
+++ src/usr.bin/netstat/if.c	Wed Dec 28 18:34:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.109 2022/12/28 18:34:33 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.108 2022/12/12 05:09:33 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.109 2022/12/28 18:34:33 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -1171,7 +1171,11 @@ fetchifs(void)
 
 			if_data_ext_get(name, );
 
-			if (interface != NULL && !strcmp(name, interface)) {
+			if ((interface != NULL && !strcmp(name, interface)) ||
+			(interface == NULL &&
+			((ip_cur.ift_ib + ip_cur.ift_ob) == 0 ||
+			 (ip_cur.ift_ib + ip_cur.ift_ob <
+			 ifd->ifi_ibytes + ifd->ifi_obytes {
 strlcpy(ip_cur.ift_name, name,
 sizeof(ip_cur.ift_name));
 ip_cur.ift_ip = ifd->ifi_ipackets;
@@ -1197,17 +1201,11 @@ fetchifs(void)
 			break;
 		}
 	}
-	if (interface == NULL) {
-		strlcpy(ip_cur.ift_name, name,
-		sizeof(ip_cur.ift_name));
-		ip_cur.ift_ip = ifd->ifi_ipackets;
-		ip_cur.ift_ib = ifd->ifi_ibytes;
-		ip_cur.ift_ie = ifd->ifi_ierrors;
-		ip_cur.ift_op = ifd->ifi_opackets;
-		ip_cur.ift_ob = ifd->ifi_obytes;
-		ip_cur.ift_oe = ifd->ifi_oerrors;
-		ip_cur.ift_co = ifd->ifi_collisions;
-		ip_cur.ift_iq = ifd->ifi_iqdrops;
-		ip_cur.ift_oq = dext.ifi_oqdrops;
-	}
+
+	/*
+	 * If we picked an interface, be sure to keep using it for the rest
+	 * of this instance.
+	 */
+	if (interface == NULL)
+		interface = ip_cur.ift_name;
 }



CVS commit: src/usr.bin/netstat

2022-12-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 28 18:34:33 UTC 2022

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

Log Message:
if not given an interface to monitor by default, pick the one
with the most bytes in/out the first time and keep using it.

in addition to picking the most likely intersting interface,
this actually fixes a bug where interfaces coming/going in
the middle of eg, "netstat -b -w 1", may end up showing the
data for another interface on any output line (including the
the header declaring the interface!)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.



CVS commit: src/usr.bin/netstat

2022-12-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec 21 09:06:59 UTC 2022

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

Log Message:
Add note about "netstat -mssv".


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.75 src/usr.bin/netstat/netstat.1:1.76
--- src/usr.bin/netstat/netstat.1:1.75	Fri Jan  7 10:17:39 2022
+++ src/usr.bin/netstat/netstat.1	Wed Dec 21 09:06:59 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.75 2022/01/07 10:17:39 bad Exp $
+.\"	$NetBSD: netstat.1,v 1.76 2022/12/21 09:06:59 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 July 21, 2020
+.Dd December 21, 2022
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -239,6 +239,12 @@ is used.
 .It Fl m
 Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
+If the kernel option
+.Cd options MBUFTRACE
+is set, extra info can be retrieved with
+.Fl mssv .
+See also
+.Xr options 4 .
 .It Fl N Ar system
 Use
 .Xr kvm 3
@@ -436,6 +442,7 @@ And the fifth character shows the header
 .Xr kvm_openfiles 3 ,
 .Xr sysctl 3 ,
 .Xr bpf 4 ,
+.Xr options 4 ,
 .Xr route 4 ,
 .Xr hosts 5 ,
 .Xr networks 5 ,



CVS commit: src/usr.bin/netstat

2022-12-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec 21 09:06:59 UTC 2022

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

Log Message:
Add note about "netstat -mssv".


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 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.



CVS commit: src/usr.bin/netstat

2022-12-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Dec 12 05:09:33 UTC 2022

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

Log Message:
Use warn() instead of warnx() and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.



CVS commit: src/usr.bin/netstat

2022-12-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Dec 12 05:09:33 UTC 2022

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

Log Message:
Use warn() instead of warnx() and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.107 src/usr.bin/netstat/if.c:1.108
--- src/usr.bin/netstat/if.c:1.107	Sat Nov 19 14:42:35 2022
+++ src/usr.bin/netstat/if.c	Mon Dec 12 05:09:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $	*/
+/*	$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 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.107 2022/11/19 14:42:35 taca Exp $");
+__RCSID("$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,9 +182,8 @@ if_data_ext_get(const char *ifname, stru
 	snprintf(namebuf, sizeof(namebuf),
 	"net.interfaces.%s.sndq.drops", ifname);
 	len = sizeof(drops);
-	if (sysctlbyname(namebuf, , , NULL, 0)
-	== -1) {
-		warnx("'%s' not found", namebuf);
+	if (sysctlbyname(namebuf, , , NULL, 0) == -1) {
+		warn("%s", namebuf);
 		dext->ifi_oqdrops = 0;
 		return -1;
 	} else



CVS commit: src/usr.bin/netstat

2022-11-19 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Sat Nov 19 14:42:36 UTC 2022

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

Log Message:
netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 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.106 src/usr.bin/netstat/if.c:1.107
--- src/usr.bin/netstat/if.c:1.106	Mon Oct 24 08:11:25 2022
+++ src/usr.bin/netstat/if.c	Sat Nov 19 14:42:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.106 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca 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.106 2022/10/24 08:11:25 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $");
 #endif
 #endif /* not lint */
 
@@ -176,7 +176,7 @@ if_data_ext_get(const char *ifname, stru
 {
 	char namebuf[1024];
 	size_t len;
-	int drops;
+	uint64_t drops;
 
 	/* For sysctl */
 	snprintf(namebuf, sizeof(namebuf),



CVS commit: src/usr.bin/netstat

2022-11-19 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Sat Nov 19 14:42:36 UTC 2022

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

Log Message:
netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 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.



CVS commit: src/usr.bin/netstat

2022-11-19 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 08:56:20 UTC 2022

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

Log Message:
netstat/bpf.c: Don't print garbage for stale pid


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.



CVS commit: src/usr.bin/netstat

2022-11-19 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 08:56:20 UTC 2022

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

Log Message:
netstat/bpf.c: Don't print garbage for stale pid


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.16 src/usr.bin/netstat/bpf.c:1.17
--- src/usr.bin/netstat/bpf.c:1.16	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/bpf.c	Sat Nov 19 08:56:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.16 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.17 2022/11/19 08:56:20 yamt Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -162,8 +162,13 @@ bpf_dump(const char *bpfif)
 			name[namelen++] = szproc;
 			name[namelen++] = 1;
 
+			/*
+			 * Note: The sysctl succeeds (returns 0) even if it failed
+			 * to find the process. The szproc check below is to detect
+			 * that case.
+			 */
 			if (prog_sysctl([0], namelen, , ,
-			NULL, 0) == -1)
+			NULL, 0) == -1 || szproc != sizeof(p))
 printf("-\n");
 			else
 printf("%s\n", p.p_comm);



CVS commit: src/usr.bin/netstat

2022-09-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Sep 21 07:59:19 UTC 2022

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

Log Message:
s/u_quad_t/uint64_t/. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.81 -r1.82 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/if.c
diff -u src/usr.bin/netstat/if.c:1.104 src/usr.bin/netstat/if.c:1.105
--- src/usr.bin/netstat/if.c:1.104	Mon Sep 12 02:25:44 2022
+++ src/usr.bin/netstat/if.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.105 2022/09/21 07:59: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.104 2022/09/12 02:25:44 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.105 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -73,15 +73,15 @@ __RCSID("$NetBSD: if.c,v 1.104 2022/09/1
 
 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_iq;		/* input drops */
-	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_oq;		/* output drops */
-	u_quad_t ift_co;		/* collisions */
+	uint64_t ift_ip;		/* input packets */
+	uint64_t ift_ib;		/* input bytes */
+	uint64_t ift_ie;		/* input errors */
+	uint64_t ift_iq;		/* input drops */
+	uint64_t ift_op;		/* output packets */
+	uint64_t ift_ob;		/* output bytes */
+	uint64_t ift_oe;		/* output errors */
+	uint64_t ift_oq;		/* output drops */
+	uint64_t ift_co;		/* collisions */
 };
 
 struct if_data_ext {

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.116 src/usr.bin/netstat/inet.c:1.117
--- src/usr.bin/netstat/inet.c:1.116	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/inet.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: inet.c,v 1.117 2022/09/21 07:59:19 msaitoh 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.116 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: inet.c,v 1.117 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -539,7 +539,7 @@ void
 udp_stats(u_long off, const char *name)
 {
 	uint64_t udpstat[UDP_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(udpstat);

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.81 src/usr.bin/netstat/inet6.c:1.82
--- src/usr.bin/netstat/inet6.c:1.81	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/inet6.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.81 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: inet6.c,v 1.82 2022/09/21 07:59:19 msaitoh 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.81 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.82 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -501,7 +501,7 @@ void
 udp6_stats(u_long off, const char *name)
 {
 	uint64_t udp6stat[UDP6_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(udp6stat);
@@ -1349,7 +1349,7 @@ void
 rip6_stats(u_long off, const char *name)
 {
 	uint64_t rip6stat[RIP6_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(rip6stat);



CVS commit: src/usr.bin/netstat

2022-09-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Sep 21 07:59:19 UTC 2022

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

Log Message:
s/u_quad_t/uint64_t/. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.81 -r1.82 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.



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep 12 02:25:44 UTC 2022

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

Log Message:
Print oqdrops correctly in continuous display mode using with kvm.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.103 src/usr.bin/netstat/if.c:1.104
--- src/usr.bin/netstat/if.c:1.103	Sun Sep 11 23:52:20 2022
+++ src/usr.bin/netstat/if.c	Mon Sep 12 02:25:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 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.103 2022/09/11 23:52:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -924,11 +924,12 @@ banner:
 		ip->ift_ip = 0;
 		ip->ift_ib = 0;
 		ip->ift_ie = 0;
+		ip->ift_iq = 0;
 		ip->ift_op = 0;
 		ip->ift_ob = 0;
 		ip->ift_oe = 0;
+		ip->ift_oq = 0;
 		ip->ift_co = 0;
-		ip->ift_iq = 0;
 	}
 	putchar('\n');
 	if (bflag)
@@ -956,11 +957,12 @@ loop:
 	sum->ift_ip = 0;
 	sum->ift_ib = 0;
 	sum->ift_ie = 0;
+	sum->ift_iq = 0;
 	sum->ift_op = 0;
 	sum->ift_ob = 0;
 	sum->ift_oe = 0;
+	sum->ift_oq = 0;
 	sum->ift_co = 0;
-	sum->ift_iq = 0;
 	for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
 		if (kread(off, (char *), sizeof ifnet)) {
 			off = 0;



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep 12 02:25:44 UTC 2022

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

Log Message:
Print oqdrops correctly in continuous display mode using with kvm.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Sep 11 23:52:20 UTC 2022

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

Log Message:
Fix printing current output drop packet count in continuous display mode.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.102 src/usr.bin/netstat/if.c:1.103
--- src/usr.bin/netstat/if.c:1.102	Mon Sep  5 04:52:53 2022
+++ src/usr.bin/netstat/if.c	Sun Sep 11 23:52:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.103 2022/09/11 23:52: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.102 2022/09/05 04:52:53 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -1182,7 +1182,7 @@ fetchifs(void)
 ip_cur.ift_oe = ifd->ifi_oerrors;
 ip_cur.ift_co = ifd->ifi_collisions;
 ip_cur.ift_iq = ifd->ifi_iqdrops;
-ip_cur.ift_oq = ifd->ifi_iqdrops; /* XXX */
+ip_cur.ift_oq = dext.ifi_oqdrops;
 			}
 
 			sum_cur.ift_ip += ifd->ifi_ipackets;



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Sep 11 23:52:20 UTC 2022

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

Log Message:
Fix printing current output drop packet count in continuous display mode.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 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.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 04:52:53 UTC 2022

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

Log Message:
G.C. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/usr.bin/netstat/if.c:1.102
--- src/usr.bin/netstat/if.c:1.101	Mon Sep  5 02:26:22 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 04:52:53 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 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.101 2022/09/05 02:26:22 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -309,25 +309,8 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		if (dflag) {
-#if 0
-			char namebuf[1024];
-			int drops;
-
-			/* For sysctl */
-			snprintf(namebuf, sizeof(namebuf),
-			"net.interfaces.%s.sndq.drops", origname);
-			len = sizeof(drops);
-			if (sysctlbyname(namebuf, , , NULL, 0)
-			== -1) {
-warnx("'%s' not found", namebuf);
-dext.ifi_oqdrops = 0;
-			} else
-dext.ifi_oqdrops = drops;
-#else
+		if (dflag)
 			if_data_ext_get(origname, );
-#endif
-		}
 
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd,
 		NULL, dflag ?  : NULL);



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 04:52:53 UTC 2022

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

Log Message:
G.C. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 02:26:22 UTC 2022

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

Log Message:
Print oqdrops correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 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.100 src/usr.bin/netstat/if.c:1.101
--- src/usr.bin/netstat/if.c:1.100	Mon Sep  5 00:18:25 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 02:26:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 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.100 2022/09/05 00:18:25 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,16 +76,21 @@ struct	iftot {
 	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_iq;		/* input drops */
 	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_oq;		/* output drops */
 	u_quad_t ift_co;		/* collisions */
-	u_quad_t ift_dr;		/* drops */
+};
+
+struct if_data_ext {
+	uint64_t ifi_oqdrops;
 };
 
 static void set_lines(void);
 static void print_addr(const int, struct sockaddr *, struct sockaddr **,
-struct if_data *, struct ifnet *);
+struct if_data *, struct ifnet *, struct if_data_ext *);
 static void sidewaysintpr(u_int, u_long);
 
 static void iftot_banner(struct iftot *);
@@ -96,6 +101,7 @@ static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
 
+static int if_data_ext_get(const char *, struct if_data_ext *);
 static void intpr_sysctl(void);
 static void intpr_kvm(u_long, void (*)(const char *));
 
@@ -165,6 +171,28 @@ intpr_header(void)
 	}
 }
 
+int
+if_data_ext_get(const char *ifname, struct if_data_ext *dext)
+{
+	char namebuf[1024];
+	size_t len;
+	int drops;
+
+	/* For sysctl */
+	snprintf(namebuf, sizeof(namebuf),
+	"net.interfaces.%s.sndq.drops", ifname);
+	len = sizeof(drops);
+	if (sysctlbyname(namebuf, , , NULL, 0)
+	== -1) {
+		warnx("'%s' not found", namebuf);
+		dext->ifi_oqdrops = 0;
+		return -1;
+	} else
+		dext->ifi_oqdrops = drops;
+
+	return 0;
+}
+
 static void
 intpr_sysctl(void)
 {
@@ -182,6 +210,7 @@ intpr_sysctl(void)
 	size_t len;
 	int did = 1, rtax = 0, n;
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	char origname[IFNAMSIZ];	/* without `*' */
 	int ifindex = 0;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
@@ -199,6 +228,8 @@ intpr_sysctl(void)
 
 	lim = buf + len;
 	for (next = buf; next < lim; next += rtm->rtm_msglen) {
+		struct if_data_ext dext;
+
 		rtm = (struct rt_msghdr *)next;
 		if (rtm->rtm_version != RTM_VERSION)
 			continue;
@@ -226,11 +257,15 @@ intpr_sysctl(void)
 
 			ifindex = sdl->sdl_index;
 
-			/* mark inactive interfaces with a '*' */
+			/* Keep the original name */
+			strcpy(origname, name);
+
+			/* Mark inactive interfaces with a '*' */
 			cp = strchr(name, '\0');
-			if ((ifm->ifm_flags & IFF_UP) == 0)
+			if ((ifm->ifm_flags & IFF_UP) == 0) {
 *cp++ = '*';
-			*cp = '\0';
+*cp = '\0';
+			}
 
 			if (qflag) {
 total = ifd->ifi_ibytes + ifd->ifi_obytes +
@@ -274,7 +309,28 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
+		if (dflag) {
+#if 0
+			char namebuf[1024];
+			int drops;
+
+			/* For sysctl */
+			snprintf(namebuf, sizeof(namebuf),
+			"net.interfaces.%s.sndq.drops", origname);
+			len = sizeof(drops);
+			if (sysctlbyname(namebuf, , , NULL, 0)
+			== -1) {
+warnx("'%s' not found", namebuf);
+dext.ifi_oqdrops = 0;
+			} else
+dext.ifi_oqdrops = drops;
+#else
+			if_data_ext_get(origname, );
+#endif
+		}
+
+		print_addr(ifindex, rti_info[rtax], rti_info, ifd,
+		NULL, dflag ?  : NULL);
 	}
 }
 
@@ -376,7 +432,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			sa = (struct sockaddr *)cp;
 			ifname_to_ifdata(s, name, );
 			print_addr(ifnet.if_index, sa, (void *),
-			, );
+			, , NULL);
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -473,8 +529,8 @@ mc4_print(const int ifindex)
 }
 
 static void
-print_addr(const int ifindex, 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, struct if_data_ext *dext)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = "%02x%c";	

CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 02:26:22 UTC 2022

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

Log Message:
Print oqdrops correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 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.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 00:18:25 UTC 2022

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

Log Message:
Get if_data correctly when kvm is used.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 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.99 src/usr.bin/netstat/if.c:1.100
--- src/usr.bin/netstat/if.c:1.99	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 00:18:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 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.99 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -287,27 +287,15 @@ union ifaddr_u {
 };
 
 static void
-ifnet_to_ifdata_kvm(const struct ifnet * const ifp, struct if_data * const ifd)
+ifname_to_ifdata(int s, const char *ifname, struct if_data * const ifd)
 {
+	struct ifdatareq ifdr;
 
-	/*
-	 * 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;
+	strlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
+	if (ioctl(s, SIOCGIFDATA, ) != 0)
+		return;
+	memcpy(ifd, _data, sizeof(ifdr.ifdr_data));
 }
 
 static void
@@ -319,6 +307,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 	u_long ifaddraddr;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	int s;
 
 	if (ifnetaddr == 0) {
 		printf("ifnet: symbol not defined\n");
@@ -334,6 +323,9 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 		return;
 	ifnetaddr = (u_long)ifhead.tqh_first;
 
+	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+		return;
+
 	intpr_header();
 
 	ifaddraddr = 0;
@@ -382,13 +374,13 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
-			ifnet_to_ifdata_kvm(, );
+			ifname_to_ifdata(s, name, );
 			print_addr(ifnet.if_index, sa, (void *),
 			, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
-
+	close(s);
 }
 
 static void
@@ -816,6 +808,7 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	unsigned line;
 	struct iftot *lastif, *sum, *interesting;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
+	int s;
 
 	set_lines();
 
@@ -828,6 +821,9 @@ sidewaysintpr_kvm(unsigned interval, u_l
 		return;
 	firstifnet = (u_long)ifhead.tqh_first;
 
+	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+		return;
+
 	lastif = iftot;
 	sum = iftot + MAXIF - 1;
 	total = sum - 1;
@@ -930,7 +926,7 @@ loop:
 			off = 0;
 			continue;
 		}
-		ifnet_to_ifdata_kvm(, );
+		ifname_to_ifdata(s, ip->ift_name, );
 		if (ip == interesting) {
 			if (bflag) {
 char humbuf[HUMBUF_SIZE];



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 00:18:25 UTC 2022

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

Log Message:
Get if_data correctly when kvm is used.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 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.



CVS commit: src/usr.bin/netstat

2022-09-02 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Sep  2 06:25:43 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c if.c inet.c inet6.c main.c pfkey.c
pfsync.c route.c unix.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.36 -r1.37 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/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.20 src/usr.bin/netstat/atalk.c:1.21
--- src/usr.bin/netstat/atalk.c:1.20	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/atalk.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: atalk.c,v 1.21 2022/09/02 06:25:43 msaitoh 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.20 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.21 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -244,9 +244,8 @@ atalkprotopr(u_long off, const char *nam
 			return;
 		next = ddpcb.ddp_next;
 #if 0
-		if (!aflag && atalk_nullhost(ddpcb.ddp_lsat)) {
+		if (!aflag && atalk_nullhost(ddpcb.ddp_lsat))
 			continue;
-		}
 #endif
 		if (kread((u_long)ddpcb.ddp_socket,
 			  (char *), sizeof(sockb)) < 0)

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.98 src/usr.bin/netstat/if.c:1.99
--- src/usr.bin/netstat/if.c:1.98	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/if.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.98 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 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.98 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -132,12 +132,10 @@ intpr(int interval, u_long ifnetaddr, vo
 		return;
 	}
 
-	if (use_sysctl) {
+	if (use_sysctl)
 		intpr_sysctl();
-	} else {
+	else
 		intpr_kvm(ifnetaddr, pfunc);
-	}
-
 }
 
 static void
@@ -214,9 +212,9 @@ intpr_sysctl(void)
 			get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
 
 			sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP];
-			if (sdl == NULL || sdl->sdl_family != AF_LINK) {
+			if (sdl == NULL || sdl->sdl_family != AF_LINK)
 continue;
-			}
+
 			bzero(name, sizeof(name));
 			if (sdl->sdl_nlen >= IFNAMSIZ)
 memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
@@ -538,9 +536,8 @@ print_addr(const int ifindex, struct soc
 ia4_print(_addr);
 multiaddr = (u_long)inm.inm_list.le_next;
 			}
-		} else {
+		} else
 			mc4_print(ifindex);
-		}
 		break;
 #ifdef INET6
 	case AF_INET6:
@@ -551,9 +548,9 @@ print_addr(const int ifindex, struct soc
 			sin6->sin6_scope_id = 0;
 #endif
 
-		if (use_sysctl) {
+		if (use_sysctl)
 			netmask6 = (struct sockaddr_in6 *)rtinfo[RTAX_NETMASK];
-		} else {
+		else {
 			struct in6_ifaddr *ifaddr_in6 = (void *)rtinfo;
 			netmask6 = _in6->ia_prefixmask;
 		}
@@ -590,9 +587,8 @@ print_addr(const int ifindex, struct soc
 ia6_print(_addr);
 multiaddr = (u_long)inm.in6m_entry.le_next;
 			}
-		} else {
+		} else
 			mc6_print(ifindex);
-		}
 		break;
 #endif /*INET6*/
 #ifndef SMALL

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.115 src/usr.bin/netstat/inet.c:1.116
--- src/usr.bin/netstat/inet.c:1.115	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/inet.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.115 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh 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.115 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -365,8 +365,7 @@ protopr(u_long off, const char *name)
 		memcpy(, [i].ki_s, sizeof(src));
 		memcpy(, [i].ki_d, sizeof(dst));
 
-		if (!aflag &&
-		inet_lnaof(dst.sin_addr) == INADDR_ANY)
+		if (!aflag && (inet_lnaof(dst.sin_addr) == INADDR_ANY))
 			continue;
 
 		if (first) {
@@ -413,18 +412,18 @@ tcp_stats(u_long off, const char *name)
 
 	printf ("%s:\n", name);
 
-#define	

CVS commit: src/usr.bin/netstat

2022-09-02 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Sep  2 06:25:43 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c if.c inet.c inet6.c main.c pfkey.c
pfsync.c route.c unix.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.36 -r1.37 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.



CVS commit: src/usr.bin/netstat

2022-09-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep  1 10:10:20 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c
main.c mbuf.c mroute.c mroute6.c netstat.h pfkey.c pfsync.c route.c
unix.c vtw.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/bpf.c \
src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/mbuf.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.12 -r1.13 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.



CVS commit: src/usr.bin/netstat

2022-09-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep  1 10:10:20 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c
main.c mbuf.c mroute.c mroute6.c netstat.h pfkey.c pfsync.c route.c
unix.c vtw.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/bpf.c \
src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/mbuf.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.12 -r1.13 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.19 src/usr.bin/netstat/atalk.c:1.20
--- src/usr.bin/netstat/atalk.c:1.19	Fri Aug 28 07:23:48 2020
+++ src/usr.bin/netstat/atalk.c	Thu Sep  1 10:10:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $	*/
+/*	$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh 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.19 2020/08/28 07:23:48 ozaki-r Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -82,11 +82,12 @@ at_pr_net(const struct sockaddr_at *sat,
 		case 0x:
 			return "";
 		case ATADDR_ANYNET:
-			return ("*");
+			return "*";
 		}
 	}
-	(void)snprintf(mybuf, sizeof(mybuf), "%hu", ntohs(sat->sat_addr.s_net));
-	return (mybuf);
+	(void)snprintf(mybuf, sizeof(mybuf), "%hu",
+	ntohs(sat->sat_addr.s_net));
+	return mybuf;
 }
 
 static const char *
@@ -99,12 +100,12 @@ at_pr_host(const struct sockaddr_at *sat
 		case ATADDR_BCAST:
 			return "bcast";
 		case ATADDR_ANYNODE:
-			return ("*");
+			return "*";
 		}
 	}
-	(void)snprintf(mybuf, sizeof(mybuf), "%d", 
+	(void)snprintf(mybuf, sizeof(mybuf), "%d",
 	(unsigned int)sat->sat_addr.s_node);
-	return (mybuf);
+	return mybuf;
 }
 
 static const char *
@@ -114,13 +115,13 @@ at_pr_port(const struct sockaddr_at *sat
 
 	switch (sat->sat_port) {
 	case ATADDR_ANYPORT:
-		return ("*");
+		return "*";
 	case 0xff:
 		return "";
 	default:
 		(void)snprintf(mybuf, sizeof(mybuf), "%d",
 		(unsigned int)sat->sat_port);
-		return (mybuf);
+		return mybuf;
 	}
 }
 
@@ -138,7 +139,7 @@ at_pr_range(const struct sockaddr_at *sa
 		(void)snprintf(mybuf, sizeof(mybuf), "%d",
 			ntohs(sat->sat_range.r_netrange.nr_firstnet));
 	}
-	return (mybuf);
+	return mybuf;
 }
 
 
@@ -180,7 +181,7 @@ atalk_print(const struct sockaddr *sa, i
 		(void)snprintf(mybuf + strlen(mybuf),
 		sizeof(mybuf) - strlen(mybuf), ".%s", at_pr_port(sat));
 	}
-	return (mybuf);
+	return mybuf;
 }
 
 const char *
@@ -221,7 +222,7 @@ atalk_print2(const struct sockaddr *sa, 
 		if (l > 0)
 			n += l;
 	}
-	return (buf);
+	return buf;
 }
 
 void
@@ -261,7 +262,7 @@ atalkprotopr(u_long off, const char *nam
 			}
 			printf("%-5.5s %-6.6s %-6.6s  %*.*s %*.*s %s\n",
 			   "Proto", "Recv-Q", "Send-Q",
-			   -width, width, "Local Address", 
+			   -width, width, "Local Address",
 			   -width, width, "Foreign Address", "(state)");
 			first = 0;
 		}
@@ -276,8 +277,9 @@ atalkprotopr(u_long off, const char *nam
 		putchar('\n');
 	}
 }
-#define ANY(x,y,z) \
-	((sflag==1 || (x)) ? printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
+#define ANY(x,y,z)			  \
+	((sflag==1 || (x)) ?		  \
+	printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
 
 /*
  * Dump DDP statistics structure.
@@ -308,7 +310,9 @@ ddp_stats(u_long off, const char *name)
 	ANY(ddpstat[DDP_STAT_TOOSMALL], "packet", " with not enough data ");
 	ANY(ddpstat[DDP_STAT_FORWARD], "packet", " forwarded ");
 	ANY(ddpstat[DDP_STAT_ENCAP], "packet", " encapsulated ");
-	ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet", " rcvd for unreachable dest ");
-	ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet", " dropped due to no socket space ");
+	ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet",
+	" rcvd for unreachable dest ");
+	ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet",
+	" dropped due to no socket space ");
 }
 #undef ANY

Index: src/usr.bin/netstat/bpf.c
diff -u 

CVS commit: src/usr.bin/netstat

2022-08-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Aug 18 12:25:32 UTC 2022

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

Log Message:
Use NULL instead of 0.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 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.96 src/usr.bin/netstat/if.c:1.97
--- src/usr.bin/netstat/if.c:1.96	Sun Feb  2 03:41:12 2020
+++ src/usr.bin/netstat/if.c	Thu Aug 18 12:25:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $	*/
+/*	$NetBSD: if.c,v 1.97 2022/08/18 12:25:32 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.96 2020/02/02 03:41:12 thorpej Exp $");
+__RCSID("$NetBSD: if.c,v 1.97 2022/08/18 12:25:32 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -223,7 +223,7 @@ intpr_sysctl(void)
 			else if (sdl->sdl_nlen > 0) 
 memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
 
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 
 			ifindex = sdl->sdl_index;
@@ -254,7 +254,7 @@ intpr_sysctl(void)
 		case RTM_NEWADDR:
 			if (qflag && total == 0)
 continue;
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 			ifam = (struct ifa_msghdr *)next;
 			if ((ifam->ifam_addrs & (RTA_NETMASK | RTA_IFA |
@@ -349,7 +349,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			memmove(name, ifnet.if_xname, IFNAMSIZ);
 			name[IFNAMSIZ - 1] = '\0';	/* sanity */
 			ifnetaddr = (u_long)ifnet.if_list.tqe_next;
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 			cp = strchr(name, '\0');
 
@@ -1135,7 +1135,7 @@ fetchifs(void)
 			else if (sdl->sdl_nlen > 0) 
 memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
 
-			if (interface != 0 && !strcmp(name, interface)) {
+			if (interface != NULL && !strcmp(name, interface)) {
 strlcpy(ip_cur.ift_name, name,
 sizeof(ip_cur.ift_name));
 ip_cur.ift_ip = ifd->ifi_ipackets;



CVS commit: src/usr.bin/netstat

2022-08-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Aug 18 12:25:32 UTC 2022

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

Log Message:
Use NULL instead of 0.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 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.



CVS commit: src/usr.bin/netstat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:23:07 UTC 2021

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

Log Message:
netstat(1): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.11 -r1.12 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/inet.c
diff -u src/usr.bin/netstat/inet.c:1.113 src/usr.bin/netstat/inet.c:1.114
--- src/usr.bin/netstat/inet.c:1.113	Fri Aug 28 07:23:48 2020
+++ src/usr.bin/netstat/inet.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $	*/
+/*	$NetBSD: inet.c,v 1.114 2021/10/30 11:23:07 nia 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.113 2020/08/28 07:23:48 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.114 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -293,8 +293,9 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
-		err(1, "malloc");
+	pcblist = NULL;
+	if (reallocarr(, size, sizeof(*pcblist)) != 0)
+		err(1, "reallocarr");
 
 	i = 0;
 	while (next != TAILQ_END(head)) {
@@ -325,11 +326,8 @@ getpcblist_kmem(u_long off, const char *
 		pcblist[i].ki_pflags = inpcb.inp_flags;
 		if (i++ == size) {
 			size += 100;
-			struct kinfo_pcb *n = realloc(pcblist,
-			size * sizeof(*pcblist));
-			if (n == NULL)
-err(1, "realloc");
-			pcblist = n;
+			if (reallocarr(, size, sizeof(*pcblist)) != 0)
+err(1, "reallocarr");
 		}
 	}
 	*len = i;

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.78 src/usr.bin/netstat/inet6.c:1.79
--- src/usr.bin/netstat/inet6.c:1.78	Fri Sep 10 21:52:18 2021
+++ src/usr.bin/netstat/inet6.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.78 2021/09/10 21:52:18 rillig Exp $	*/
+/*	$NetBSD: inet6.c,v 1.79 2021/10/30 11:23:07 nia 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.78 2021/09/10 21:52:18 rillig Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.79 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -302,8 +302,9 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
-		err(1, "malloc");
+	pcblist = NULL;
+	if (reallocarr(, size, sizeof(*pcblist)) != 0)
+		err(1, "reallocarr");
 
 	i = 0;
 	while (next != TAILQ_END(head)) {
@@ -338,11 +339,8 @@ getpcblist_kmem(u_long off, const char *
 		pcblist[i].ki_tstate = tcpcb.t_state;
 		if (i++ == size) {
 			size += 100;
-			struct kinfo_pcb *n = realloc(pcblist,
-			size * sizeof(*pcblist));
-			if (n == NULL)
-err(1, "realloc");
-			pcblist = n;
+			if (reallocarr(, size, sizeof(*pcblist)) != 0)
+err(1, "reallocarr");
 		}
 	}
 	*len = i;

Index: src/usr.bin/netstat/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.11 src/usr.bin/netstat/vtw.c:1.12
--- src/usr.bin/netstat/vtw.c:1.11	Tue Mar  2 01:02:12 2021
+++ src/usr.bin/netstat/vtw.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $	*/
+/*	$NetBSD: vtw.c,v 1.12 2021/10/30 11:23:07 nia 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.11 2021/03/02 01:02:12 simonb Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.12 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -303,8 +303,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 		n = (klim - kbase + 1);
 
 		if (!i) {
-			if ((ubase = malloc(n * sizeof(*kbase))) == NULL)
-err(EXIT_FAILURE, NULL);
+			ubase = NULL;
+			if (reallocarr(, n, sizeof(*kbase)) != 0)
+err(EXIT_FAILURE, "reallocarr");
 			snarf(kbase, ubase, n * sizeof(*ubase));
 
 			mem += n * sizeof(*ubase);
@@ -333,9 +334,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 
 	mem += (lim - base + 1) * sizeof(*base);
 
-	fat_tcpv4.base = malloc((lim - base + 1) * sizeof(*base));
-	if (fat_tcpv4.base == NULL)
-		err(EXIT_FAILURE, NULL);
+	fat_tcpv4.base = NULL;
+	if (reallocarr(_tcpv4.base, lim - base + 1, sizeof(*base)) != 0)
+		err(EXIT_FAILURE, "reallocarr");
 	fat_tcpv4.lim = fat_tcpv4.base + (lim - base);
 
 	snarf(base, fat_tcpv4.base, sizeof(*base) * (lim - base + 1));
@@ -347,10 +348,13 @@ show_vtw_v4(void (*print)(const vtw_t *)
 	hash = fat_tcpv4.hash;
 	port = fat_tcpv4.port;
 
-	

CVS commit: src/usr.bin/netstat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:23:07 UTC 2021

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

Log Message:
netstat(1): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.11 -r1.12 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.



CVS commit: src/usr.bin/netstat

2019-10-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct  6 00:27:50 UTC 2019

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

Log Message:
sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/netstat/mroute.c

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



CVS commit: src/usr.bin/netstat

2019-10-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct  6 00:27:50 UTC 2019

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

Log Message:
sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/netstat/mroute.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/mroute.c
diff -u src/usr.bin/netstat/mroute.c:1.25 src/usr.bin/netstat/mroute.c:1.26
--- src/usr.bin/netstat/mroute.c:1.25	Thu Nov  6 21:30:09 2014
+++ src/usr.bin/netstat/mroute.c	Sun Oct  6 00:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: mroute.c,v 1.26 2019/10/06 00:27:50 mrg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mroute.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $");
+__RCSID("$NetBSD: mroute.c,v 1.26 2019/10/06 00:27:50 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -269,7 +269,7 @@ mroutepr(u_long mrpaddr, u_long mfchasht
 static void
 print_bw_meter(struct bw_meter *bw_meter, int *banner_printed)
 {
-	char s0[256], s1[256], s2[256], s3[256];
+	char s0[256*3], s1[256], s2[256], s3[256];
 	struct timeval now, end, delta;
 
 	gettimeofday(, NULL);
@@ -286,37 +286,37 @@ print_bw_meter(struct bw_meter *bw_meter
 
 	/* The measured values */
 	if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
-		sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
+		snprintf(s1, sizeof s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
 	else
-		sprintf(s1, "?");
+		snprintf(s1, sizeof s1, "?");
 	if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
-		sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
+		snprintf(s2, sizeof s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
 	else
-		sprintf(s2, "?");
-	sprintf(s0, "%lld.%ld|%s|%s",
+		snprintf(s2, sizeof s2, "?");
+	snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
 		(long long)bw_meter->bm_start_time.tv_sec,
 		(long)bw_meter->bm_start_time.tv_usec,
 		s1, s2);
 	printf("  %-30s", s0);
 
 	/* The type of entry */
-	sprintf(s0, "%s", "?");
+	snprintf(s0, sizeof s0, "%s", "?");
 	if (bw_meter->bm_flags & BW_METER_GEQ)
-		sprintf(s0, "%s", ">=");
+		snprintf(s0, sizeof s0, "%s", ">=");
 	else if (bw_meter->bm_flags & BW_METER_LEQ)
-		sprintf(s0, "%s", "<=");
+		snprintf(s0, sizeof s0, "%s", "<=");
 	printf("  %-3s", s0);
 
 	/* The threshold values */
 	if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
-		sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
+		snprintf(s1, sizeof s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
 	else
-		sprintf(s1, "?");
+		snprintf(s1, sizeof s1, "?");
 	if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
-		sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
+		snprintf(s2, sizeof s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
 	else
-		sprintf(s2, "?");
-	sprintf(s0, "%lld.%ld|%s|%s",
+		snprintf(s2, sizeof s2, "?");
+	snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
 		(long long)bw_meter->bm_threshold.b_time.tv_sec,
 		(long)bw_meter->bm_threshold.b_time.tv_usec,
 		s1, s2);
@@ -327,12 +327,12 @@ print_bw_meter(struct bw_meter *bw_meter
 		 _meter->bm_threshold.b_time, );
 	if (timercmp(, , <=)) {
 		timersub(, , );
-		sprintf(s3, "%lld.%ld",
+		snprintf(s3, sizeof s3, "%lld.%ld",
 		(long long)delta.tv_sec, (long)delta.tv_usec);
 	} else {
 		/* Negative time */
 		timersub(, , );
-		sprintf(s3, "-%lld.%ld",
+		snprintf(s3, sizeof s3, "-%lld.%ld",
 		(long long)delta.tv_sec, (long)delta.tv_usec);
 	}
 	printf(" %s", s3);



CVS commit: src/usr.bin/netstat

2019-08-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Aug 18 04:14:41 UTC 2019

Modified Files:
src/usr.bin/netstat: Makefile atalk.c bpf.c fast_ipsec.c inet.c inet6.c
netstat_hostops.c netstat_rumpops.c pfkey.c pfsync.c prog_ops.h

Log Message:
netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.2 -r1.3 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.



CVS commit: src/usr.bin/netstat

2019-08-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Aug 18 04:14:41 UTC 2019

Modified Files:
src/usr.bin/netstat: Makefile atalk.c bpf.c fast_ipsec.c inet.c inet6.c
netstat_hostops.c netstat_rumpops.c pfkey.c pfsync.c prog_ops.h

Log Message:
netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.2 -r1.3 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.45 src/usr.bin/netstat/Makefile:1.46
--- src/usr.bin/netstat/Makefile:1.45	Tue Oct 10 19:31:10 2017
+++ src/usr.bin/netstat/Makefile	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.45 2017/10/10 19:31:10 christos Exp $
+#	$NetBSD: Makefile,v 1.46 2019/08/18 04:14:40 kamil Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
@@ -25,6 +25,10 @@ RUMPSRCS+= sysctlbyname.c sysctlgetmibin
 LDADD.rump+=	-lrumpres
 DPADD.add+=	${LIBRUMPRES}
 CPPFLAGS+=  -DRUMP_ACTION
+
+SANITIZER_RENAME_CLASSES+=	rump
+SANITIZER_RENAME_FILES.rump+=	${PROG}_rumpops.c ${RUMPSRCS}
+SANITIZER_RENAME_SYMBOL.rump+=	sysctlbyname sysctlgetmibinfo sysctlnametomib
 .endif
 
 

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.16 src/usr.bin/netstat/atalk.c:1.17
--- src/usr.bin/netstat/atalk.c:1.16	Sat Jun  6 13:08:31 2015
+++ src/usr.bin/netstat/atalk.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $	*/
+/*	$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil 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.16 2015/06/06 13:08:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,7 @@ __RCSID("$NetBSD: atalk.c,v 1.16 2015/06
 #include 
 #include 
 #include "netstat.h"
+#include "prog_ops.h"
 
 struct ddpcbddpcb;
 struct socket   sockb;
@@ -290,7 +291,7 @@ ddp_stats(u_long off, const char *name)
 	if (use_sysctl) {
 		size_t size = sizeof(ddpstat);
 
-		if (sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
+		if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
  NULL, 0) == -1)
 			return;
 	} else {

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.13 src/usr.bin/netstat/bpf.c:1.14
--- src/usr.bin/netstat/bpf.c:1.13	Tue Jun 26 09:50:42 2018
+++ src/usr.bin/netstat/bpf.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.13 2018/06/26 09:50:42 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@ bpf_stats(void)
 	size_t len = sizeof(bpf_s);
 
 	if (use_sysctl) {
-		if (sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
+		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
 			err(1, "net.bpf.stats");
 	
 		printf("bpf:\n");
@@ -83,7 +83,7 @@ bpf_dump(const char *bpfif)
 		/* adapted from sockstat.c by Andrew Brown */
 
 		sz = CTL_MAXNAME;
-		if (sysctlnametomib("net.bpf.peers", [0], ) == -1)
+		if (prog_sysctlnametomib("net.bpf.peers", [0], ) == -1)
 			err(1, "sysctlnametomib: net.bpf.peers");
 		namelen = sz;
 

Index: src/usr.bin/netstat/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.22 src/usr.bin/netstat/fast_ipsec.c:1.23
--- src/usr.bin/netstat/fast_ipsec.c:1.22	Thu Jun 29 07:15:27 2017
+++ src/usr.bin/netstat/fast_ipsec.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.23 2019/08/18 04:14:40 kamil 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.22 2017/06/29 07:15:27 ozaki-r Exp $");
+__RCSID("$NetBSD: fast_ipsec.c,v 1.23 2019/08/18 04:14:40 kamil Exp $");
 #endif
 #endif /* not lint*/
 
@@ -62,6 +62,7 @@ __RCSID("$NetBSD: fast_ipsec.c,v 1.22 20
 #include 
 
 #include "netstat.h"
+#include "prog_ops.h"
 
 /*
  * Table-driven mapping from SADB algorithm codes to 

CVS commit: src/usr.bin/netstat

2019-06-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 25 14:52:56 UTC 2019

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

Log Message:
Limit maximum owner name to appease gcc


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 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.33 src/usr.bin/netstat/mbuf.c:1.34
--- src/usr.bin/netstat/mbuf.c:1.33	Tue Jul 28 19:46:42 2015
+++ src/usr.bin/netstat/mbuf.c	Tue Jun 25 14:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.34 2019/06/25 14:52:55 martin Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.34 2019/06/25 14:52:55 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -239,7 +239,7 @@ dump_drain:
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
 			continue;
-		snprintf(buf, sizeof(buf), "%16s %-13s",
+		snprintf(buf, sizeof(buf), "%16.16s %-13s",
 		mo->mo_name, mo->mo_descr);
 		if ((lines % 24) == 0 || lines > 24) {
 			printf("%30s %-8s %10s %10s %10s\n",



CVS commit: src/usr.bin/netstat

2019-06-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 25 14:52:56 UTC 2019

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

Log Message:
Limit maximum owner name to appease gcc


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 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.



CVS commit: src/usr.bin/netstat

2019-05-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon May 13 07:48:42 UTC 2019

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

Log Message:
Show the number of packets dropped by pfil


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.71 -r1.72 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.



CVS commit: src/usr.bin/netstat

2019-05-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon May 13 07:48:42 UTC 2019

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

Log Message:
Show the number of packets dropped by pfil


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.71 -r1.72 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.108 src/usr.bin/netstat/inet.c:1.109
--- src/usr.bin/netstat/inet.c:1.108	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/inet.c	Mon May 13 07:48:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.108 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: inet.c,v 1.109 2019/05/13 07:48:42 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.108 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: inet.c,v 1.109 2019/05/13 07:48:42 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -630,6 +630,8 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_OFRAGMENTS, "\t%" PRIu64 " fragment%s created\n");
 	p(IP_STAT_CANTFRAG, "\t%" PRIu64 " datagram%s that can't be fragmented\n");
 	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");
 #undef ps
 #undef p
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.71 src/usr.bin/netstat/inet6.c:1.72
--- src/usr.bin/netstat/inet6.c:1.71	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/inet6.c	Mon May 13 07:48:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.71 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: inet6.c,v 1.72 2019/05/13 07:48:42 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.71 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.72 2019/05/13 07:48:42 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -798,6 +798,8 @@ ip6_stats(u_long off, const char *name)
 
 	p1(IP6_STAT_FORWARD_CACHEHIT, "\t%llu forward cache hit\n");
 	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");
 #undef p
 #undef p1
 }



Re: CVS commit: src/usr.bin/netstat

2016-05-13 Thread Christos Zoulas
On May 13,  6:58pm, ozak...@netbsd.org (Ryota Ozaki) wrote:
-- Subject: Re: CVS commit: src/usr.bin/netstat

| Heh. References to route(4) and route(8) are in the previous
| sentence so I thought they are in the SEE ALSO too :-/
| 
| > Also it is not
| > that bad to have both lists. If you are worried about forgetting
| > to update one, put a comment in both. I would prefer to revert
| > and add a comment; the list in route is more confusing because
| > it includes the command line flags and the descriptions are more
| > terse.
| 
| Hmm, I still prefer to putting the list at one place.
| Another complainer? I'll concede if one joined.

Well, the right fix is to mention what needs to be updated in the source
too. I volunteer to fix it all.

christos


Re: CVS commit: src/usr.bin/netstat

2016-05-13 Thread Ryota Ozaki
On Thu, May 12, 2016 at 9:24 PM, Christos Zoulas  wrote:
> In article <20160512034411.abad5f...@cvs.netbsd.org>,
> Ryota Ozaki  wrote:
>>-=-=-=-=-=-
>>
>>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.)
>
> Yes, but at least leave a cross-reference behind!

Heh. References to route(4) and route(8) are in the previous
sentence so I thought they are in the SEE ALSO too :-/

> Also it is not
> that bad to have both lists. If you are worried about forgetting
> to update one, put a comment in both. I would prefer to revert
> and add a comment; the list in route is more confusing because
> it includes the command line flags and the descriptions are more
> terse.

Hmm, I still prefer to putting the list at one place.
Another complainer? I'll concede if one joined.

  ozaki-r


Re: CVS commit: src/usr.bin/netstat

2014-04-28 Thread Takahiro HAYASHI

hi,

(04/25/14 04:02), Christos Zoulas wrote: In article 
20140424191900.gp20...@snowdrop.l8s.co.uk,

David Laight  da...@l8s.co.uk wrote:

On Thu, Apr 24, 2014 at 10:56:29AM -0400, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Thu Apr 24 14:56:29 UTC 2014

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

Log Message:
The sysctl code does not support verbose route printing that prints the
internal route statistics. Restore the old kmem route printing code that
was not just used for post-mortem displays. Reported by kardel@, test by
netstat -nrvf inet


That seems a large backwards step...


No, the sysctl code is still used in the same cases as before. It
is only for the parts that are not supported by the sysctl code
that fail back to the kmem code (where the functionality was lost
when the code was deleted).


Are you guys interested in use_sysctl version of netstat -nrv code?
I think that's useful if kmem is not available.

Both struct rtentry from kmem and struct rt_msghdr from sysctl
has struct rt_metrics.  This code splits printing rt_metrics
and allows call from both paths.
To check both paths, try netstat -nrv -X and netstat -nrv -g.
(side effect of -g causes use_sysctl=0)

Index: src/usr.bin/netstat/main.c
===
RCS file: /cvsroot/src/usr.bin/netstat/main.c,v
retrieving revision 1.89
diff -u -p -r1.89 main.c
--- src/usr.bin/netstat/main.c24 Apr 2014 14:56:29 -1.89
+++ src/usr.bin/netstat/main.c25 Apr 2014 20:19:28 -
@@ -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
===
RCS file: /cvsroot/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.49
diff -u -p -r1.49 netstat.h
--- src/usr.bin/netstat/netstat.h24 Apr 2014 14:54:51 -1.49
+++ src/usr.bin/netstat/netstat.h25 Apr 2014 20:19:28 -
@@ -116,6 +116,8 @@ voidimpstats(u_long, u_long);
 
 voidpr_rthdr(int, int);

 voidpr_family(int);
+struct rt_metrics;
+voidpr_rtrmx(struct rt_metrics *);
 voidrt_stats(u_long);
 char*ns_phost(struct sockaddr *);
 
Index: src/usr.bin/netstat/route.c

===
RCS file: /cvsroot/src/usr.bin/netstat/route.c,v
retrieving revision 1.81
diff -u -p -r1.81 route.c
--- src/usr.bin/netstat/route.c24 Apr 2014 14:56:29 -1.81
+++ src/usr.bin/netstat/route.c25 Apr 2014 20:19:28 -
@@ -286,27 +286,36 @@ 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)
+{
+if (rmx == NULL)
+return;
+
+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
===
RCS file: /cvsroot/src/usr.bin/netstat/show.c,v
retrieving revision 1.18
diff -u -p -r1.18 show.c

Re: CVS commit: src/usr.bin/netstat

2014-04-24 Thread David Laight
On Thu, Apr 24, 2014 at 10:56:29AM -0400, Christos Zoulas wrote:
 Module Name:  src
 Committed By: christos
 Date: Thu Apr 24 14:56:29 UTC 2014
 
 Modified Files:
   src/usr.bin/netstat: main.c route.c
 
 Log Message:
 The sysctl code does not support verbose route printing that prints the
 internal route statistics. Restore the old kmem route printing code that
 was not just used for post-mortem displays. Reported by kardel@, test by
 netstat -nrvf inet

That seems a large backwards step...

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/usr.bin/netstat

2014-04-24 Thread Christos Zoulas
In article 20140424191900.gp20...@snowdrop.l8s.co.uk,
David Laight  da...@l8s.co.uk wrote:
On Thu, Apr 24, 2014 at 10:56:29AM -0400, Christos Zoulas wrote:
 Module Name: src
 Committed By:christos
 Date:Thu Apr 24 14:56:29 UTC 2014
 
 Modified Files:
  src/usr.bin/netstat: main.c route.c
 
 Log Message:
 The sysctl code does not support verbose route printing that prints the
 internal route statistics. Restore the old kmem route printing code that
 was not just used for post-mortem displays. Reported by kardel@, test by
 netstat -nrvf inet

That seems a large backwards step...

No, the sysctl code is still used in the same cases as before. It
is only for the parts that are not supported by the sysctl code
that fail back to the kmem code (where the functionality was lost
when the code was deleted).

christos



CVS commit: src/usr.bin/netstat

2010-02-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Feb 24 11:00:28 UTC 2010

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

Log Message:
Add -h, which makes output of bytes counts humanized (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/netstat/netstat.1
cvs rdiff -u -r1.39 -r1.40 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.