summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/main.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-08-08 08:13:04 +0000
committerphk <phk@FreeBSD.org>1998-08-08 08:13:04 +0000
commit8cd84a68cc2bb1ddbe112224cee1f42017fbfbc0 (patch)
tree047024e42a38711231926c3600f284ec36833933 /usr.bin/netstat/main.c
parenta5e1d6e09cff33279213d996def3d9ebea963d49 (diff)
downloadFreeBSD-src-8cd84a68cc2bb1ddbe112224cee1f42017fbfbc0.zip
FreeBSD-src-8cd84a68cc2bb1ddbe112224cee1f42017fbfbc0.tar.gz
Make netstat work again.
Diffstat (limited to 'usr.bin/netstat/main.c')
-rw-r--r--usr.bin/netstat/main.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index fd54b12..fd0c5bd 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -42,7 +42,7 @@ char const copyright[] =
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94";
#endif
static const char rcsid[] =
- "$Id: main.c,v 1.20 1998/05/15 20:19:16 wollman Exp $";
+ "$Id: main.c,v 1.21 1998/08/05 13:54:07 phk Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -66,7 +66,7 @@ static const char rcsid[] =
#include <unistd.h>
#include "netstat.h"
-struct nlist nl[] = {
+static struct nlist nl[] = {
#define N_IFNET 0
{ "_ifnet" },
#define N_IMP 1
@@ -209,7 +209,7 @@ static void usage __P((void));
static struct protox *name2protox __P((char *));
static struct protox *knownname __P((char *));
-kvm_t *kvmd;
+static kvm_t *kvmd;
char *nlistf = NULL, *memf = NULL;
int
@@ -220,7 +220,6 @@ main(argc, argv)
register struct protoent *p;
register struct protox *tp; /* for printing cblocks & stats */
int ch;
- char buf[_POSIX2_LINE_MAX];
af = AF_UNSPEC;
@@ -348,12 +347,17 @@ main(argc, argv)
exit(0);
}
if (pflag) {
- if (tp->pr_stats)
- (*tp->pr_stats)(tp->pr_usesysctl ? tp->pr_usesysctl
- : nl[tp->pr_sindex].n_value,
- tp->pr_name);
- else
+ if (!tp->pr_stats) {
printf("%s: no stats routine\n", tp->pr_name);
+ exit(0);
+ }
+ if (tp->pr_usesysctl) {
+ (*tp->pr_stats)(tp->pr_usesysctl, tp->pr_name);
+ } else {
+ kread(0, 0, 0);
+ (*tp->pr_stats)(nl[tp->pr_sindex].n_value,
+ tp->pr_name);
+ }
exit(0);
}
#if 0
@@ -371,10 +375,12 @@ main(argc, argv)
*/
#endif
if (iflag) {
+ kread(0, 0, 0);
intpr(interval, nl[N_IFNET].n_value);
exit(0);
}
if (rflag) {
+ kread(0, 0, 0);
if (sflag)
rt_stats(nl[N_RTSTAT].n_value);
else
@@ -382,6 +388,7 @@ main(argc, argv)
exit(0);
}
if (gflag) {
+ kread(0, 0, 0);
if (sflag)
mrt_stats(nl[N_MRTPROTO].n_value,
nl[N_MRTSTAT].n_value);
@@ -486,6 +493,8 @@ kread(addr, buf, size)
return(-1);
}
}
+ if (!buf)
+ return (0);
if (kvm_read(kvmd, addr, buf, size) != size) {
warnx("%s", kvm_geterr(kvmd));
return (-1);
OpenPOWER on IntegriCloud