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