[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.51

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