Use sysctl to fetch network statistics unless a memory file is specified
on the command line.
This commit is contained in:
parent
ded7276f3f
commit
f2bff8adc3
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.39 2008/04/07 05:18:25 thorpej Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.40 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@ -60,6 +60,7 @@ extern char *memf;
|
||||
extern int allflag;
|
||||
extern int turns;
|
||||
extern gid_t egid;
|
||||
extern int use_sysctl;
|
||||
|
||||
struct inpcb;
|
||||
#ifdef INET6
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: icmp.c,v 1.10 2008/04/07 05:18:25 thorpej Exp $ */
|
||||
/* $NetBSD: icmp.c,v 1.11 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
@ -29,10 +29,11 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: icmp.c,v 1.10 2008/04/07 05:18:25 thorpej Exp $");
|
||||
__RCSID("$NetBSD: icmp.c,v 1.11 2008/04/10 17:14:25 thorpej Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
@ -178,7 +179,15 @@ fetchicmp(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
if (use_sysctl) {
|
||||
size_t size = sizeof(newstat);
|
||||
|
||||
if (sysctlbyname("net.inet.icmp.stats", newstat, &size,
|
||||
NULL, 0) == -1)
|
||||
return;
|
||||
} else {
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
}
|
||||
|
||||
xADJINETCTR(curstat, oldstat, newstat, ICMP_STAT_BADCODE);
|
||||
xADJINETCTR(curstat, oldstat, newstat, ICMP_STAT_BADLEN);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ip.c,v 1.15 2008/04/07 06:31:28 thorpej Exp $ */
|
||||
/* $NetBSD: ip.c,v 1.16 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: ip.c,v 1.15 2008/04/07 06:31:28 thorpej Exp $");
|
||||
__RCSID("$NetBSD: ip.c,v 1.16 2008/04/10 17:14:25 thorpej Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -203,10 +203,23 @@ void
|
||||
fetchip(void)
|
||||
{
|
||||
|
||||
KREAD((void *)namelist[0].n_value, newstat.i,
|
||||
sizeof(newstat.i));
|
||||
KREAD((void *)namelist[1].n_value, newstat.u,
|
||||
sizeof(newstat.u));
|
||||
if (use_sysctl) {
|
||||
size_t size;
|
||||
|
||||
size = sizeof(newstat.i);
|
||||
if (sysctlbyname("net.inet.ip.stats", newstat.i, &size,
|
||||
NULL, 0) == -1)
|
||||
return;
|
||||
size = sizeof(newstat.u);
|
||||
if (sysctlbyname("net.inet.udp.stats", newstat.u, &size,
|
||||
NULL, 0) == -1)
|
||||
return;
|
||||
} else {
|
||||
KREAD((void *)namelist[0].n_value, newstat.i,
|
||||
sizeof(newstat.i));
|
||||
KREAD((void *)namelist[1].n_value, newstat.u,
|
||||
sizeof(newstat.u));
|
||||
}
|
||||
|
||||
ADJINETCTR(curstat, oldstat, newstat, i[IP_STAT_TOTAL]);
|
||||
ADJINETCTR(curstat, oldstat, newstat, i[IP_STAT_DELIVERED]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ip6.c,v 1.13 2008/04/08 23:37:43 thorpej Exp $ */
|
||||
/* $NetBSD: ip6.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: ip6.c,v 1.13 2008/04/08 23:37:43 thorpej Exp $");
|
||||
__RCSID("$NetBSD: ip6.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -204,7 +204,15 @@ fetchip6(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
if (use_sysctl) {
|
||||
size_t size = sizeof(newstat);
|
||||
|
||||
if (sysctlbyname("net.inet6.ip6.stats", newstat, &size,
|
||||
NULL, 0) == -1)
|
||||
return;
|
||||
} else {
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
}
|
||||
|
||||
for (i = 0; i < IP6_NSTATS; i++)
|
||||
xADJINETCTR(curstat, oldstat, newstat, i);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.41 2007/12/31 00:22:15 christos Exp $ */
|
||||
/* $NetBSD: main.c,v 1.42 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1980, 1992, 1993
|
||||
@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1992, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: main.c,v 1.41 2007/12/31 00:22:15 christos Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.42 2008/04/10 17:14:25 thorpej Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -86,6 +86,7 @@ int turns = 2; /* stay how many refresh-turns in 'all' mode? */
|
||||
int allflag;
|
||||
int allcounter;
|
||||
sig_atomic_t needsredraw = 0;
|
||||
int use_sysctl = 1;
|
||||
|
||||
static WINDOW *wload; /* one line window for load average */
|
||||
|
||||
@ -110,6 +111,7 @@ main(int argc, char **argv)
|
||||
switch(ch) {
|
||||
case 'M':
|
||||
memf = optarg;
|
||||
use_sysctl = 0;
|
||||
break;
|
||||
case 'N':
|
||||
nlistf = optarg;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tcp.c,v 1.13 2008/04/08 01:03:58 thorpej Exp $ */
|
||||
/* $NetBSD: tcp.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: tcp.c,v 1.13 2008/04/08 01:03:58 thorpej Exp $");
|
||||
__RCSID("$NetBSD: tcp.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -233,7 +233,15 @@ fetchtcp(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
if (use_sysctl) {
|
||||
size_t size = sizeof(newstat);
|
||||
|
||||
if (sysctlbyname("net.inet.tcp.stats", newstat, &size,
|
||||
NULL, 0) == -1)
|
||||
return;
|
||||
} else {
|
||||
KREAD((void *)namelist[0].n_value, newstat, sizeof(newstat));
|
||||
}
|
||||
|
||||
for (i = 0; i < TCP_NSTATS; i++)
|
||||
xADJINETCTR(curstat, oldstat, newstat, i);
|
||||
|
Loading…
Reference in New Issue
Block a user