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