version 1.12, 2002/02/23 01:12:54 |
version 1.13, 2002/06/09 05:09:09 |
|
|
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/mbuf.h> |
#include <sys/mbuf.h> |
#include <sys/pool.h> |
#include <sys/pool.h> |
|
#include <sys/sysctl.h> |
|
#include <sys/errno.h> |
|
|
|
#include <kvm.h> |
#include <limits.h> |
#include <limits.h> |
#include <stdio.h> |
#include <stdio.h> |
#include "netstat.h" |
#include "netstat.h" |
|
|
struct mbstat mbstat; |
struct mbstat mbstat; |
struct pool mbpool, mclpool; |
struct pool mbpool, mclpool; |
|
|
|
extern kvm_t *kvmd; |
|
|
static struct mbtypes { |
static struct mbtypes { |
int mt_type; |
int mt_type; |
|
|
u_long mbpooladdr, mclpooladdr; |
u_long mbpooladdr, mclpooladdr; |
{ |
{ |
int totmem, totused, totmbufs, totpct; |
int totmem, totused, totmbufs, totpct; |
int i; |
int i, mib[4], npools, flag = 0; |
|
struct pool pool; |
struct mbtypes *mp; |
struct mbtypes *mp; |
|
size_t size; |
int page_size = getpagesize(); |
int page_size = getpagesize(); |
|
|
if (nmbtypes != 256) { |
if (nmbtypes != 256) { |
|
|
__progname); |
__progname); |
return; |
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))) |
if (kvmd == NULL) { |
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; |
|
} 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; |
totmbufs = 0; |
for (mp = mbtypes; mp->mt_name; mp++) |
for (mp = mbtypes; mp->mt_name; mp++) |