summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2002-06-09 05:09:10 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2002-06-09 05:09:10 +0000
commit224566cec3754799e796c6cf5ef7597ee633da5a (patch)
tree1ee8509e9521e00a359f1995e0facedaa9ae7430 /usr.bin
parent2be9275ed1a1a7b949ecbe1405cb43092674fea6 (diff)
Begin some sysctl-ization.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/mbuf.c88
1 files changed, 74 insertions, 14 deletions
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 <sys/socket.h>
#include <sys/mbuf.h>
#include <sys/pool.h>
+#include <sys/sysctl.h>
+#include <sys/errno.h>
+#include <kvm.h>
#include <limits.h>
#include <stdio.h>
#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++)