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