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