Annotation of src/usr.bin/netstat/if.c, Revision 1.42
1.42 ! mpf 1: /* $OpenBSD: if.c,v 1.41 2005/03/04 20:22:16 jaredy 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.42 ! mpf 37: static char *rcsid = "$OpenBSD: if.c,v 1.41 2005/03/04 20:22:16 jaredy 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.42 ! mpf 322: sdl->sdl_type == IFT_CARP ||
1.23 fgsch 323: sdl->sdl_type == IFT_FDDI ||
324: sdl->sdl_type == IFT_ISO88025)
1.5 deraadt 325: printf("%-17.17s ",
1.11 millert 326: ether_ntoa((struct ether_addr *)LLADDR(sdl)));
1.5 deraadt 327: else {
328: cp = (char *)LLADDR(sdl);
329: n = sdl->sdl_alen;
330: goto hexprint;
331: }
1.1 deraadt 332: }
1.5 deraadt 333: break;
1.1 deraadt 334: default:
335: m = printf("(%d)", sa->sa_family);
336: for (cp = sa->sa_len + (char *)sa;
337: --cp > sa->sa_data && (*cp == 0);) {}
338: n = cp - sa->sa_data + 1;
339: cp = sa->sa_data;
340: hexprint:
341: while (--n >= 0)
342: m += printf("%x%c", *cp++ & 0xff,
343: n > 0 ? '.' : ' ');
344: m = 30 - m;
345: while (m-- > 0)
346: putchar(' ');
347: break;
348: }
349: ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
350: }
1.22 camield 351: if (bflag)
352: printf("%10lu %10lu",
353: ifnet.if_ibytes, ifnet.if_obytes);
354: else
355: printf("%8lu %5lu %8lu %5lu %5lu",
356: ifnet.if_ipackets, ifnet.if_ierrors,
357: ifnet.if_opackets, ifnet.if_oerrors,
358: ifnet.if_collisions);
1.1 deraadt 359: if (tflag)
1.22 camield 360: printf(" %4d", ifnet.if_timer);
1.1 deraadt 361: if (dflag)
1.22 camield 362: printf(" %4d", ifnet.if_snd.ifq_drops);
1.1 deraadt 363: putchar('\n');
364: }
365: }
366:
1.4 deraadt 367: #define MAXIF 100
1.1 deraadt 368: struct iftot {
1.3 deraadt 369: char ift_name[IFNAMSIZ]; /* interface name */
1.40 dhartmei 370: u_long ift_ip; /* input packets */
371: u_long ift_ib; /* input bytes */
372: u_long ift_ie; /* input errors */
373: u_long ift_op; /* output packets */
374: u_long ift_ob; /* output bytes */
375: u_long ift_oe; /* output errors */
376: u_long ift_co; /* collisions */
377: u_long ift_dr; /* drops */
1.1 deraadt 378: } iftot[MAXIF];
379:
1.26 millert 380: volatile sig_atomic_t signalled; /* set if alarm goes off "early" */
1.1 deraadt 381:
382: /*
383: * Print a running summary of interface statistics.
384: * Repeat display every interval seconds, showing statistics
385: * collected over that interval. Assumes that interval is non-zero.
386: * First line printed at top of screen is always cumulative.
387: */
388: static void
1.33 deraadt 389: sidewaysintpr(unsigned int interval, u_long off)
1.1 deraadt 390: {
391: struct ifnet ifnet;
392: u_long firstifnet;
1.27 mpech 393: struct iftot *ip, *total;
394: int line;
1.1 deraadt 395: struct iftot *lastif, *sum, *interesting;
1.3 deraadt 396: struct ifnet_head ifhead; /* TAILQ_HEAD */
1.26 millert 397: sigset_t emptyset;
1.1 deraadt 398:
1.3 deraadt 399: /*
400: * Find the pointer to the first ifnet structure. Replace
401: * the pointer to the TAILQ_HEAD with the actual pointer
402: * to the first list element.
403: */
404: if (kread(off, (char *)&ifhead, sizeof ifhead))
1.1 deraadt 405: return;
1.3 deraadt 406: firstifnet = (u_long)ifhead.tqh_first;
407:
1.1 deraadt 408: lastif = iftot;
409: sum = iftot + MAXIF - 1;
410: total = sum - 1;
1.4 deraadt 411: interesting = (interface == NULL) ? iftot : NULL;
1.1 deraadt 412: for (off = firstifnet, ip = iftot; off;) {
413: if (kread(off, (char *)&ifnet, sizeof ifnet))
414: break;
1.6 deraadt 415: bzero(ip->ift_name, sizeof(ip->ift_name));
1.22 camield 416: snprintf(ip->ift_name, IFNAMSIZ, "%s", ifnet.if_xname);
1.6 deraadt 417: if (interface && strcmp(ifnet.if_xname, interface) == 0)
1.1 deraadt 418: interesting = ip;
419: ip++;
420: if (ip >= iftot + MAXIF - 2)
421: break;
422: off = (u_long)ifnet.if_list.tqe_next;
1.4 deraadt 423: }
424: if (interesting == NULL) {
425: fprintf(stderr, "%s: %s: unknown interface\n",
426: __progname, interface);
427: exit(1);
1.1 deraadt 428: }
429: lastif = ip;
430:
431: (void)signal(SIGALRM, catchalarm);
432: signalled = NO;
433: (void)alarm(interval);
434: banner:
1.22 camield 435: if (bflag)
436: printf("%7.7s in %8.8s %6.6s out %5.5s",
437: interesting->ift_name, " ",
438: interesting->ift_name, " ");
439: else
440: printf("%5.5s in %5.5s%5.5s out %5.5s %5.5s",
441: interesting->ift_name, " ",
442: interesting->ift_name, " ", " ");
443: if (dflag)
444: printf(" %5.5s", " ");
1.1 deraadt 445: if (lastif - iftot > 0) {
1.22 camield 446: if (bflag)
447: printf(" %7.7s in %8.8s %6.6s out %5.5s",
448: "total", " ", "total", " ");
449: else
450: printf(" %5.5s in %5.5s%5.5s out %5.5s %5.5s",
451: "total", " ", "total", " ", " ");
1.1 deraadt 452: if (dflag)
1.22 camield 453: printf(" %5.5s", " ");
1.1 deraadt 454: }
455: for (ip = iftot; ip < iftot + MAXIF; ip++) {
456: ip->ift_ip = 0;
1.22 camield 457: ip->ift_ib = 0;
1.1 deraadt 458: ip->ift_ie = 0;
459: ip->ift_op = 0;
1.22 camield 460: ip->ift_ob = 0;
1.1 deraadt 461: ip->ift_oe = 0;
462: ip->ift_co = 0;
463: ip->ift_dr = 0;
464: }
465: putchar('\n');
1.22 camield 466: if (bflag)
467: printf("%10.10s %8.8s %10.10s %5.5s",
468: "bytes", " ", "bytes", " ");
469: else
470: printf("%8.8s %5.5s %8.8s %5.5s %5.5s",
471: "packets", "errs", "packets", "errs", "colls");
1.1 deraadt 472: if (dflag)
473: printf(" %5.5s", "drops");
1.22 camield 474: if (lastif - iftot > 0) {
475: if (bflag)
476: printf(" %10.10s %8.8s %10.10s %5.5s",
477: "bytes", " ", "bytes", " ");
478: else
479: printf(" %8.8s %5.5s %8.8s %5.5s %5.5s",
480: "packets", "errs", "packets", "errs", "colls");
481: if (dflag)
482: printf(" %5.5s", "drops");
483: }
1.1 deraadt 484: putchar('\n');
485: fflush(stdout);
486: line = 0;
487: loop:
488: sum->ift_ip = 0;
1.22 camield 489: sum->ift_ib = 0;
1.1 deraadt 490: sum->ift_ie = 0;
491: sum->ift_op = 0;
1.22 camield 492: sum->ift_ob = 0;
1.1 deraadt 493: sum->ift_oe = 0;
494: sum->ift_co = 0;
495: sum->ift_dr = 0;
496: for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
497: if (kread(off, (char *)&ifnet, sizeof ifnet)) {
498: off = 0;
499: continue;
500: }
501: if (ip == interesting) {
1.22 camield 502: if (bflag)
503: printf("%10lu %8.8s %10lu %5.5s",
504: ifnet.if_ibytes - ip->ift_ib, " ",
505: ifnet.if_obytes - ip->ift_ob, " ");
506: else
507: printf("%8lu %5lu %8lu %5lu %5lu",
508: ifnet.if_ipackets - ip->ift_ip,
509: ifnet.if_ierrors - ip->ift_ie,
510: ifnet.if_opackets - ip->ift_op,
511: ifnet.if_oerrors - ip->ift_oe,
512: ifnet.if_collisions - ip->ift_co);
1.1 deraadt 513: if (dflag)
1.41 jaredy 514: printf(" %5lu",
1.1 deraadt 515: ifnet.if_snd.ifq_drops - ip->ift_dr);
516: }
517: ip->ift_ip = ifnet.if_ipackets;
1.22 camield 518: ip->ift_ib = ifnet.if_ibytes;
1.1 deraadt 519: ip->ift_ie = ifnet.if_ierrors;
520: ip->ift_op = ifnet.if_opackets;
1.22 camield 521: ip->ift_ob = ifnet.if_obytes;
1.1 deraadt 522: ip->ift_oe = ifnet.if_oerrors;
523: ip->ift_co = ifnet.if_collisions;
524: ip->ift_dr = ifnet.if_snd.ifq_drops;
525: sum->ift_ip += ip->ift_ip;
1.22 camield 526: sum->ift_ib += ip->ift_ib;
1.1 deraadt 527: sum->ift_ie += ip->ift_ie;
528: sum->ift_op += ip->ift_op;
1.22 camield 529: sum->ift_ob += ip->ift_ob;
1.1 deraadt 530: sum->ift_oe += ip->ift_oe;
531: sum->ift_co += ip->ift_co;
532: sum->ift_dr += ip->ift_dr;
533: off = (u_long)ifnet.if_list.tqe_next;
534: }
535: if (lastif - iftot > 0) {
1.22 camield 536: if (bflag)
537: printf(" %10lu %8.8s %10lu %5.5s",
1.41 jaredy 538: sum->ift_ib - total->ift_ib, " ",
539: sum->ift_ob - total->ift_ob, " ");
1.22 camield 540: else
541: printf(" %8lu %5lu %8lu %5lu %5lu",
1.41 jaredy 542: sum->ift_ip - total->ift_ip,
543: sum->ift_ie - total->ift_ie,
544: sum->ift_op - total->ift_op,
545: sum->ift_oe - total->ift_oe,
546: sum->ift_co - total->ift_co);
1.1 deraadt 547: if (dflag)
1.41 jaredy 548: printf(" %5lu", sum->ift_dr - total->ift_dr);
1.1 deraadt 549: }
550: *total = *sum;
551: putchar('\n');
552: fflush(stdout);
553: line++;
1.26 millert 554: sigemptyset(&emptyset);
555: if (!signalled)
556: sigsuspend(&emptyset);
1.1 deraadt 557: signalled = NO;
558: (void)alarm(interval);
559: if (line == 21)
560: goto banner;
561: goto loop;
562: /*NOTREACHED*/
563: }
564:
565: /*
566: * Called if an interval expires before sidewaysintpr has completed a loop.
567: * Sets a flag to not wait for the alarm.
568: */
569: static void
1.33 deraadt 570: catchalarm(int signo)
1.1 deraadt 571: {
572: signalled = YES;
573: }