]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/netstat/if.c
This commit was generated by cvs2svn to compensate for changes in r83174,
[FreeBSD/FreeBSD.git] / usr.bin / netstat / if.c
1 /*
2  * Copyright (c) 1983, 1988, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #ifndef lint
35 /*
36 static char sccsid[] = "@(#)if.c        8.3 (Berkeley) 4/28/95";
37 */
38 static const char rcsid[] =
39   "$FreeBSD$";
40 #endif /* not lint */
41
42 #include <sys/types.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/sysctl.h>
46 #include <sys/time.h>
47
48 #include <net/if.h>
49 #include <net/if_var.h>
50 #include <net/if_dl.h>
51 #include <net/if_types.h>
52 #include <net/bridge.h>
53 #include <net/ethernet.h>
54 #include <netinet/in.h>
55 #include <netinet/in_var.h>
56 #include <netipx/ipx.h>
57 #include <netipx/ipx_if.h>
58 #ifdef NS
59 #include <netns/ns.h>
60 #include <netns/ns_if.h>
61 #endif
62 #ifdef ISO
63 #include <netiso/iso.h>
64 #include <netiso/iso_var.h>
65 #endif
66 #include <arpa/inet.h>
67
68 #include <signal.h>
69 #include <stdio.h>
70 #include <stdlib.h>
71 #include <string.h>
72 #include <unistd.h>
73
74 #include "netstat.h"
75
76 #define YES     1
77 #define NO      0
78
79 static void sidewaysintpr (u_int, u_long);
80 static void catchalarm (int);
81
82 #ifdef INET6
83 char *netname6 (struct sockaddr_in6 *, struct in6_addr *);
84 static char ntop_buf[INET6_ADDRSTRLEN];         /* for inet_ntop() */
85 static int bdg_done;
86 #endif
87
88 /* print bridge statistics */
89 void
90 bdg_stats(u_long dummy __unused, char *name, int af __unused)
91 {
92     int i;
93     size_t slen ;
94     struct bdg_stats s ;
95     int mib[4] ;
96
97     slen = sizeof(s);
98
99     mib[0] = CTL_NET ;
100     mib[1] = PF_LINK ;
101     mib[2] = IFT_ETHER ;
102     mib[3] = PF_BDG ;
103     if (sysctl(mib,4, &s,&slen,NULL,0)==-1)
104         return ; /* no bridging */
105 #ifdef INET6
106     if (bdg_done != 0)
107         return;
108     else
109         bdg_done = 1;
110 #endif
111     printf("-- Bridging statistics (%s) --\n", name) ;
112     printf(
113 "Name          In      Out  Forward     Drop    Bcast    Mcast    Local  Unknown\n");
114     for (i = 0 ; i < 16 ; i++) {
115         if (s.s[i].name[0])
116         printf("%-6s %9ld%9ld%9ld%9ld%9ld%9ld%9ld%9ld\n",
117           s.s[i].name,
118           s.s[i].p_in[(int)BDG_IN],
119           s.s[i].p_in[(int)BDG_OUT],
120           s.s[i].p_in[(int)BDG_FORWARD],
121           s.s[i].p_in[(int)BDG_DROP],
122           s.s[i].p_in[(int)BDG_BCAST],
123           s.s[i].p_in[(int)BDG_MCAST],
124           s.s[i].p_in[(int)BDG_LOCAL],
125           s.s[i].p_in[(int)BDG_UNKNOWN] );
126     }
127 }
128
129
130
131
132 /*
133  * Display a formatted value, or a '-' in the same space.
134  */
135 static void
136 show_stat(const char *fmt, int width, u_long value, short showvalue)
137 {
138         char newfmt[32];
139
140         /* Construct the format string */
141         if (showvalue) {
142                 sprintf(newfmt, "%%%d%s", width, fmt);
143                 printf(newfmt, value);
144         } else {
145                 sprintf(newfmt, "%%%ds", width);
146                 printf(newfmt, "-");
147         }
148 }
149
150
151
152 /*
153  * Print a description of the network interfaces.
154  */
155 void
156 intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *))
157 {
158         struct ifnet ifnet;
159         struct ifnethead ifnethead;
160         union {
161                 struct ifaddr ifa;
162                 struct in_ifaddr in;
163 #ifdef INET6
164                 struct in6_ifaddr in6;
165 #endif
166                 struct ipx_ifaddr ipx;
167 #ifdef NS
168                 struct ns_ifaddr ns;
169 #endif
170 #ifdef ISO
171                 struct iso_ifaddr iso;
172 #endif
173         } ifaddr;
174         u_long ifaddraddr;
175         u_long ifaddrfound;
176         u_long ifnetfound;
177         u_long opackets;
178         u_long ipackets;
179         u_long obytes;
180         u_long ibytes;
181         u_long oerrors;
182         u_long ierrors;
183         u_long collisions;
184         short timer;
185         int drops;
186         struct sockaddr *sa = NULL;
187         char name[32], tname[16];
188         short network_layer;
189         short link_layer;
190
191         if (ifnetaddr == 0) {
192                 printf("ifnet: symbol not defined\n");
193                 return;
194         }
195         if (interval) {
196                 sidewaysintpr((unsigned)interval, ifnetaddr);
197                 return;
198         }
199         if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead))
200                 return;
201         ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
202         if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
203                 return;
204
205         if (!pfunc) {
206                 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
207                        "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
208                 if (bflag)
209                         printf(" %10.10s","Ibytes");
210                 printf(" %8.8s %5.5s", "Opkts", "Oerrs");
211                 if (bflag)
212                         printf(" %10.10s","Obytes");
213                 printf(" %5s", "Coll");
214                 if (tflag)
215                         printf(" %s", "Time");
216                 if (dflag)
217                         printf(" %s", "Drop");
218                 putchar('\n');
219         }
220         ifaddraddr = 0;
221         while (ifnetaddr || ifaddraddr) {
222                 struct sockaddr_in *sin;
223 #ifdef INET6
224                 struct sockaddr_in6 *sin6;
225 #endif
226                 register char *cp;
227                 int n, m;
228
229                 network_layer = 0;
230                 link_layer = 0;
231
232                 if (ifaddraddr == 0) {
233                         ifnetfound = ifnetaddr;
234                         if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
235                             kread((u_long)ifnet.if_name, tname, 16))
236                                 return;
237                         tname[15] = '\0';
238                         ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
239                         snprintf(name, 32, "%s%d", tname, ifnet.if_unit);
240                         if (interface != 0 && (strcmp(name, interface) != 0))
241                                 continue;
242                         cp = index(name, '\0');
243
244                         if (pfunc) {
245                                 (*pfunc)(name);
246                                 continue;
247                         }
248
249                         if ((ifnet.if_flags&IFF_UP) == 0)
250                                 *cp++ = '*';
251                         *cp = '\0';
252                         ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead);
253                 }
254                 printf("%-5.5s %-5lu ", name, ifnet.if_mtu);
255                 ifaddrfound = ifaddraddr;
256
257                 /*
258                  * Get the interface stats.  These may get
259                  * overriden below on a per-interface basis.
260                  */
261                 opackets = ifnet.if_opackets;
262                 ipackets = ifnet.if_ipackets;
263                 obytes = ifnet.if_obytes;
264                 ibytes = ifnet.if_ibytes;
265                 oerrors = ifnet.if_oerrors;
266                 ierrors = ifnet.if_ierrors;
267                 collisions = ifnet.if_collisions;
268                 timer = ifnet.if_timer;
269                 drops = ifnet.if_snd.ifq_drops;
270
271                 if (ifaddraddr == 0) {
272                         printf("%-13.13s ", "none");
273                         printf("%-15.15s ", "none");
274                 } else {
275                         if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
276                                 ifaddraddr = 0;
277                                 continue;
278                         }
279 #define CP(x) ((char *)(x))
280                         cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
281                                 CP(&ifaddr);
282                         sa = (struct sockaddr *)cp;
283                         switch (sa->sa_family) {
284                         case AF_UNSPEC:
285                                 printf("%-13.13s ", "none");
286                                 printf("%-15.15s ", "none");
287                                 break;
288                         case AF_INET:
289                                 sin = (struct sockaddr_in *)sa;
290 #ifdef notdef
291                                 /* can't use inet_makeaddr because kernel
292                                  * keeps nets unshifted.
293                                  */
294                                 in = inet_makeaddr(ifaddr.in.ia_subnet,
295                                         INADDR_ANY);
296                                 printf("%-13.13s ", netname(in.s_addr,
297                                     ifaddr.in.ia_subnetmask));
298 #else
299                                 printf("%-13.13s ",
300                                     netname(htonl(ifaddr.in.ia_subnet),
301                                     ifaddr.in.ia_subnetmask));
302 #endif
303                                 printf("%-15.15s ",
304                                     routename(sin->sin_addr.s_addr));
305
306                                 network_layer = 1;
307                                 break;
308 #ifdef INET6
309                         case AF_INET6:
310                                 sin6 = (struct sockaddr_in6 *)sa;
311                                 printf("%-11.11s ",
312                                        netname6(&ifaddr.in6.ia_addr,
313                                                 &ifaddr.in6.ia_prefixmask.sin6_addr));
314                                 printf("%-17.17s ",
315                                     (char *)inet_ntop(AF_INET6,
316                                         &sin6->sin6_addr,
317                                         ntop_buf, sizeof(ntop_buf)));
318
319                                 network_layer = 1;
320                                 break;
321 #endif /*INET6*/
322                         case AF_IPX:
323                                 {
324                                 struct sockaddr_ipx *sipx =
325                                         (struct sockaddr_ipx *)sa;
326                                 u_long net;
327                                 char netnum[10];
328
329                                 *(union ipx_net *) &net = sipx->sipx_addr.x_net;
330                                 sprintf(netnum, "%lx", (u_long)ntohl(net));
331                                 printf("ipx:%-8s  ", netnum);
332 /*                              printf("ipx:%-8s ", netname(net, 0L)); */
333                                 printf("%-15s ",
334                                     ipx_phost((struct sockaddr *)sipx));
335                                 }
336                                 break;
337
338                         case AF_APPLETALK:
339                                 printf("atalk:%-12.12s ",atalk_print(sa,0x10) );
340                                 printf("%-9.9s  ",atalk_print(sa,0x0b) );
341                                 break;
342 #ifdef NS
343                         case AF_NS:
344                                 {
345                                 struct sockaddr_ns *sns =
346                                         (struct sockaddr_ns *)sa;
347                                 u_long net;
348                                 char netnum[10];
349
350                                 *(union ns_net *) &net = sns->sns_addr.x_net;
351                                 sprintf(netnum, "%lxH", ntohl(net));
352                                 upHex(netnum);
353                                 printf("ns:%-8s ", netnum);
354                                 printf("%-15s ",
355                                     ns_phost((struct sockaddr *)sns));
356                                 }
357                                 break;
358 #endif
359                         case AF_LINK:
360                                 {
361                                 struct sockaddr_dl *sdl =
362                                         (struct sockaddr_dl *)sa;
363                                 char linknum[10];
364                                 cp = (char *)LLADDR(sdl);
365                                 n = sdl->sdl_alen;
366                                 sprintf(linknum, "<Link#%d>", sdl->sdl_index);
367                                 m = printf("%-11.11s ", linknum);
368                                 }
369                                 goto hexprint;
370                         default:
371                                 m = printf("(%d)", sa->sa_family);
372                                 for (cp = sa->sa_len + (char *)sa;
373                                         --cp > sa->sa_data && (*cp == 0);) {}
374                                 n = cp - sa->sa_data + 1;
375                                 cp = sa->sa_data;
376                         hexprint:
377                                 while (--n >= 0)
378                                         m += printf("%02x%c", *cp++ & 0xff,
379                                                     n > 0 ? ':' : ' ');
380                                 m = 30 - m;
381                                 while (m-- > 0)
382                                         putchar(' ');
383
384                                 link_layer = 1;
385                                 break;
386                         }
387
388                         /*
389                          * Fixup the statistics for interfaces that
390                          * update stats for their network addresses
391                          */
392                         if (network_layer) {
393                                 opackets = ifaddr.in.ia_ifa.if_opackets;
394                                 ipackets = ifaddr.in.ia_ifa.if_ipackets;
395                                 obytes = ifaddr.in.ia_ifa.if_obytes;
396                                 ibytes = ifaddr.in.ia_ifa.if_ibytes;
397                         }
398
399                         ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
400                 }
401
402                 show_stat("lu", 8, ipackets, link_layer|network_layer);
403                 printf(" ");
404                 show_stat("lu", 5, ierrors, link_layer);
405                 printf(" ");
406                 if (bflag) {
407                         show_stat("lu", 10, ibytes, link_layer|network_layer);
408                         printf(" ");
409                 }
410                 show_stat("lu", 8, opackets, link_layer|network_layer);
411                 printf(" ");
412                 show_stat("lu", 5, oerrors, link_layer);
413                 printf(" ");
414                 if (bflag) {
415                         show_stat("lu", 10, obytes, link_layer|network_layer);
416                         printf(" ");
417                 }
418                 show_stat("lu", 5, collisions, link_layer);
419                 if (tflag) {
420                         printf(" ");
421                         show_stat("d", 3, timer, link_layer);
422                 }
423                 if (dflag) {
424                         printf(" ");
425                         show_stat("d", 3, drops, link_layer);
426                 }
427                 putchar('\n');
428                 if (aflag && ifaddrfound) {
429                         /*
430                          * Print family's multicast addresses
431                          */
432                         struct ifmultiaddr *multiaddr;
433                         struct ifmultiaddr ifma;
434                         union {
435                                 struct sockaddr sa;
436                                 struct sockaddr_in in;
437 #ifdef INET6
438                                 struct sockaddr_in6 in6;
439 #endif /* INET6 */
440                                 struct sockaddr_dl dl;
441                         } msa;
442                         const char *fmt;
443
444                         TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
445                                 if (kread((u_long)multiaddr, (char *)&ifma,
446                                           sizeof ifma))
447                                         break;
448                                 multiaddr = &ifma;
449                                 if (kread((u_long)ifma.ifma_addr, (char *)&msa,
450                                           sizeof msa))
451                                         break;
452                                 if (msa.sa.sa_family != sa->sa_family)
453                                         continue;
454                                 
455                                 fmt = 0;
456                                 switch (msa.sa.sa_family) {
457                                 case AF_INET:
458                                         fmt = routename(msa.in.sin_addr.s_addr);
459                                         break;
460 #ifdef INET6
461                                 case AF_INET6:
462                                         printf("%23s %-19.19s(refs: %d)\n", "",
463                                                inet_ntop(AF_INET6,
464                                                          &msa.in6.sin6_addr,
465                                                          ntop_buf,
466                                                          sizeof(ntop_buf)),
467                                                ifma.ifma_refcount);
468                                         break;
469 #endif /* INET6 */
470                                 case AF_LINK:
471                                         switch (msa.dl.sdl_type) {
472                                         case IFT_ETHER:
473                                         case IFT_FDDI:
474                                                 fmt = ether_ntoa(
475                                                         (struct ether_addr *)
476                                                         LLADDR(&msa.dl));
477                                                 break;
478                                         }
479                                         break;
480                                 }
481                                 if (fmt)
482                                         printf("%23s %s\n", "", fmt);
483                         }
484                 }
485         }
486 }
487
488 struct  iftot {
489         SLIST_ENTRY(iftot) chain;
490         char    ift_name[16];           /* interface name */
491         u_long  ift_ip;                 /* input packets */
492         u_long  ift_ie;                 /* input errors */
493         u_long  ift_op;                 /* output packets */
494         u_long  ift_oe;                 /* output errors */
495         u_long  ift_co;                 /* collisions */
496         u_int   ift_dr;                 /* drops */
497         u_long  ift_ib;                 /* input bytes */
498         u_long  ift_ob;                 /* output bytes */
499 };
500
501 u_char  signalled;                      /* set if alarm goes off "early" */
502
503 /*
504  * Print a running summary of interface statistics.
505  * Repeat display every interval seconds, showing statistics
506  * collected over that interval.  Assumes that interval is non-zero.
507  * First line printed at top of screen is always cumulative.
508  * XXX - should be rewritten to use ifmib(4).
509  */
510 static void
511 sidewaysintpr(unsigned interval, u_long off)
512 {
513         struct ifnet ifnet;
514         u_long firstifnet;
515         struct ifnethead ifnethead;
516         struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
517         register int line;
518         int oldmask, first;
519         u_long interesting_off;
520
521         if (kread(off, (char *)&ifnethead, sizeof ifnethead))
522                 return;
523         firstifnet = (u_long)TAILQ_FIRST(&ifnethead);
524
525         if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
526                 printf("malloc failed\n");
527                 exit(1);
528         }
529         memset(iftot, 0, sizeof(struct iftot));
530
531         interesting = NULL;
532         interesting_off = 0;
533         for (off = firstifnet, ip = iftot; off;) {
534                 char name[16], tname[16];
535
536                 if (kread(off, (char *)&ifnet, sizeof ifnet))
537                         break;
538                 if (kread((u_long)ifnet.if_name, tname, 16))
539                         break;
540                 tname[15] = '\0';
541                 snprintf(name, 16, "%s%d", tname, ifnet.if_unit);
542                 if (interface && strcmp(name, interface) == 0) {
543                         interesting = ip;
544                         interesting_off = off;
545                 }
546                 snprintf(ip->ift_name, 16, "(%s)", name);;
547                 if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
548                         printf("malloc failed\n");
549                         exit(1);
550                 }
551                 memset(ipn, 0, sizeof(struct iftot));
552                 SLIST_NEXT(ip, chain) = ipn;
553                 ip = ipn;
554                 off = (u_long)TAILQ_NEXT(&ifnet, if_link);
555         }
556         if ((total = malloc(sizeof(struct iftot))) == NULL) {
557                 printf("malloc failed\n");
558                 exit(1);
559         }
560         memset(total, 0, sizeof(struct iftot));
561         if ((sum = malloc(sizeof(struct iftot))) == NULL) {
562                 printf("malloc failed\n");
563                 exit(1);
564         }
565         memset(sum, 0, sizeof(struct iftot));
566
567
568         (void)signal(SIGALRM, catchalarm);
569         signalled = NO;
570         (void)alarm(interval);
571         first = 1;
572 banner:
573         printf("%17s %14s %16s", "input",
574             interesting ? interesting->ift_name : "(Total)", "output");
575         putchar('\n');
576         printf("%10s %5s %10s %10s %5s %10s %5s",
577             "packets", "errs", "bytes", "packets", "errs", "bytes", "colls");
578         if (dflag)
579                 printf(" %5.5s", "drops");
580         putchar('\n');
581         fflush(stdout);
582         line = 0;
583 loop:
584         if (interesting != NULL) {
585                 ip = interesting;
586                 if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) {
587                         printf("???\n");
588                         exit(1);
589                 };
590                 if (!first) {
591                         printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
592                                 ifnet.if_ipackets - ip->ift_ip,
593                                 ifnet.if_ierrors - ip->ift_ie,
594                                 ifnet.if_ibytes - ip->ift_ib,
595                                 ifnet.if_opackets - ip->ift_op,
596                                 ifnet.if_oerrors - ip->ift_oe,
597                                 ifnet.if_obytes - ip->ift_ob,
598                                 ifnet.if_collisions - ip->ift_co);
599                         if (dflag)
600                                 printf(" %5u", ifnet.if_snd.ifq_drops - ip->ift_dr);
601                 }
602                 ip->ift_ip = ifnet.if_ipackets;
603                 ip->ift_ie = ifnet.if_ierrors;
604                 ip->ift_ib = ifnet.if_ibytes;
605                 ip->ift_op = ifnet.if_opackets;
606                 ip->ift_oe = ifnet.if_oerrors;
607                 ip->ift_ob = ifnet.if_obytes;
608                 ip->ift_co = ifnet.if_collisions;
609                 ip->ift_dr = ifnet.if_snd.ifq_drops;
610         } else {
611                 sum->ift_ip = 0;
612                 sum->ift_ie = 0;
613                 sum->ift_ib = 0;
614                 sum->ift_op = 0;
615                 sum->ift_oe = 0;
616                 sum->ift_ob = 0;
617                 sum->ift_co = 0;
618                 sum->ift_dr = 0;
619                 for (off = firstifnet, ip = iftot;
620                      off && SLIST_NEXT(ip, chain) != NULL;
621                      ip = SLIST_NEXT(ip, chain)) {
622                         if (kread(off, (char *)&ifnet, sizeof ifnet)) {
623                                 off = 0;
624                                 continue;
625                         }
626                         sum->ift_ip += ifnet.if_ipackets;
627                         sum->ift_ie += ifnet.if_ierrors;
628                         sum->ift_ib += ifnet.if_ibytes;
629                         sum->ift_op += ifnet.if_opackets;
630                         sum->ift_oe += ifnet.if_oerrors;
631                         sum->ift_ob += ifnet.if_obytes;
632                         sum->ift_co += ifnet.if_collisions;
633                         sum->ift_dr += ifnet.if_snd.ifq_drops;
634                         off = (u_long)TAILQ_NEXT(&ifnet, if_link);
635                 }
636                 if (!first) {
637                         printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
638                                 sum->ift_ip - total->ift_ip,
639                                 sum->ift_ie - total->ift_ie,
640                                 sum->ift_ib - total->ift_ib,
641                                 sum->ift_op - total->ift_op,
642                                 sum->ift_oe - total->ift_oe,
643                                 sum->ift_ob - total->ift_ob,
644                                 sum->ift_co - total->ift_co);
645                         if (dflag)
646                                 printf(" %5u", sum->ift_dr - total->ift_dr);
647                 }
648                 *total = *sum;
649         }
650         if (!first)
651                 putchar('\n');
652         fflush(stdout);
653         oldmask = sigblock(sigmask(SIGALRM));
654         if (! signalled) {
655                 sigpause(0);
656         }
657         sigsetmask(oldmask);
658         signalled = NO;
659         (void)alarm(interval);
660         line++;
661         first = 0;
662         if (line == 21)
663                 goto banner;
664         else
665                 goto loop;
666         /*NOTREACHED*/
667 }
668
669 /*
670  * Called if an interval expires before sidewaysintpr has completed a loop.
671  * Sets a flag to not wait for the alarm.
672  */
673 static void
674 catchalarm(int signo __unused)
675 {
676         signalled = YES;
677 }