BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / systat / mbufs.c
CommitLineData
07ed1e09
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
4376ba29 7#ifndef lint
1c15e888 8static char sccsid[] = "@(#)mbufs.c 5.3 (Berkeley) 5/11/89";
07ed1e09 9#endif not lint
4376ba29
SL
10
11#include "systat.h"
12#include <sys/mbuf.h>
eef33ea7 13#include <paths.h>
4376ba29 14
d830bff6
SL
15WINDOW *
16openmbufs()
4376ba29 17{
b5eefd1e 18 return (subwin(stdscr, LINES-5-1, 0, 5, 0));
4376ba29
SL
19}
20
d830bff6
SL
21closembufs(w)
22 WINDOW *w;
4376ba29 23{
d830bff6
SL
24 if (w == NULL)
25 return;
d830bff6
SL
26 wclear(w);
27 wrefresh(w);
b5eefd1e 28 delwin(w);
4376ba29
SL
29}
30
d830bff6
SL
31struct mbstat *mb;
32
4376ba29
SL
33labelmbufs()
34{
eef33ea7
KB
35 wmove(wnd, 0, 0); wclrtoeol(wnd);
36 mvwaddstr(wnd, 0, 10,
37 "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50 /55 /60");
4376ba29
SL
38}
39
b5eefd1e 40char *mtnames[] = {
4376ba29
SL
41 "free",
42 "data",
43 "headers",
44 "sockets",
45 "pcbs",
46 "routes",
47 "hosts",
48 "arps",
49 "socknames",
50 "zombies",
51 "sockopts",
52 "frags",
2081a3b4
SL
53 "rights",
54 "ifaddrs",
4376ba29 55};
b5eefd1e 56#define NNAMES (sizeof (mtnames) / sizeof (mtnames[0]))
4376ba29
SL
57
58showmbufs()
59{
60 register int i, j, max, index;
61 char buf[10];
62
63 if (mb == 0)
64 return;
b5eefd1e 65 for (j = 0; j < wnd->_maxy; j++) {
4376ba29 66 max = 0, index = -1;
b5eefd1e 67 for (i = 0; i < wnd->_maxy; i++)
4376ba29
SL
68 if (mb->m_mtypes[i] > max) {
69 max = mb->m_mtypes[i];
70 index = i;
71 }
72 if (max == 0)
73 break;
b5eefd1e
SL
74 if (j > NNAMES)
75 mvwprintw(wnd, 1+j, 0, "%10d", index);
76 else
77 mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
78 wmove(wnd, 1 + j, 10);
79 if (max > 60) {
4376ba29 80 sprintf(buf, " %d", max);
b5eefd1e 81 max = 60;
4376ba29
SL
82 while (max--)
83 waddch(wnd, 'X');
84 waddstr(wnd, buf);
85 } else {
86 while (max--)
87 waddch(wnd, 'X');
88 wclrtoeol(wnd);
89 }
90 mb->m_mtypes[index] = 0;
91 }
b5eefd1e 92 wmove(wnd, 1+j, 0); wclrtobot(wnd);
4376ba29 93}
d830bff6
SL
94
95static struct nlist nlst[] = {
96#define X_MBSTAT 0
97 { "_mbstat" },
eef33ea7 98 { "" }
d830bff6
SL
99};
100
101initmbufs()
102{
d830bff6 103 if (nlst[X_MBSTAT].n_type == 0) {
eef33ea7 104 nlist(_PATH_UNIX, nlst);
d830bff6 105 if (nlst[X_MBSTAT].n_type == 0) {
eef33ea7 106 error("namelist on %s failed", _PATH_UNIX);
c0b7e584 107 return(0);
d830bff6
SL
108 }
109 }
110 if (mb == 0)
111 mb = (struct mbstat *)calloc(1, sizeof (*mb));
c0b7e584 112 return(1);
d830bff6
SL
113}
114
115fetchmbufs()
116{
d830bff6
SL
117 if (nlst[X_MBSTAT].n_type == 0)
118 return;
119 lseek(kmem, nlst[X_MBSTAT].n_value, L_SET);
120 read(kmem, mb, sizeof (*mb));
121}