155623Sbostic /*-
2*62281Sbostic * Copyright (c) 1980, 1992, 1993
3*62281Sbostic * The Regents of the University of California. All rights reserved.
455623Sbostic *
560197Smckusick * %sccs.include.redist.c%
621452Smckusick */
721452Smckusick
815150Ssam #ifndef lint
9*62281Sbostic static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 06/06/93";
1055623Sbostic #endif /* not lint */
1115150Ssam
1255623Sbostic #include <sys/param.h>
1355623Sbostic #include <sys/types.h>
1415150Ssam #include <sys/mbuf.h>
1555623Sbostic
1655623Sbostic #include <stdlib.h>
1755623Sbostic #include <string.h>
1855623Sbostic #include <nlist.h>
1937906Sbostic #include <paths.h>
2055623Sbostic #include "systat.h"
2155623Sbostic #include "extern.h"
2215150Ssam
2355623Sbostic static struct mbstat *mb;
2455623Sbostic
2555623Sbostic char *mtnames[] = {
2655623Sbostic "free",
2755623Sbostic "data",
2855623Sbostic "headers",
2955623Sbostic "sockets",
3055623Sbostic "pcbs",
3155623Sbostic "routes",
3255623Sbostic "hosts",
3355623Sbostic "arps",
3455623Sbostic "socknames",
3555623Sbostic "zombies",
3655623Sbostic "sockopts",
3755623Sbostic "frags",
3855623Sbostic "rights",
3955623Sbostic "ifaddrs",
4055623Sbostic };
4155623Sbostic
4255623Sbostic #define NNAMES (sizeof (mtnames) / sizeof (mtnames[0]))
4355623Sbostic
4415152Ssam WINDOW *
openmbufs()4515152Ssam openmbufs()
4615150Ssam {
4719051Ssam return (subwin(stdscr, LINES-5-1, 0, 5, 0));
4815150Ssam }
4915150Ssam
5055623Sbostic void
closembufs(w)5115152Ssam closembufs(w)
5215152Ssam WINDOW *w;
5315150Ssam {
5415152Ssam if (w == NULL)
5515152Ssam return;
5615152Ssam wclear(w);
5715152Ssam wrefresh(w);
5819051Ssam delwin(w);
5915150Ssam }
6015150Ssam
6155623Sbostic void
labelmbufs()6215150Ssam labelmbufs()
6315150Ssam {
6437906Sbostic wmove(wnd, 0, 0); wclrtoeol(wnd);
6537906Sbostic mvwaddstr(wnd, 0, 10,
6637906Sbostic "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50 /55 /60");
6715150Ssam }
6815150Ssam
6955623Sbostic void
showmbufs()7015150Ssam showmbufs()
7115150Ssam {
7215150Ssam register int i, j, max, index;
7315150Ssam char buf[10];
7415150Ssam
7515150Ssam if (mb == 0)
7615150Ssam return;
7756712Selan for (j = 0; j < wnd->maxy; j++) {
7815150Ssam max = 0, index = -1;
7956712Selan for (i = 0; i < wnd->maxy; i++)
8015150Ssam if (mb->m_mtypes[i] > max) {
8115150Ssam max = mb->m_mtypes[i];
8215150Ssam index = i;
8315150Ssam }
8415150Ssam if (max == 0)
8515150Ssam break;
8619051Ssam if (j > NNAMES)
8719051Ssam mvwprintw(wnd, 1+j, 0, "%10d", index);
8819051Ssam else
8919051Ssam mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
9019051Ssam wmove(wnd, 1 + j, 10);
9119051Ssam if (max > 60) {
9215150Ssam sprintf(buf, " %d", max);
9319051Ssam max = 60;
9415150Ssam while (max--)
9515150Ssam waddch(wnd, 'X');
9615150Ssam waddstr(wnd, buf);
9715150Ssam } else {
9815150Ssam while (max--)
9915150Ssam waddch(wnd, 'X');
10015150Ssam wclrtoeol(wnd);
10115150Ssam }
10215150Ssam mb->m_mtypes[index] = 0;
10315150Ssam }
10419051Ssam wmove(wnd, 1+j, 0); wclrtobot(wnd);
10515150Ssam }
10615152Ssam
10756173Sbostic static struct nlist namelist[] = {
10815152Ssam #define X_MBSTAT 0
10915152Ssam { "_mbstat" },
11037906Sbostic { "" }
11115152Ssam };
11215152Ssam
11355623Sbostic int
initmbufs()11415152Ssam initmbufs()
11515152Ssam {
11656173Sbostic if (namelist[X_MBSTAT].n_type == 0) {
11756173Sbostic if (kvm_nlist(kd, namelist)) {
11856173Sbostic nlisterr(namelist);
11955623Sbostic return(0);
12055623Sbostic }
12156173Sbostic if (namelist[X_MBSTAT].n_type == 0) {
12237906Sbostic error("namelist on %s failed", _PATH_UNIX);
12325587Sbloom return(0);
12415152Ssam }
12515152Ssam }
12615152Ssam if (mb == 0)
12715152Ssam mb = (struct mbstat *)calloc(1, sizeof (*mb));
12825587Sbloom return(1);
12915152Ssam }
13015152Ssam
13155623Sbostic void
fetchmbufs()13215152Ssam fetchmbufs()
13315152Ssam {
13456173Sbostic if (namelist[X_MBSTAT].n_type == 0)
13515152Ssam return;
13650148Smarc NREAD(X_MBSTAT, mb, sizeof (*mb));
13715152Ssam }
138