4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / systat / mbufs.c
CommitLineData
543607e3 1/*-
65f8349f
KB
2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
543607e3 4 *
1e3c68be 5 * %sccs.include.redist.c%
07ed1e09
KM
6 */
7
4376ba29 8#ifndef lint
65f8349f 9static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) %G%";
543607e3 10#endif /* not lint */
4376ba29 11
543607e3
KB
12#include <sys/param.h>
13#include <sys/types.h>
4376ba29 14#include <sys/mbuf.h>
543607e3
KB
15
16#include <stdlib.h>
17#include <string.h>
18#include <nlist.h>
eef33ea7 19#include <paths.h>
543607e3
KB
20#include "systat.h"
21#include "extern.h"
22
23static struct mbstat *mb;
24
25char *mtnames[] = {
26 "free",
27 "data",
28 "headers",
29 "sockets",
30 "pcbs",
31 "routes",
32 "hosts",
33 "arps",
34 "socknames",
35 "zombies",
36 "sockopts",
37 "frags",
38 "rights",
39 "ifaddrs",
40};
41
42#define NNAMES (sizeof (mtnames) / sizeof (mtnames[0]))
4376ba29 43
d830bff6
SL
44WINDOW *
45openmbufs()
4376ba29 46{
b5eefd1e 47 return (subwin(stdscr, LINES-5-1, 0, 5, 0));
4376ba29
SL
48}
49
543607e3 50void
d830bff6
SL
51closembufs(w)
52 WINDOW *w;
4376ba29 53{
d830bff6
SL
54 if (w == NULL)
55 return;
d830bff6
SL
56 wclear(w);
57 wrefresh(w);
b5eefd1e 58 delwin(w);
4376ba29
SL
59}
60
543607e3 61void
4376ba29
SL
62labelmbufs()
63{
eef33ea7
KB
64 wmove(wnd, 0, 0); wclrtoeol(wnd);
65 mvwaddstr(wnd, 0, 10,
66 "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50 /55 /60");
4376ba29
SL
67}
68
543607e3 69void
4376ba29
SL
70showmbufs()
71{
72 register int i, j, max, index;
73 char buf[10];
74
75 if (mb == 0)
76 return;
edfbb71e 77 for (j = 0; j < wnd->maxy; j++) {
4376ba29 78 max = 0, index = -1;
edfbb71e 79 for (i = 0; i < wnd->maxy; i++)
4376ba29
SL
80 if (mb->m_mtypes[i] > max) {
81 max = mb->m_mtypes[i];
82 index = i;
83 }
84 if (max == 0)
85 break;
b5eefd1e
SL
86 if (j > NNAMES)
87 mvwprintw(wnd, 1+j, 0, "%10d", index);
88 else
89 mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
90 wmove(wnd, 1 + j, 10);
91 if (max > 60) {
4376ba29 92 sprintf(buf, " %d", max);
b5eefd1e 93 max = 60;
4376ba29
SL
94 while (max--)
95 waddch(wnd, 'X');
96 waddstr(wnd, buf);
97 } else {
98 while (max--)
99 waddch(wnd, 'X');
100 wclrtoeol(wnd);
101 }
102 mb->m_mtypes[index] = 0;
103 }
b5eefd1e 104 wmove(wnd, 1+j, 0); wclrtobot(wnd);
4376ba29 105}
d830bff6 106
86923762 107static struct nlist namelist[] = {
d830bff6
SL
108#define X_MBSTAT 0
109 { "_mbstat" },
eef33ea7 110 { "" }
d830bff6
SL
111};
112
543607e3 113int
d830bff6
SL
114initmbufs()
115{
86923762
KB
116 if (namelist[X_MBSTAT].n_type == 0) {
117 if (kvm_nlist(kd, namelist)) {
118 nlisterr(namelist);
543607e3
KB
119 return(0);
120 }
86923762 121 if (namelist[X_MBSTAT].n_type == 0) {
eef33ea7 122 error("namelist on %s failed", _PATH_UNIX);
c0b7e584 123 return(0);
d830bff6
SL
124 }
125 }
126 if (mb == 0)
127 mb = (struct mbstat *)calloc(1, sizeof (*mb));
c0b7e584 128 return(1);
d830bff6
SL
129}
130
543607e3 131void
d830bff6
SL
132fetchmbufs()
133{
86923762 134 if (namelist[X_MBSTAT].n_type == 0)
d830bff6 135 return;
142cb8a1 136 NREAD(X_MBSTAT, mb, sizeof (*mb));
d830bff6 137}