From 224566cec3754799e796c6cf5ef7597ee633da5a Mon Sep 17 00:00:00 2001 From: "Angelos D. Keromytis" Date: Sun, 9 Jun 2002 05:09:10 +0000 Subject: Begin some sysctl-ization. --- usr.bin/netstat/mbuf.c | 88 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 14 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index 335d4035d3c..1b091dae037 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.c,v 1.12 2002/02/23 01:12:54 art Exp $ */ +/* $OpenBSD: mbuf.c,v 1.13 2002/06/09 05:09:09 angelos Exp $ */ /* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)mbuf.c 8.1 (Berkeley) 6/6/93"; #else -static char *rcsid = "$OpenBSD: mbuf.c,v 1.12 2002/02/23 01:12:54 art Exp $"; +static char *rcsid = "$OpenBSD: mbuf.c,v 1.13 2002/06/09 05:09:09 angelos Exp $"; #endif #endif /* not lint */ @@ -47,7 +47,10 @@ static char *rcsid = "$OpenBSD: mbuf.c,v 1.12 2002/02/23 01:12:54 art Exp $"; #include #include #include +#include +#include +#include #include #include #include "netstat.h" @@ -58,6 +61,7 @@ typedef int bool; struct mbstat mbstat; struct pool mbpool, mclpool; +extern kvm_t *kvmd; static struct mbtypes { int mt_type; @@ -85,8 +89,10 @@ mbpr(mbaddr, mbpooladdr, mclpooladdr) u_long mbpooladdr, mclpooladdr; { int totmem, totused, totmbufs, totpct; - int i; + int i, mib[4], npools, flag = 0; + struct pool pool; struct mbtypes *mp; + size_t size; int page_size = getpagesize(); if (nmbtypes != 256) { @@ -95,18 +101,72 @@ mbpr(mbaddr, mbpooladdr, mclpooladdr) __progname); return; } - if (mbaddr == 0) { - fprintf(stderr, "%s: mbstat: symbol not in namelist\n", - __progname); - return; - } - if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) - return; - if (kread(mbpooladdr, (char *)&mbpool, sizeof (mbpool))) - return; - if (kread(mclpooladdr, (char *)&mclpool, sizeof (mclpool))) - return; + if (kvmd == NULL) { + if (mbaddr == 0) { + fprintf(stderr, "%s: mbstat: symbol not in namelist\n", + __progname); + return; + } + + if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) + return; + if (kread(mbpooladdr, (char *)&mbpool, sizeof (mbpool))) + return; + + if (kread(mclpooladdr, (char *)&mclpool, sizeof (mclpool))) + return; + } else { + mib[0] = CTL_KERN; + mib[1] = KERN_POOL; + mib[2] = KERN_POOL_POOL; + size = sizeof(npools); + + if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) { + printf("Can't figure out number of pools in kernel: %s\n", + strerror(errno)); + return; + } + + for (i = 1; npools; i++) { + char name[32]; + + mib[0] = CTL_KERN; + mib[1] = KERN_POOL; + mib[2] = KERN_POOL_POOL; + mib[3] = i; + size = sizeof(struct pool); + if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) { + if (errno == ENOENT) + continue; + printf("error getting pool: %s\n", + strerror(errno)); + return; + } + npools--; + mib[2] = KERN_POOL_NAME; + size = sizeof(name); + if (sysctl(mib, 4, &name, &size, NULL, 0) < 0) { + printf("error getting pool name: %s\n", + strerror(errno)); + return; + } + + if (!strncmp(name, "mbpl", strlen("mbpl"))) { + bcopy(&pool, &mbpool, sizeof(struct pool)); + flag++; + } else { + if (!strncmp(name, "mclpl", strlen("mclpl"))) { + bcopy(&pool, &mclpool, + sizeof(struct pool)); + flag++; + } + } + + if (flag == 2) + break; + } + } totmbufs = 0; for (mp = mbtypes; mp->mt_name; mp++) -- cgit v1.2.3