not every value return in an nlist structure was being
[unix-history] / usr / src / usr.bin / netstat / mbuf.c
CommitLineData
5ff67f98 1/*
b36fc510 2 * Copyright (c) 1983, 1988 Regents of the University of California.
ee3f90a5
MK
3 * All rights reserved.
4 *
87198c0c 5 * %sccs.include.redist.c%
5ff67f98
DF
6 */
7
bad4305f 8#ifndef lint
d1cfb820 9static char sccsid[] = "@(#)mbuf.c 5.12 (Berkeley) %G%";
b36fc510 10#endif /* not lint */
bad4305f 11
24bf5f10 12#include <sys/param.h>
6e549c8f
KS
13#include <sys/protosw.h>
14#include <sys/socket.h>
bad4305f 15#include <sys/mbuf.h>
6e549c8f
KS
16
17#include <stdio.h>
18#include "netstat.h"
19
7c69b0a9
MK
20#define YES 1
21typedef int bool;
bad4305f
SL
22
23struct mbstat mbstat;
bad4305f 24
02c6746b
SL
25static struct mbtypes {
26 int mt_type;
27 char *mt_name;
28} mbtypes[] = {
29 { MT_DATA, "data" },
a65693cc
MK
30 { MT_OOBDATA, "oob data" },
31 { MT_CONTROL, "ancillary data" },
02c6746b 32 { MT_HEADER, "packet headers" },
a65693cc
MK
33 { MT_SOCKET, "socket structures" }, /* XXX */
34 { MT_PCB, "protocol control blocks" }, /* XXX */
35 { MT_RTABLE, "routing table entries" }, /* XXX */
36 { MT_HTABLE, "IMP host table entries" }, /* XXX */
02c6746b 37 { MT_ATABLE, "address resolution tables" },
a65693cc 38 { MT_FTABLE, "fragment reassembly queue headers" }, /* XXX */
02c6746b 39 { MT_SONAME, "socket names and addresses" },
02c6746b 40 { MT_SOOPTS, "socket options" },
1ab9ab56 41 { MT_RIGHTS, "access rights" },
6e549c8f 42 { MT_IFADDR, "interface addresses" }, /* XXX */
02c6746b
SL
43 { 0, 0 }
44};
45
7c69b0a9
MK
46int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
47bool seen[256]; /* "have we seen this type yet?" */
48
bad4305f
SL
49/*
50 * Print mbuf statistics.
51 */
6e549c8f 52void
bad4305f 53mbpr(mbaddr)
d1cfb820 54 u_long mbaddr;
bad4305f 55{
02c6746b 56 register int totmem, totfree, totmbufs;
7c69b0a9 57 register int i;
02c6746b 58 register struct mbtypes *mp;
24bf5f10 59
7c69b0a9 60 if (nmbtypes != 256) {
6e549c8f
KS
61 fprintf(stderr,
62 "%s: unexpected change to mbstat; check source\n", prog);
7c69b0a9
MK
63 return;
64 }
bad4305f 65 if (mbaddr == 0) {
6e549c8f 66 fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog);
bad4305f
SL
67 return;
68 }
6e549c8f 69 if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat)))
24bf5f10 70 return;
02c6746b 71 totmbufs = 0;
a65693cc
MK
72 for (mp = mbtypes; mp->mt_name; mp++)
73 totmbufs += mbstat.m_mtypes[mp->mt_type];
74 printf("%u mbufs in use:\n", totmbufs);
02c6746b
SL
75 for (mp = mbtypes; mp->mt_name; mp++)
76 if (mbstat.m_mtypes[mp->mt_type]) {
7c69b0a9 77 seen[mp->mt_type] = YES;
f9ae784a 78 printf("\t%u mbufs allocated to %s\n",
7c69b0a9 79 mbstat.m_mtypes[mp->mt_type], mp->mt_name);
02c6746b 80 }
7c69b0a9
MK
81 seen[MT_FREE] = YES;
82 for (i = 0; i < nmbtypes; i++)
83 if (!seen[i] && mbstat.m_mtypes[i]) {
f9ae784a 84 printf("\t%u mbufs allocated to <mbuf type %d>\n",
7c69b0a9 85 mbstat.m_mtypes[i], i);
7c69b0a9 86 }
f9ae784a 87 printf("%u/%u mapped pages in use\n",
24bf5f10 88 mbstat.m_clusters - mbstat.m_clfree, mbstat.m_clusters);
51d84d35
MK
89 totmem = totmbufs * MSIZE + mbstat.m_clusters * MCLBYTES;
90 totfree = mbstat.m_clfree * MCLBYTES;
f9ae784a 91 printf("%u Kbytes allocated to network (%d%% in use)\n",
c1567c4d 92 totmem / 1024, (totmem - totfree) * 100 / totmem);
f9ae784a
MK
93 printf("%u requests for memory denied\n", mbstat.m_drops);
94 printf("%u requests for memory delayed\n", mbstat.m_wait);
95 printf("%u calls to protocol drain routines\n", mbstat.m_drain);
bad4305f 96}