[BACK]Return to mbufs.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Annotation of src/usr.bin/systat/mbufs.c, Revision 1.17

1.17    ! deraadt     1: /*     $OpenBSD: mbufs.c,v 1.16 2006/03/31 04:10:59 deraadt Exp $      */
1.1       deraadt     2: /*     $NetBSD: mbufs.c,v 1.2 1995/01/20 08:52:02 jtc Exp $    */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1980, 1992, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.13      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: #if 0
                     35: static char sccsid[] = "@(#)mbufs.c    8.1 (Berkeley) 6/6/93";
                     36: #endif
1.17    ! deraadt    37: static char rcsid[] = "$OpenBSD: mbufs.c,v 1.16 2006/03/31 04:10:59 deraadt Exp $";
1.1       deraadt    38: #endif /* not lint */
                     39:
                     40: #include <sys/param.h>
                     41: #include <sys/types.h>
                     42: #include <sys/mbuf.h>
1.10      angelos    43: #include <sys/sysctl.h>
1.1       deraadt    44:
                     45: #include <stdlib.h>
                     46: #include <string.h>
1.9       deraadt    47: #include <err.h>
1.1       deraadt    48: #include <paths.h>
                     49: #include "systat.h"
                     50: #include "extern.h"
                     51:
1.15      deraadt    52: static struct mbstat mb;
1.1       deraadt    53:
                     54: char *mtnames[] = {
                     55:        "free",
                     56:        "data",
                     57:        "headers",
                     58:        "sockets",
                     59:        "pcbs",
                     60:        "routes",
                     61:        "hosts",
                     62:        "arps",
                     63:        "socknames",
                     64:        "zombies",
                     65:        "sockopts",
                     66:        "frags",
                     67:        "rights",
                     68:        "ifaddrs",
                     69: };
                     70:
                     71: #define        NNAMES  (sizeof (mtnames) / sizeof (mtnames[0]))
                     72:
                     73: WINDOW *
1.11      deraadt    74: openmbufs(void)
1.1       deraadt    75: {
1.17    ! deraadt    76:        return (subwin(stdscr, LINES-1-2, 0, 2, 0));
1.1       deraadt    77: }
                     78:
                     79: void
1.11      deraadt    80: closembufs(WINDOW *w)
1.1       deraadt    81: {
                     82:        if (w == NULL)
                     83:                return;
                     84:        wclear(w);
                     85:        wrefresh(w);
                     86:        delwin(w);
                     87: }
                     88:
                     89: void
1.11      deraadt    90: labelmbufs(void)
1.1       deraadt    91: {
1.16      deraadt    92:        wmove(wnd, 0, 0);
                     93:        wclrtoeol(wnd);
1.1       deraadt    94:        mvwaddstr(wnd, 0, 10,
                     95:            "/0   /5   /10  /15  /20  /25  /30  /35  /40  /45  /50  /55  /60");
                     96: }
                     97:
                     98: void
1.11      deraadt    99: showmbufs(void)
1.1       deraadt   100: {
1.16      deraadt   101:        int i, j, max, ind;
1.4       deraadt   102:        char buf[13];
1.1       deraadt   103:
1.2       mickey    104:        for (j = 0; j < wnd->_maxy; j++) {
1.16      deraadt   105:                max = 0, ind = -1;
1.2       mickey    106:                for (i = 0; i < wnd->_maxy; i++)
1.15      deraadt   107:                        if (mb.m_mtypes[i] > max) {
                    108:                                max = mb.m_mtypes[i];
1.16      deraadt   109:                                ind = i;
1.1       deraadt   110:                        }
                    111:                if (max == 0)
                    112:                        break;
                    113:                if (j > NNAMES)
1.16      deraadt   114:                        mvwprintw(wnd, 1+j, 0, "%10d", ind);
1.1       deraadt   115:                else
1.16      deraadt   116:                        mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[ind]);
1.1       deraadt   117:                wmove(wnd, 1 + j, 10);
                    118:                if (max > 60) {
1.4       deraadt   119:                        snprintf(buf, sizeof buf, " %d", max);
1.1       deraadt   120:                        max = 60;
                    121:                        while (max--)
                    122:                                waddch(wnd, 'X');
                    123:                        waddstr(wnd, buf);
                    124:                } else {
                    125:                        while (max--)
                    126:                                waddch(wnd, 'X');
                    127:                        wclrtoeol(wnd);
                    128:                }
1.16      deraadt   129:                mb.m_mtypes[ind] = 0;
1.1       deraadt   130:        }
1.16      deraadt   131:        wmove(wnd, 1+j, 0);
                    132:        wclrtobot(wnd);
1.1       deraadt   133: }
                    134:
                    135:
1.15      deraadt   136: void
                    137: fetchmbufs(void)
1.1       deraadt   138: {
1.15      deraadt   139:        int mib[2];
                    140:        size_t size = sizeof (mb);
1.5       ericj     141:
1.15      deraadt   142:        mib[0] = CTL_KERN;
                    143:        mib[1] = KERN_MBSTAT;
                    144:        if (sysctl(mib, 2, &mb, &size, NULL, 0) < 0)
                    145:                err(1, "sysctl(KERN_MBSTAT) failed");
1.1       deraadt   146: }
                    147:
1.15      deraadt   148: int
                    149: initmbufs(void)
1.1       deraadt   150: {
1.15      deraadt   151:        return (1);
1.1       deraadt   152: }