Restore -M -N support for -m.
PR: 20808
This commit is contained in:
parent
1122486743
commit
bf0e940d3c
@ -145,6 +145,14 @@ static struct nlist nl[] = {
|
||||
{ "_mif6table" },
|
||||
#define N_PFKEYSTAT 37
|
||||
{ "_pfkeystat" },
|
||||
#define N_MBSTAT 38
|
||||
{ "_mbstat" },
|
||||
#define N_MBTYPES 39
|
||||
{ "_mbtypes" },
|
||||
#define N_NMBCLUSTERS 40
|
||||
{ "_nmbclusters" },
|
||||
#define N_NMBUFS 41
|
||||
{ "_nmbufs" },
|
||||
{ "" },
|
||||
};
|
||||
|
||||
@ -467,7 +475,14 @@ main(argc, argv)
|
||||
setgid(getgid());
|
||||
|
||||
if (mflag) {
|
||||
mbpr();
|
||||
if (memf != NULL) {
|
||||
if (kread(0, 0, 0) == 0)
|
||||
mbpr(nl[N_MBSTAT].n_value,
|
||||
nl[N_MBTYPES].n_value,
|
||||
nl[N_NMBCLUSTERS].n_value,
|
||||
nl[N_NMBUFS].n_value);
|
||||
} else
|
||||
mbpr(0, 0, 0, 0);
|
||||
exit(0);
|
||||
}
|
||||
if (pflag) {
|
||||
@ -723,10 +738,11 @@ name2protox(name)
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
||||
"usage: netstat [-AaLlnW] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-abdgilmnrs] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-abdgilnrs] [-f address_family] [-M core] [-N system]",
|
||||
" netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
|
||||
" netstat -m [-M core] [-N system]",
|
||||
" netstat [-M core] [-N system] [-p protocol]");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ static const char rcsid[] =
|
||||
#define YES 1
|
||||
typedef int bool;
|
||||
|
||||
struct mbstat mbstat;
|
||||
|
||||
static struct mbtypenames {
|
||||
int mt_type;
|
||||
char *mt_name;
|
||||
@ -96,10 +94,12 @@ static struct mbtypenames {
|
||||
* Print mbuf statistics.
|
||||
*/
|
||||
void
|
||||
mbpr()
|
||||
mbpr(mbaddr, mbtaddr, nmbcaddr, nmbufaddr)
|
||||
u_long mbaddr, mbtaddr, nmbcaddr, nmbufaddr;
|
||||
{
|
||||
u_long totmem, totpossible, totmbufs;
|
||||
register int i;
|
||||
struct mbstat mbstat;
|
||||
struct mbtypenames *mp;
|
||||
int name[3], nmbclusters, nmbufs, nmbcnt, nmbtypes;
|
||||
size_t nmbclen, nmbuflen, nmbcntlen, mbstatlen, mbtypeslen;
|
||||
@ -109,15 +109,11 @@ mbpr()
|
||||
mbtypes = NULL;
|
||||
seen = NULL;
|
||||
|
||||
name[0] = CTL_KERN;
|
||||
name[1] = KERN_IPC;
|
||||
name[2] = KIPC_MBSTAT;
|
||||
mbstatlen = sizeof mbstat;
|
||||
if (sysctl(name, 3, &mbstat, &mbstatlen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving mbstat");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* We can't kread() mbtypeslen from a core image so we'll
|
||||
* bogusly assume it's the same as in the running kernel.
|
||||
*/
|
||||
if (sysctlbyname("kern.ipc.mbtypes", NULL, &mbtypeslen, NULL, 0) < 0) {
|
||||
warn("sysctl: retrieving mbtypes length");
|
||||
goto err;
|
||||
@ -126,29 +122,50 @@ mbpr()
|
||||
warn("malloc: %lu bytes for mbtypes", (u_long)mbtypeslen);
|
||||
goto err;
|
||||
}
|
||||
if (sysctlbyname("kern.ipc.mbtypes", mbtypes, &mbtypeslen, NULL,
|
||||
0) < 0) {
|
||||
warn("sysctl: retrieving mbtypes");
|
||||
goto err;
|
||||
}
|
||||
|
||||
nmbtypes = mbtypeslen / sizeof(*mbtypes);
|
||||
if ((seen = calloc(nmbtypes, sizeof(*seen))) == NULL) {
|
||||
warn("calloc");
|
||||
goto err;
|
||||
}
|
||||
|
||||
name[2] = KIPC_NMBCLUSTERS;
|
||||
nmbclen = sizeof(int);
|
||||
if (sysctl(name, 3, &nmbclusters, &nmbclen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving nmbclusters");
|
||||
goto err;
|
||||
}
|
||||
|
||||
nmbuflen = sizeof(int);
|
||||
if (sysctlbyname("kern.ipc.nmbufs", &nmbufs, &nmbuflen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving nmbufs");
|
||||
goto err;
|
||||
if (mbaddr) {
|
||||
if (kread(mbaddr, (char *)&mbstat, sizeof mbstat))
|
||||
goto err;
|
||||
if (kread(mbtaddr, (char *)mbtypes, mbtypeslen))
|
||||
goto err;
|
||||
if (kread(nmbcaddr, (char *)&nmbclusters, sizeof(int)))
|
||||
goto err;
|
||||
if (kread(nmbufaddr, (char *)&nmbufs, sizeof(int)))
|
||||
goto err;
|
||||
} else {
|
||||
name[0] = CTL_KERN;
|
||||
name[1] = KERN_IPC;
|
||||
name[2] = KIPC_MBSTAT;
|
||||
mbstatlen = sizeof mbstat;
|
||||
if (sysctl(name, 3, &mbstat, &mbstatlen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving mbstat");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (sysctlbyname("kern.ipc.mbtypes", mbtypes, &mbtypeslen, NULL,
|
||||
0) < 0) {
|
||||
warn("sysctl: retrieving mbtypes");
|
||||
goto err;
|
||||
}
|
||||
|
||||
name[2] = KIPC_NMBCLUSTERS;
|
||||
nmbclen = sizeof(int);
|
||||
if (sysctl(name, 3, &nmbclusters, &nmbclen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving nmbclusters");
|
||||
goto err;
|
||||
}
|
||||
|
||||
nmbuflen = sizeof(int);
|
||||
if (sysctlbyname("kern.ipc.nmbufs", &nmbufs, &nmbuflen, 0, 0) < 0) {
|
||||
warn("sysctl: retrieving nmbufs");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
nmbcntlen = sizeof(int);
|
||||
|
@ -45,7 +45,7 @@
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
.Nm
|
||||
.Op Fl bdgilmnrs
|
||||
.Op Fl bdgilnrs
|
||||
.Op Fl f Ar address_family
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
@ -68,6 +68,10 @@
|
||||
.Op Fl f Ar address_family
|
||||
.Op Fl i
|
||||
.Op Fl I Ar Interface
|
||||
.Nm
|
||||
.Fl m
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
|
@ -95,7 +95,7 @@ void pfkey_stats __P((u_long, char *));
|
||||
|
||||
void bdg_stats __P((u_long, char *));
|
||||
|
||||
void mbpr __P((void));
|
||||
void mbpr __P((u_long, u_long, u_long, u_long));
|
||||
|
||||
void hostpr __P((u_long, u_long));
|
||||
void impstats __P((u_long, u_long));
|
||||
|
Loading…
x
Reference in New Issue
Block a user