From 7c69b0a93849e4342cef36fe09c036b501dec8b5 Mon Sep 17 00:00:00 2001 From: Michael Kupfer Date: Sun, 7 Apr 1985 23:45:30 -0800 Subject: [PATCH] Know about MT_IFADDR mbufs. Also, be more graceful if there are mbuf types defined that we don't know about. The code could be simplified some, at the cost of breaking whenever old type constants get shuffled around. SCCS-vsn: usr.bin/netstat/mbuf.c 4.8 --- usr/src/usr.bin/netstat/mbuf.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/usr/src/usr.bin/netstat/mbuf.c b/usr/src/usr.bin/netstat/mbuf.c index 7db5c33ab4..d1b84c87b7 100644 --- a/usr/src/usr.bin/netstat/mbuf.c +++ b/usr/src/usr.bin/netstat/mbuf.c @@ -1,9 +1,12 @@ #ifndef lint -static char sccsid[] = "@(#)mbuf.c 4.7 84/11/16"; +static char sccsid[] = "@(#)mbuf.c 4.8 85/04/07"; #endif +#include #include #include +#define YES 1 +typedef int bool; struct mbstat mbstat; extern int kmem; @@ -24,9 +27,13 @@ static struct mbtypes { { MT_ZOMBIE, "zombie process information" }, { MT_SOOPTS, "socket options" }, { MT_RIGHTS, "access rights" }, + { MT_IFADDR, "interface addresses" }, { 0, 0 } }; +int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short); +bool seen[256]; /* "have we seen this type yet?" */ + /* * Print mbuf statistics. */ @@ -34,8 +41,13 @@ mbpr(mbaddr) off_t mbaddr; { register int totmem, totfree, totmbufs; + register int i; register struct mbtypes *mp; + if (nmbtypes != 256) { + fprintf(stderr, "unexpected change to mbstat; check source\n"); + return; + } if (mbaddr == 0) { printf("mbstat: symbol not in namelist\n"); return; @@ -50,10 +62,18 @@ mbpr(mbaddr) totmbufs = 0; for (mp = mbtypes; mp->mt_name; mp++) if (mbstat.m_mtypes[mp->mt_type]) { + seen[mp->mt_type] = YES; printf("\t%d mbufs allocated to %s\n", - mbstat.m_mtypes[mp->mt_type], mp->mt_name); + mbstat.m_mtypes[mp->mt_type], mp->mt_name); totmbufs += mbstat.m_mtypes[mp->mt_type]; } + seen[MT_FREE] = YES; + for (i = 0; i < nmbtypes; i++) + if (!seen[i] && mbstat.m_mtypes[i]) { + printf("\t%d mbufs allocated to \n", + mbstat.m_mtypes[i], i); + totmbufs += mbstat.m_mtypes[i]; + } if (totmbufs != mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) printf("*** %d mbufs missing ***\n", (mbstat.m_mbufs - mbstat.m_mtypes[MT_FREE]) - totmbufs); -- 2.20.1