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