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

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