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

Annotation of src/usr.bin/netstat/if.c, Revision 1.45

1.45    ! otto        1: /*     $OpenBSD: if.c,v 1.44 2005/06/08 04:47:04 henning Exp $ */
1.6       deraadt     2: /*     $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $      */
1.1       deraadt     3:
                      4: /*
                      5:  * Copyright (c) 1983, 1988, 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.35      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[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
                     36: #else
1.45    ! otto       37: static char *rcsid = "$OpenBSD: if.c,v 1.44 2005/06/08 04:47:04 henning Exp $";
1.1       deraadt    38: #endif
                     39: #endif /* not lint */
                     40:
                     41: #include <sys/types.h>
                     42: #include <sys/protosw.h>
                     43: #include <sys/socket.h>
                     44:
                     45: #include <net/if.h>
                     46: #include <net/if_dl.h>
1.5       deraadt    47: #include <net/if_types.h>
1.1       deraadt    48: #include <netinet/in.h>
                     49: #include <netinet/in_var.h>
1.11      millert    50: #include <netinet/if_ether.h>
1.8       mickey     51: #include <netipx/ipx.h>
                     52: #include <netipx/ipx_if.h>
1.1       deraadt    53: #include <arpa/inet.h>
                     54:
1.13      millert    55: #include <limits.h>
1.1       deraadt    56: #include <signal.h>
                     57: #include <stdio.h>
1.36      david      58: #include <stdlib.h>
1.1       deraadt    59: #include <string.h>
                     60: #include <unistd.h>
                     61:
                     62: #include "netstat.h"
                     63:
                     64: #define        YES     1
                     65: #define        NO      0
                     66:
1.29      millert    67: static void sidewaysintpr(u_int, u_long);
                     68: static void catchalarm(int);
1.1       deraadt    69:
                     70: /*
                     71:  * Print a description of the network interfaces.
1.3       deraadt    72:  * NOTE: ifnetaddr is the location of the kernel global "ifnet",
                     73:  * which is a TAILQ_HEAD.
1.1       deraadt    74:  */
                     75: void
1.33      deraadt    76: intpr(int interval, u_long ifnetaddr)
1.1       deraadt    77: {
                     78:        struct ifnet ifnet;
                     79:        union {
                     80:                struct ifaddr ifa;
                     81:                struct in_ifaddr in;
1.18      itojun     82: #ifdef INET6
                     83:                struct in6_ifaddr in6;
                     84: #endif
1.8       mickey     85:                struct ipx_ifaddr ipx;
1.1       deraadt    86:        } ifaddr;
1.33      deraadt    87:        u_long total, ifaddraddr;
1.1       deraadt    88:        struct sockaddr *sa;
1.3       deraadt    89:        struct ifnet_head ifhead;       /* TAILQ_HEAD */
                     90:        char name[IFNAMSIZ];
1.1       deraadt    91:
                     92:        if (ifnetaddr == 0) {
                     93:                printf("ifnet: symbol not defined\n");
                     94:                return;
                     95:        }
                     96:        if (interval) {
                     97:                sidewaysintpr((unsigned)interval, ifnetaddr);
                     98:                return;
                     99:        }
1.3       deraadt   100:
                    101:        /*
                    102:         * Find the pointer to the first ifnet structure.  Replace
                    103:         * the pointer to the TAILQ_HEAD with the actual pointer
                    104:         * to the first list element.
                    105:         */
1.43      jaredy    106:        if (kread(ifnetaddr, &ifhead, sizeof ifhead))
1.1       deraadt   107:                return;
1.45    ! otto      108:        ifnetaddr = (u_long)TAILQ_FIRST(&ifhead);
1.3       deraadt   109:
1.22      camield   110:        printf("%-7.7s %-5.5s %-11.11s %-17.17s ",
1.33      deraadt   111:            "Name", "Mtu", "Network", "Address");
1.22      camield   112:        if (bflag)
                    113:                printf("%10.10s %10.10s", "Ibytes", "Obytes");
                    114:        else
                    115:                printf("%8.8s %5.5s %8.8s %5.5s %5.5s",
                    116:                    "Ipkts", "Ierrs", "Opkts", "Oerrs", "Colls");
1.1       deraadt   117:        if (tflag)
                    118:                printf(" %s", "Time");
                    119:        if (dflag)
                    120:                printf(" %s", "Drop");
                    121:        putchar('\n');
                    122:        ifaddraddr = 0;
                    123:        while (ifnetaddr || ifaddraddr) {
                    124:                struct sockaddr_in *sin;
1.18      itojun    125: #ifdef INET6
                    126:                struct sockaddr_in6 *sin6;
                    127: #endif
1.27      mpech     128:                char *cp;
1.1       deraadt   129:                int n, m;
                    130:
                    131:                if (ifaddraddr == 0) {
1.43      jaredy    132:                        if (kread(ifnetaddr, &ifnet, sizeof ifnet))
1.1       deraadt   133:                                return;
1.3       deraadt   134:                        bcopy(ifnet.if_xname, name, IFNAMSIZ);
                    135:                        name[IFNAMSIZ - 1] = '\0';      /* sanity */
1.45    ! otto      136:                        ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_list);
1.3       deraadt   137:                        if (interface != 0 && strcmp(name, interface) != 0)
1.1       deraadt   138:                                continue;
1.10      millert   139:                        cp = strchr(name, '\0');
1.1       deraadt   140:                        if ((ifnet.if_flags & IFF_UP) == 0)
                    141:                                *cp++ = '*';
                    142:                        *cp = '\0';
1.45    ! otto      143:                        ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrlist);
1.1       deraadt   144:                }
1.25      brian     145:
                    146:                if (qflag) {
                    147:                        total = ifnet.if_ibytes + ifnet.if_obytes +
                    148:                            ifnet.if_ipackets + ifnet.if_ierrors +
                    149:                            ifnet.if_opackets + ifnet.if_oerrors +
                    150:                            ifnet.if_collisions;
                    151:                        if (tflag)
                    152:                                total += ifnet.if_timer;
                    153:                        if (dflag)
                    154:                                total += ifnet.if_snd.ifq_drops;
                    155:                        if (total == 0) {
                    156:                                ifaddraddr = 0;
                    157:                                continue;
                    158:                        }
                    159:                }
                    160:
1.16      mickey    161:                printf("%-7.7s %-5ld ", name, ifnet.if_mtu);
1.1       deraadt   162:                if (ifaddraddr == 0) {
                    163:                        printf("%-11.11s ", "none");
1.37      deraadt   164:                        printf("%-17.17s ", "none");
1.1       deraadt   165:                } else {
1.43      jaredy    166:                        if (kread(ifaddraddr, &ifaddr, sizeof ifaddr)) {
1.1       deraadt   167:                                ifaddraddr = 0;
                    168:                                continue;
                    169:                        }
                    170: #define CP(x) ((char *)(x))
                    171:                        cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
                    172:                                CP(&ifaddr); sa = (struct sockaddr *)cp;
                    173:                        switch (sa->sa_family) {
                    174:                        case AF_UNSPEC:
                    175:                                printf("%-11.11s ", "none");
                    176:                                printf("%-17.17s ", "none");
                    177:                                break;
                    178:                        case AF_INET:
                    179:                                sin = (struct sockaddr_in *)sa;
                    180: #ifdef notdef
                    181:                                /* can't use inet_makeaddr because kernel
                    182:                                 * keeps nets unshifted.
                    183:                                 */
                    184:                                in = inet_makeaddr(ifaddr.in.ia_subnet,
1.30      deraadt   185:                                    INADDR_ANY);
1.20      itojun    186:                                cp = netname(in.s_addr,
1.30      deraadt   187:                                    ifaddr.in.ia_subnetmask);
1.1       deraadt   188: #else
1.20      itojun    189:                                cp = netname(ifaddr.in.ia_subnet,
                    190:                                    ifaddr.in.ia_subnetmask);
1.1       deraadt   191: #endif
1.20      itojun    192:                                if (vflag)
                    193:                                        n = strlen(cp) < 11 ? 11 : strlen(cp);
                    194:                                else
                    195:                                        n = 11;
                    196:                                printf("%-*.*s ", n, n, cp);
                    197:                                cp = routename(sin->sin_addr.s_addr);
                    198:                                if (vflag)
                    199:                                        n = strlen(cp) < 17 ? 17 : strlen(cp);
                    200:                                else
                    201:                                        n = 17;
                    202:                                printf("%-*.*s ", n, n, cp);
1.1       deraadt   203:
                    204:                                if (aflag) {
                    205:                                        u_long multiaddr;
                    206:                                        struct in_multi inm;
1.28      mickey    207:
1.45    ! otto      208:                                        multiaddr = (u_long)LIST_FIRST(&ifaddr.in.ia_multiaddrs);
1.1       deraadt   209:                                        while (multiaddr != 0) {
1.43      jaredy    210:                                                kread(multiaddr, &inm, sizeof inm);
1.19      itojun    211:                                                printf("\n%25s %-17.17s ", "",
1.1       deraadt   212:                                                    routename(inm.inm_addr.s_addr));
1.45    ! otto      213:                                                multiaddr = (u_long)LIST_NEXT(&inm, inm_list);
1.1       deraadt   214:                                        }
1.8       mickey    215:                                }
                    216:                                break;
1.18      itojun    217: #ifdef INET6
                    218:                        case AF_INET6:
                    219:                                sin6 = (struct sockaddr_in6 *)sa;
1.34      itojun    220: #ifdef __KAME__
1.20      itojun    221:                                if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
                    222:                                        sin6->sin6_scope_id =
1.30      deraadt   223:                                            ntohs(*(u_int16_t *)
1.38      deraadt   224:                                            &sin6->sin6_addr.s6_addr[2]);
1.20      itojun    225:                                        sin6->sin6_addr.s6_addr[2] = 0;
                    226:                                        sin6->sin6_addr.s6_addr[3] = 0;
                    227:                                }
                    228: #endif
                    229:                                cp = netname6(&ifaddr.in6.ia_addr,
1.30      deraadt   230:                                    &ifaddr.in6.ia_prefixmask.sin6_addr);
1.20      itojun    231:                                if (vflag)
                    232:                                        n = strlen(cp) < 11 ? 11 : strlen(cp);
                    233:                                else
                    234:                                        n = 11;
                    235:                                printf("%-*.*s ", n, n, cp);
                    236:                                cp = routename6(sin6);
                    237:                                if (vflag)
                    238:                                        n = strlen(cp) < 17 ? 17 : strlen(cp);
                    239:                                else
                    240:                                        n = 17;
                    241:                                printf("%-*.*s ", n, n, cp);
1.19      itojun    242:                                if (aflag) {
                    243:                                        u_long multiaddr;
                    244:                                        struct in6_multi inm;
1.31      itojun    245:                                        struct sockaddr_in6 m6;
1.28      mickey    246:
1.45    ! otto      247:                                        multiaddr = (u_long)LIST_FIRST(&ifaddr.in6.ia6_multiaddrs);
1.19      itojun    248:                                        while (multiaddr != 0) {
1.43      jaredy    249:                                                kread(multiaddr, &inm, sizeof inm);
1.31      itojun    250:                                                memset(&m6, 0, sizeof(m6));
                    251:                                                m6.sin6_len = sizeof(struct sockaddr_in6);
                    252:                                                m6.sin6_family = AF_INET6;
                    253:                                                m6.sin6_addr = inm.in6m_addr;
1.34      itojun    254: #ifdef __KAME__
1.32      itojun    255:                                                if (IN6_IS_ADDR_MC_LINKLOCAL(&m6.sin6_addr)) {
1.31      itojun    256:                                                        m6.sin6_scope_id =
                    257:                                                            ntohs(*(u_int16_t *)
1.38      deraadt   258:                                                            &m6.sin6_addr.s6_addr[2]);
1.31      itojun    259:                                                        m6.sin6_addr.s6_addr[2] = 0;
                    260:                                                        m6.sin6_addr.s6_addr[3] = 0;
                    261:                                                }
                    262: #endif
                    263:                                                cp = routename6(&m6);
1.19      itojun    264:                                                if (vflag)
1.31      itojun    265:                                                        n = strlen(cp) < 17 ? 17 : strlen(cp);
1.19      itojun    266:                                                else
                    267:                                                        n = 17;
                    268:                                                printf("\n%25s %-*.*s ", "",
1.31      itojun    269:                                                    n, n, cp);
1.45    ! otto      270:                                                multiaddr = (u_long)LIST_NEXT(&inm, in6m_entry);
1.19      itojun    271:                                        }
                    272:                                }
1.18      itojun    273:                                break;
                    274: #endif
1.8       mickey    275:                        case AF_IPX:
                    276:                                {
                    277:                                struct sockaddr_ipx *sipx =
                    278:                                        (struct sockaddr_ipx *)sa;
                    279:                                u_long net;
                    280:                                char netnum[8];
                    281:
1.17      deraadt   282:                                *(union ipx_net *)&net = sipx->sipx_addr.ipx_net;
                    283:                                snprintf(netnum, sizeof netnum, "%xH",
                    284:                                    ntohl(net));
1.8       mickey    285:                                upHex(netnum);
                    286:                                printf("ipx:%-8s", netnum);
                    287:                                printf("%-17s ",
                    288:                                    ipx_phost((struct sockaddr *)sipx));
1.1       deraadt   289:                                }
1.15      denny     290:                                break;
                    291:                        case AF_APPLETALK:
                    292:                                printf("atlk:%-12s",atalk_print(sa,0x10) );
                    293:                                printf("%-12s ",atalk_print(sa,0x0b) );
1.1       deraadt   294:                                break;
                    295:                        case AF_LINK:
                    296:                                {
                    297:                                struct sockaddr_dl *sdl =
                    298:                                        (struct sockaddr_dl *)sa;
1.5       deraadt   299:                                m = printf("%-11.11s ", "<Link>");
                    300:                                if (sdl->sdl_type == IFT_ETHER ||
1.42      mpf       301:                                    sdl->sdl_type == IFT_CARP ||
1.23      fgsch     302:                                    sdl->sdl_type == IFT_FDDI ||
                    303:                                    sdl->sdl_type == IFT_ISO88025)
1.5       deraadt   304:                                        printf("%-17.17s ",
1.11      millert   305:                                            ether_ntoa((struct ether_addr *)LLADDR(sdl)));
1.5       deraadt   306:                                else {
                    307:                                        cp = (char *)LLADDR(sdl);
                    308:                                        n = sdl->sdl_alen;
                    309:                                        goto hexprint;
                    310:                                }
1.1       deraadt   311:                                }
1.5       deraadt   312:                                break;
1.1       deraadt   313:                        default:
                    314:                                m = printf("(%d)", sa->sa_family);
                    315:                                for (cp = sa->sa_len + (char *)sa;
                    316:                                        --cp > sa->sa_data && (*cp == 0);) {}
                    317:                                n = cp - sa->sa_data + 1;
                    318:                                cp = sa->sa_data;
                    319:                        hexprint:
                    320:                                while (--n >= 0)
                    321:                                        m += printf("%x%c", *cp++ & 0xff,
                    322:                                                    n > 0 ? '.' : ' ');
                    323:                                m = 30 - m;
                    324:                                while (m-- > 0)
                    325:                                        putchar(' ');
                    326:                                break;
                    327:                        }
1.45    ! otto      328:                        ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_list);
1.1       deraadt   329:                }
1.22      camield   330:                if (bflag)
                    331:                        printf("%10lu %10lu",
                    332:                            ifnet.if_ibytes, ifnet.if_obytes);
                    333:                else
                    334:                        printf("%8lu %5lu %8lu %5lu %5lu",
                    335:                            ifnet.if_ipackets, ifnet.if_ierrors,
                    336:                            ifnet.if_opackets, ifnet.if_oerrors,
                    337:                            ifnet.if_collisions);
1.1       deraadt   338:                if (tflag)
1.22      camield   339:                        printf(" %4d", ifnet.if_timer);
1.1       deraadt   340:                if (dflag)
1.22      camield   341:                        printf(" %4d", ifnet.if_snd.ifq_drops);
1.1       deraadt   342:                putchar('\n');
                    343:        }
                    344: }
                    345:
1.4       deraadt   346: #define        MAXIF   100
1.1       deraadt   347: struct iftot {
1.3       deraadt   348:        char    ift_name[IFNAMSIZ];     /* interface name */
1.40      dhartmei  349:        u_long  ift_ip;                 /* input packets */
                    350:        u_long  ift_ib;                 /* input bytes */
                    351:        u_long  ift_ie;                 /* input errors */
                    352:        u_long  ift_op;                 /* output packets */
                    353:        u_long  ift_ob;                 /* output bytes */
                    354:        u_long  ift_oe;                 /* output errors */
                    355:        u_long  ift_co;                 /* collisions */
                    356:        u_long  ift_dr;                 /* drops */
1.1       deraadt   357: } iftot[MAXIF];
                    358:
1.26      millert   359: volatile sig_atomic_t signalled;       /* set if alarm goes off "early" */
1.1       deraadt   360:
                    361: /*
                    362:  * Print a running summary of interface statistics.
                    363:  * Repeat display every interval seconds, showing statistics
                    364:  * collected over that interval.  Assumes that interval is non-zero.
                    365:  * First line printed at top of screen is always cumulative.
                    366:  */
                    367: static void
1.33      deraadt   368: sidewaysintpr(unsigned int interval, u_long off)
1.1       deraadt   369: {
                    370:        struct ifnet ifnet;
                    371:        u_long firstifnet;
1.27      mpech     372:        struct iftot *ip, *total;
                    373:        int line;
1.1       deraadt   374:        struct iftot *lastif, *sum, *interesting;
1.3       deraadt   375:        struct ifnet_head ifhead;       /* TAILQ_HEAD */
1.26      millert   376:        sigset_t emptyset;
1.1       deraadt   377:
1.3       deraadt   378:        /*
                    379:         * Find the pointer to the first ifnet structure.  Replace
                    380:         * the pointer to the TAILQ_HEAD with the actual pointer
                    381:         * to the first list element.
                    382:         */
1.43      jaredy    383:        if (kread(off, &ifhead, sizeof ifhead))
1.1       deraadt   384:                return;
1.45    ! otto      385:        firstifnet = (u_long)TAILQ_FIRST(&ifhead);
1.3       deraadt   386:
1.1       deraadt   387:        lastif = iftot;
                    388:        sum = iftot + MAXIF - 1;
                    389:        total = sum - 1;
1.4       deraadt   390:        interesting = (interface == NULL) ? iftot : NULL;
1.1       deraadt   391:        for (off = firstifnet, ip = iftot; off;) {
1.43      jaredy    392:                if (kread(off, &ifnet, sizeof ifnet))
1.1       deraadt   393:                        break;
1.6       deraadt   394:                bzero(ip->ift_name, sizeof(ip->ift_name));
1.22      camield   395:                snprintf(ip->ift_name, IFNAMSIZ, "%s", ifnet.if_xname);
1.6       deraadt   396:                if (interface && strcmp(ifnet.if_xname, interface) == 0)
1.1       deraadt   397:                        interesting = ip;
                    398:                ip++;
                    399:                if (ip >= iftot + MAXIF - 2)
                    400:                        break;
1.45    ! otto      401:                off = (u_long)TAILQ_NEXT(&ifnet, if_list);
1.4       deraadt   402:        }
                    403:        if (interesting == NULL) {
                    404:                fprintf(stderr, "%s: %s: unknown interface\n",
                    405:                    __progname, interface);
                    406:                exit(1);
1.1       deraadt   407:        }
                    408:        lastif = ip;
                    409:
                    410:        (void)signal(SIGALRM, catchalarm);
                    411:        signalled = NO;
                    412:        (void)alarm(interval);
                    413: banner:
1.22      camield   414:        if (bflag)
                    415:                printf("%7.7s in %8.8s %6.6s out %5.5s",
                    416:                    interesting->ift_name, " ",
                    417:                    interesting->ift_name, " ");
                    418:        else
                    419:                printf("%5.5s in %5.5s%5.5s out %5.5s %5.5s",
                    420:                    interesting->ift_name, " ",
                    421:                    interesting->ift_name, " ", " ");
                    422:        if (dflag)
                    423:                printf(" %5.5s", " ");
1.1       deraadt   424:        if (lastif - iftot > 0) {
1.22      camield   425:                if (bflag)
                    426:                        printf("  %7.7s in %8.8s %6.6s out %5.5s",
                    427:                            "total", " ", "total", " ");
                    428:                else
                    429:                        printf("  %5.5s in %5.5s%5.5s out %5.5s %5.5s",
                    430:                            "total", " ", "total", " ", " ");
1.1       deraadt   431:                if (dflag)
1.22      camield   432:                        printf(" %5.5s", " ");
1.1       deraadt   433:        }
                    434:        for (ip = iftot; ip < iftot + MAXIF; ip++) {
                    435:                ip->ift_ip = 0;
1.22      camield   436:                ip->ift_ib = 0;
1.1       deraadt   437:                ip->ift_ie = 0;
                    438:                ip->ift_op = 0;
1.22      camield   439:                ip->ift_ob = 0;
1.1       deraadt   440:                ip->ift_oe = 0;
                    441:                ip->ift_co = 0;
                    442:                ip->ift_dr = 0;
                    443:        }
                    444:        putchar('\n');
1.22      camield   445:        if (bflag)
                    446:                printf("%10.10s %8.8s %10.10s %5.5s",
                    447:                    "bytes", " ", "bytes", " ");
                    448:        else
                    449:                printf("%8.8s %5.5s %8.8s %5.5s %5.5s",
                    450:                    "packets", "errs", "packets", "errs", "colls");
1.1       deraadt   451:        if (dflag)
                    452:                printf(" %5.5s", "drops");
1.22      camield   453:        if (lastif - iftot > 0) {
                    454:                if (bflag)
                    455:                        printf("  %10.10s %8.8s %10.10s %5.5s",
                    456:                            "bytes", " ", "bytes", " ");
                    457:                else
                    458:                        printf("  %8.8s %5.5s %8.8s %5.5s %5.5s",
                    459:                            "packets", "errs", "packets", "errs", "colls");
                    460:                if (dflag)
                    461:                        printf(" %5.5s", "drops");
                    462:        }
1.1       deraadt   463:        putchar('\n');
                    464:        fflush(stdout);
                    465:        line = 0;
                    466: loop:
                    467:        sum->ift_ip = 0;
1.22      camield   468:        sum->ift_ib = 0;
1.1       deraadt   469:        sum->ift_ie = 0;
                    470:        sum->ift_op = 0;
1.22      camield   471:        sum->ift_ob = 0;
1.1       deraadt   472:        sum->ift_oe = 0;
                    473:        sum->ift_co = 0;
                    474:        sum->ift_dr = 0;
                    475:        for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
1.43      jaredy    476:                if (kread(off, &ifnet, sizeof ifnet)) {
1.1       deraadt   477:                        off = 0;
                    478:                        continue;
                    479:                }
                    480:                if (ip == interesting) {
1.22      camield   481:                        if (bflag)
                    482:                                printf("%10lu %8.8s %10lu %5.5s",
                    483:                                    ifnet.if_ibytes - ip->ift_ib, " ",
                    484:                                    ifnet.if_obytes - ip->ift_ob, " ");
                    485:                        else
                    486:                                printf("%8lu %5lu %8lu %5lu %5lu",
                    487:                                    ifnet.if_ipackets - ip->ift_ip,
                    488:                                    ifnet.if_ierrors - ip->ift_ie,
                    489:                                    ifnet.if_opackets - ip->ift_op,
                    490:                                    ifnet.if_oerrors - ip->ift_oe,
                    491:                                    ifnet.if_collisions - ip->ift_co);
1.1       deraadt   492:                        if (dflag)
1.41      jaredy    493:                                printf(" %5lu",
1.1       deraadt   494:                                    ifnet.if_snd.ifq_drops - ip->ift_dr);
                    495:                }
                    496:                ip->ift_ip = ifnet.if_ipackets;
1.22      camield   497:                ip->ift_ib = ifnet.if_ibytes;
1.1       deraadt   498:                ip->ift_ie = ifnet.if_ierrors;
                    499:                ip->ift_op = ifnet.if_opackets;
1.22      camield   500:                ip->ift_ob = ifnet.if_obytes;
1.1       deraadt   501:                ip->ift_oe = ifnet.if_oerrors;
                    502:                ip->ift_co = ifnet.if_collisions;
                    503:                ip->ift_dr = ifnet.if_snd.ifq_drops;
                    504:                sum->ift_ip += ip->ift_ip;
1.22      camield   505:                sum->ift_ib += ip->ift_ib;
1.1       deraadt   506:                sum->ift_ie += ip->ift_ie;
                    507:                sum->ift_op += ip->ift_op;
1.22      camield   508:                sum->ift_ob += ip->ift_ob;
1.1       deraadt   509:                sum->ift_oe += ip->ift_oe;
                    510:                sum->ift_co += ip->ift_co;
                    511:                sum->ift_dr += ip->ift_dr;
1.45    ! otto      512:                off = (u_long)TAILQ_NEXT(&ifnet, if_list);
1.1       deraadt   513:        }
                    514:        if (lastif - iftot > 0) {
1.22      camield   515:                if (bflag)
                    516:                        printf("  %10lu %8.8s %10lu %5.5s",
1.41      jaredy    517:                            sum->ift_ib - total->ift_ib, " ",
                    518:                            sum->ift_ob - total->ift_ob, " ");
1.22      camield   519:                else
                    520:                        printf("  %8lu %5lu %8lu %5lu %5lu",
1.41      jaredy    521:                            sum->ift_ip - total->ift_ip,
                    522:                            sum->ift_ie - total->ift_ie,
                    523:                            sum->ift_op - total->ift_op,
                    524:                            sum->ift_oe - total->ift_oe,
                    525:                            sum->ift_co - total->ift_co);
1.1       deraadt   526:                if (dflag)
1.41      jaredy    527:                        printf(" %5lu", sum->ift_dr - total->ift_dr);
1.1       deraadt   528:        }
                    529:        *total = *sum;
                    530:        putchar('\n');
                    531:        fflush(stdout);
                    532:        line++;
1.26      millert   533:        sigemptyset(&emptyset);
                    534:        if (!signalled)
                    535:                sigsuspend(&emptyset);
1.1       deraadt   536:        signalled = NO;
                    537:        (void)alarm(interval);
                    538:        if (line == 21)
                    539:                goto banner;
                    540:        goto loop;
                    541:        /*NOTREACHED*/
                    542: }
                    543:
                    544: /*
                    545:  * Called if an interval expires before sidewaysintpr has completed a loop.
                    546:  * Sets a flag to not wait for the alarm.
                    547:  */
                    548: static void
1.33      deraadt   549: catchalarm(int signo)
1.1       deraadt   550: {
                    551:        signalled = YES;
                    552: }