summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-06-23 17:17:59 +0000
committerru <ru@FreeBSD.org>2001-06-23 17:17:59 +0000
commitf8e11dde2671e192fa12edbf3487f63e8e0ade6e (patch)
tree1118088749c1baef05d754645d1ad80a5646de4e /usr.bin/netstat
parentdb2094554ee872866a777f43b3a558c744e82e2f (diff)
downloadFreeBSD-src-f8e11dde2671e192fa12edbf3487f63e8e0ade6e.zip
FreeBSD-src-f8e11dde2671e192fa12edbf3487f63e8e0ade6e.tar.gz
Add netstat(1) knob to reset net.inet.{ip|icmp|tcp|udp|igmp}.stats.
For example, ``netstat -s -p ip -z'' will show and reset IP stats. PR: bin/17338
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/inet.c40
-rw-r--r--usr.bin/netstat/main.c6
-rw-r--r--usr.bin/netstat/netstat.13
-rw-r--r--usr.bin/netstat/netstat.h1
4 files changed, 37 insertions, 13 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 723ec5b..594ab7f 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -348,10 +348,13 @@ protopr(u_long proto, /* for sysctl version we pass proto # */
void
tcp_stats(u_long off __unused, char *name, int af __unused)
{
- struct tcpstat tcpstat;
+ struct tcpstat tcpstat, zerostat;
size_t len = sizeof tcpstat;
- if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, 0, 0) < 0) {
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
warn("sysctl: net.inet.tcp.stats");
return;
}
@@ -446,11 +449,14 @@ tcp_stats(u_long off __unused, char *name, int af __unused)
void
udp_stats(u_long off __unused, char *name, int af __unused)
{
- struct udpstat udpstat;
+ struct udpstat udpstat, zerostat;
size_t len = sizeof udpstat;
u_long delivered;
- if (sysctlbyname("net.inet.udp.stats", &udpstat, &len, 0, 0) < 0) {
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet.udp.stats", &udpstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
warn("sysctl: net.inet.udp.stats");
return;
}
@@ -497,10 +503,13 @@ udp_stats(u_long off __unused, char *name, int af __unused)
void
ip_stats(u_long off __unused, char *name, int af __unused)
{
- struct ipstat ipstat;
+ struct ipstat ipstat, zerostat;
size_t len = sizeof ipstat;
- if (sysctlbyname("net.inet.ip.stats", &ipstat, &len, 0, 0) < 0) {
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet.ip.stats", &ipstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
warn("sysctl: net.inet.ip.stats");
return;
}
@@ -577,7 +586,7 @@ static char *icmpnames[] = {
void
icmp_stats(u_long off __unused, char *name, int af __unused)
{
- struct icmpstat icmpstat;
+ struct icmpstat icmpstat, zerostat;
int i, first;
int mib[4]; /* CTL_NET + PF_INET + IPPROTO_ICMP + req */
size_t len;
@@ -588,9 +597,13 @@ icmp_stats(u_long off __unused, char *name, int af __unused)
mib[3] = ICMPCTL_STATS;
len = sizeof icmpstat;
- memset(&icmpstat, 0, len);
- if (sysctl(mib, 4, &icmpstat, &len, (void *)0, 0) < 0)
- return; /* XXX should complain, but not traditional */
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctl(mib, 4, &icmpstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
+ warn("sysctl: net.inet.icmp.stats");
+ return;
+ }
printf("%s:\n", name);
@@ -643,10 +656,13 @@ icmp_stats(u_long off __unused, char *name, int af __unused)
void
igmp_stats(u_long off __unused, char *name, int af __unused)
{
- struct igmpstat igmpstat;
+ struct igmpstat igmpstat, zerostat;
size_t len = sizeof igmpstat;
- if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len, 0, 0) < 0) {
+ if (zflag)
+ memset(&zerostat, 0, len);
+ if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len,
+ zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
warn("sysctl: net.inet.igmp.stats");
return;
}
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 15736f9..d2417de 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -330,6 +330,7 @@ int rflag; /* show routing tables (or routing stats) */
int sflag; /* show protocol statistics */
int tflag; /* show i/f watchdog timers */
int Wflag; /* wide display */
+int zflag; /* zero stats */
int interval; /* repeat interval for i/f stats */
@@ -348,7 +349,7 @@ main(argc, argv)
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:")) != -1)
+ while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:z")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -458,6 +459,9 @@ main(argc, argv)
interval = atoi(optarg);
iflag = 1;
break;
+ case 'z':
+ zflag = 1;
+ break;
case '?':
default:
usage();
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 667c29f..9209628 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -57,6 +57,7 @@
.Op Fl N Ar system
.Nm
.Fl s Op Fl s
+.Op Fl z
.Op Fl f Ar address_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
@@ -272,6 +273,8 @@ some fields to overflow.
Show network interface statistics at intervals of
.Ar wait
seconds.
+.It Fl z
+Reset statistics.
.El
.Pp
The default display, for active sockets, shows the local
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index fffcfd6..f4411e6 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -51,6 +51,7 @@ extern int rflag; /* show routing tables (or routing stats) */
extern int sflag; /* show protocol statistics */
extern int tflag; /* show i/f watchdog timers */
extern int Wflag; /* wide display */
+extern int zflag; /* zero stats */
extern int interval; /* repeat interval for i/f stats */
OpenPOWER on IntegriCloud