xref: /freebsd/usr.bin/netstat/if.c (revision 9b50d9027575220cb6dd09b3e62f03f511e908b8)
19b50d902SRodney W. Grimes /*
29b50d902SRodney W. Grimes  * Copyright (c) 1983, 1988, 1993
39b50d902SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
49b50d902SRodney W. Grimes  *
59b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
69b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
79b50d902SRodney W. Grimes  * are met:
89b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
99b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
109b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
119b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
129b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
139b50d902SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
149b50d902SRodney W. Grimes  *    must display the following acknowledgement:
159b50d902SRodney W. Grimes  *	This product includes software developed by the University of
169b50d902SRodney W. Grimes  *	California, Berkeley and its contributors.
179b50d902SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
189b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
199b50d902SRodney W. Grimes  *    without specific prior written permission.
209b50d902SRodney W. Grimes  *
219b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
229b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
239b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
249b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
259b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
269b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
279b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
289b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
299b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
309b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
319b50d902SRodney W. Grimes  * SUCH DAMAGE.
329b50d902SRodney W. Grimes  */
339b50d902SRodney W. Grimes 
349b50d902SRodney W. Grimes #ifndef lint
359b50d902SRodney W. Grimes static char sccsid[] = "@(#)if.c	8.2 (Berkeley) 2/21/94";
369b50d902SRodney W. Grimes #endif /* not lint */
379b50d902SRodney W. Grimes 
389b50d902SRodney W. Grimes #include <sys/types.h>
399b50d902SRodney W. Grimes #include <sys/protosw.h>
409b50d902SRodney W. Grimes #include <sys/socket.h>
419b50d902SRodney W. Grimes 
429b50d902SRodney W. Grimes #include <net/if.h>
439b50d902SRodney W. Grimes #include <net/if_dl.h>
449b50d902SRodney W. Grimes #include <netinet/in.h>
459b50d902SRodney W. Grimes #include <netinet/in_var.h>
469b50d902SRodney W. Grimes #include <netns/ns.h>
479b50d902SRodney W. Grimes #include <netns/ns_if.h>
489b50d902SRodney W. Grimes #include <netiso/iso.h>
499b50d902SRodney W. Grimes #include <netiso/iso_var.h>
509b50d902SRodney W. Grimes #include <arpa/inet.h>
519b50d902SRodney W. Grimes 
529b50d902SRodney W. Grimes #include <signal.h>
539b50d902SRodney W. Grimes #include <stdio.h>
549b50d902SRodney W. Grimes #include <string.h>
559b50d902SRodney W. Grimes #include <unistd.h>
569b50d902SRodney W. Grimes 
579b50d902SRodney W. Grimes #include "netstat.h"
589b50d902SRodney W. Grimes 
599b50d902SRodney W. Grimes #define	YES	1
609b50d902SRodney W. Grimes #define	NO	0
619b50d902SRodney W. Grimes 
629b50d902SRodney W. Grimes static void sidewaysintpr __P((u_int, u_long));
639b50d902SRodney W. Grimes static void catchalarm __P((int));
649b50d902SRodney W. Grimes 
659b50d902SRodney W. Grimes /*
669b50d902SRodney W. Grimes  * Print a description of the network interfaces.
679b50d902SRodney W. Grimes  */
689b50d902SRodney W. Grimes void
699b50d902SRodney W. Grimes intpr(interval, ifnetaddr)
709b50d902SRodney W. Grimes 	int interval;
719b50d902SRodney W. Grimes 	u_long ifnetaddr;
729b50d902SRodney W. Grimes {
739b50d902SRodney W. Grimes 	struct ifnet ifnet;
749b50d902SRodney W. Grimes 	union {
759b50d902SRodney W. Grimes 		struct ifaddr ifa;
769b50d902SRodney W. Grimes 		struct in_ifaddr in;
779b50d902SRodney W. Grimes 		struct ns_ifaddr ns;
789b50d902SRodney W. Grimes 		struct iso_ifaddr iso;
799b50d902SRodney W. Grimes 	} ifaddr;
809b50d902SRodney W. Grimes 	u_long ifaddraddr;
819b50d902SRodney W. Grimes 	struct sockaddr *sa;
829b50d902SRodney W. Grimes 	char name[16];
839b50d902SRodney W. Grimes 
849b50d902SRodney W. Grimes 	if (ifnetaddr == 0) {
859b50d902SRodney W. Grimes 		printf("ifnet: symbol not defined\n");
869b50d902SRodney W. Grimes 		return;
879b50d902SRodney W. Grimes 	}
889b50d902SRodney W. Grimes 	if (interval) {
899b50d902SRodney W. Grimes 		sidewaysintpr((unsigned)interval, ifnetaddr);
909b50d902SRodney W. Grimes 		return;
919b50d902SRodney W. Grimes 	}
929b50d902SRodney W. Grimes 	if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
939b50d902SRodney W. Grimes 		return;
949b50d902SRodney W. Grimes 	printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
959b50d902SRodney W. Grimes 		"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
969b50d902SRodney W. Grimes 		"Opkts", "Oerrs");
979b50d902SRodney W. Grimes 	printf(" %5s", "Coll");
989b50d902SRodney W. Grimes 	if (tflag)
999b50d902SRodney W. Grimes 		printf(" %s", "Time");
1009b50d902SRodney W. Grimes 	if (dflag)
1019b50d902SRodney W. Grimes 		printf(" %s", "Drop");
1029b50d902SRodney W. Grimes 	putchar('\n');
1039b50d902SRodney W. Grimes 	ifaddraddr = 0;
1049b50d902SRodney W. Grimes 	while (ifnetaddr || ifaddraddr) {
1059b50d902SRodney W. Grimes 		struct sockaddr_in *sin;
1069b50d902SRodney W. Grimes 		register char *cp;
1079b50d902SRodney W. Grimes 		int n, m;
1089b50d902SRodney W. Grimes 
1099b50d902SRodney W. Grimes 		if (ifaddraddr == 0) {
1109b50d902SRodney W. Grimes 			if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
1119b50d902SRodney W. Grimes 			    kread((u_long)ifnet.if_name, name, 16))
1129b50d902SRodney W. Grimes 				return;
1139b50d902SRodney W. Grimes 			name[15] = '\0';
1149b50d902SRodney W. Grimes 			ifnetaddr = (u_long)ifnet.if_next;
1159b50d902SRodney W. Grimes 			if (interface != 0 && (strcmp(name, interface) != 0 ||
1169b50d902SRodney W. Grimes 			    unit != ifnet.if_unit))
1179b50d902SRodney W. Grimes 				continue;
1189b50d902SRodney W. Grimes 			cp = index(name, '\0');
1199b50d902SRodney W. Grimes 			cp += sprintf(cp, "%d", ifnet.if_unit);
1209b50d902SRodney W. Grimes 			if ((ifnet.if_flags&IFF_UP) == 0)
1219b50d902SRodney W. Grimes 				*cp++ = '*';
1229b50d902SRodney W. Grimes 			*cp = '\0';
1239b50d902SRodney W. Grimes 			ifaddraddr = (u_long)ifnet.if_addrlist;
1249b50d902SRodney W. Grimes 		}
1259b50d902SRodney W. Grimes 		printf("%-5.5s %-5d ", name, ifnet.if_mtu);
1269b50d902SRodney W. Grimes 		if (ifaddraddr == 0) {
1279b50d902SRodney W. Grimes 			printf("%-11.11s ", "none");
1289b50d902SRodney W. Grimes 			printf("%-15.15s ", "none");
1299b50d902SRodney W. Grimes 		} else {
1309b50d902SRodney W. Grimes 			if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
1319b50d902SRodney W. Grimes 				ifaddraddr = 0;
1329b50d902SRodney W. Grimes 				continue;
1339b50d902SRodney W. Grimes 			}
1349b50d902SRodney W. Grimes #define CP(x) ((char *)(x))
1359b50d902SRodney W. Grimes 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
1369b50d902SRodney W. Grimes 				CP(&ifaddr); sa = (struct sockaddr *)cp;
1379b50d902SRodney W. Grimes 			switch (sa->sa_family) {
1389b50d902SRodney W. Grimes 			case AF_UNSPEC:
1399b50d902SRodney W. Grimes 				printf("%-11.11s ", "none");
1409b50d902SRodney W. Grimes 				printf("%-15.15s ", "none");
1419b50d902SRodney W. Grimes 				break;
1429b50d902SRodney W. Grimes 			case AF_INET:
1439b50d902SRodney W. Grimes 				sin = (struct sockaddr_in *)sa;
1449b50d902SRodney W. Grimes #ifdef notdef
1459b50d902SRodney W. Grimes 				/* can't use inet_makeaddr because kernel
1469b50d902SRodney W. Grimes 				 * keeps nets unshifted.
1479b50d902SRodney W. Grimes 				 */
1489b50d902SRodney W. Grimes 				in = inet_makeaddr(ifaddr.in.ia_subnet,
1499b50d902SRodney W. Grimes 					INADDR_ANY);
1509b50d902SRodney W. Grimes 				printf("%-11.11s ", netname(in.s_addr,
1519b50d902SRodney W. Grimes 				    ifaddr.in.ia_subnetmask));
1529b50d902SRodney W. Grimes #else
1539b50d902SRodney W. Grimes 				printf("%-11.11s ",
1549b50d902SRodney W. Grimes 				    netname(htonl(ifaddr.in.ia_subnet),
1559b50d902SRodney W. Grimes 				    ifaddr.in.ia_subnetmask));
1569b50d902SRodney W. Grimes #endif
1579b50d902SRodney W. Grimes 				printf("%-15.15s ",
1589b50d902SRodney W. Grimes 				    routename(sin->sin_addr.s_addr));
1599b50d902SRodney W. Grimes 				break;
1609b50d902SRodney W. Grimes 			case AF_NS:
1619b50d902SRodney W. Grimes 				{
1629b50d902SRodney W. Grimes 				struct sockaddr_ns *sns =
1639b50d902SRodney W. Grimes 					(struct sockaddr_ns *)sa;
1649b50d902SRodney W. Grimes 				u_long net;
1659b50d902SRodney W. Grimes 				char netnum[8];
1669b50d902SRodney W. Grimes 
1679b50d902SRodney W. Grimes 				*(union ns_net *) &net = sns->sns_addr.x_net;
1689b50d902SRodney W. Grimes 		sprintf(netnum, "%lxH", ntohl(net));
1699b50d902SRodney W. Grimes 				upHex(netnum);
1709b50d902SRodney W. Grimes 				printf("ns:%-8s ", netnum);
1719b50d902SRodney W. Grimes 				printf("%-15s ",
1729b50d902SRodney W. Grimes 				    ns_phost((struct sockaddr *)sns));
1739b50d902SRodney W. Grimes 				}
1749b50d902SRodney W. Grimes 				break;
1759b50d902SRodney W. Grimes 			case AF_LINK:
1769b50d902SRodney W. Grimes 				{
1779b50d902SRodney W. Grimes 				struct sockaddr_dl *sdl =
1789b50d902SRodney W. Grimes 					(struct sockaddr_dl *)sa;
1799b50d902SRodney W. Grimes 				    cp = (char *)LLADDR(sdl);
1809b50d902SRodney W. Grimes 				    n = sdl->sdl_alen;
1819b50d902SRodney W. Grimes 				}
1829b50d902SRodney W. Grimes 				m = printf("<Link>");
1839b50d902SRodney W. Grimes 				goto hexprint;
1849b50d902SRodney W. Grimes 			default:
1859b50d902SRodney W. Grimes 				m = printf("(%d)", sa->sa_family);
1869b50d902SRodney W. Grimes 				for (cp = sa->sa_len + (char *)sa;
1879b50d902SRodney W. Grimes 					--cp > sa->sa_data && (*cp == 0);) {}
1889b50d902SRodney W. Grimes 				n = cp - sa->sa_data + 1;
1899b50d902SRodney W. Grimes 				cp = sa->sa_data;
1909b50d902SRodney W. Grimes 			hexprint:
1919b50d902SRodney W. Grimes 				while (--n >= 0)
1929b50d902SRodney W. Grimes 					m += printf("%x%c", *cp++ & 0xff,
1939b50d902SRodney W. Grimes 						    n > 0 ? '.' : ' ');
1949b50d902SRodney W. Grimes 				m = 28 - m;
1959b50d902SRodney W. Grimes 				while (m-- > 0)
1969b50d902SRodney W. Grimes 					putchar(' ');
1979b50d902SRodney W. Grimes 				break;
1989b50d902SRodney W. Grimes 			}
1999b50d902SRodney W. Grimes 			ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
2009b50d902SRodney W. Grimes 		}
2019b50d902SRodney W. Grimes 		printf("%8d %5d %8d %5d %5d",
2029b50d902SRodney W. Grimes 		    ifnet.if_ipackets, ifnet.if_ierrors,
2039b50d902SRodney W. Grimes 		    ifnet.if_opackets, ifnet.if_oerrors,
2049b50d902SRodney W. Grimes 		    ifnet.if_collisions);
2059b50d902SRodney W. Grimes 		if (tflag)
2069b50d902SRodney W. Grimes 			printf(" %3d", ifnet.if_timer);
2079b50d902SRodney W. Grimes 		if (dflag)
2089b50d902SRodney W. Grimes 			printf(" %3d", ifnet.if_snd.ifq_drops);
2099b50d902SRodney W. Grimes 		putchar('\n');
2109b50d902SRodney W. Grimes 	}
2119b50d902SRodney W. Grimes }
2129b50d902SRodney W. Grimes 
2139b50d902SRodney W. Grimes #define	MAXIF	10
2149b50d902SRodney W. Grimes struct	iftot {
2159b50d902SRodney W. Grimes 	char	ift_name[16];		/* interface name */
2169b50d902SRodney W. Grimes 	int	ift_ip;			/* input packets */
2179b50d902SRodney W. Grimes 	int	ift_ie;			/* input errors */
2189b50d902SRodney W. Grimes 	int	ift_op;			/* output packets */
2199b50d902SRodney W. Grimes 	int	ift_oe;			/* output errors */
2209b50d902SRodney W. Grimes 	int	ift_co;			/* collisions */
2219b50d902SRodney W. Grimes 	int	ift_dr;			/* drops */
2229b50d902SRodney W. Grimes } iftot[MAXIF];
2239b50d902SRodney W. Grimes 
2249b50d902SRodney W. Grimes u_char	signalled;			/* set if alarm goes off "early" */
2259b50d902SRodney W. Grimes 
2269b50d902SRodney W. Grimes /*
2279b50d902SRodney W. Grimes  * Print a running summary of interface statistics.
2289b50d902SRodney W. Grimes  * Repeat display every interval seconds, showing statistics
2299b50d902SRodney W. Grimes  * collected over that interval.  Assumes that interval is non-zero.
2309b50d902SRodney W. Grimes  * First line printed at top of screen is always cumulative.
2319b50d902SRodney W. Grimes  */
2329b50d902SRodney W. Grimes static void
2339b50d902SRodney W. Grimes sidewaysintpr(interval, off)
2349b50d902SRodney W. Grimes 	unsigned interval;
2359b50d902SRodney W. Grimes 	u_long off;
2369b50d902SRodney W. Grimes {
2379b50d902SRodney W. Grimes 	struct ifnet ifnet;
2389b50d902SRodney W. Grimes 	u_long firstifnet;
2399b50d902SRodney W. Grimes 	register struct iftot *ip, *total;
2409b50d902SRodney W. Grimes 	register int line;
2419b50d902SRodney W. Grimes 	struct iftot *lastif, *sum, *interesting;
2429b50d902SRodney W. Grimes 	int oldmask;
2439b50d902SRodney W. Grimes 
2449b50d902SRodney W. Grimes 	if (kread(off, (char *)&firstifnet, sizeof (u_long)))
2459b50d902SRodney W. Grimes 		return;
2469b50d902SRodney W. Grimes 	lastif = iftot;
2479b50d902SRodney W. Grimes 	sum = iftot + MAXIF - 1;
2489b50d902SRodney W. Grimes 	total = sum - 1;
2499b50d902SRodney W. Grimes 	interesting = iftot;
2509b50d902SRodney W. Grimes 	for (off = firstifnet, ip = iftot; off;) {
2519b50d902SRodney W. Grimes 		char *cp;
2529b50d902SRodney W. Grimes 
2539b50d902SRodney W. Grimes 		if (kread(off, (char *)&ifnet, sizeof ifnet))
2549b50d902SRodney W. Grimes 			break;
2559b50d902SRodney W. Grimes 		ip->ift_name[0] = '(';
2569b50d902SRodney W. Grimes 		if (kread((u_long)ifnet.if_name, ip->ift_name + 1, 15))
2579b50d902SRodney W. Grimes 			break;
2589b50d902SRodney W. Grimes 		if (interface && strcmp(ip->ift_name + 1, interface) == 0 &&
2599b50d902SRodney W. Grimes 		    unit == ifnet.if_unit)
2609b50d902SRodney W. Grimes 			interesting = ip;
2619b50d902SRodney W. Grimes 		ip->ift_name[15] = '\0';
2629b50d902SRodney W. Grimes 		cp = index(ip->ift_name, '\0');
2639b50d902SRodney W. Grimes 		sprintf(cp, "%d)", ifnet.if_unit);
2649b50d902SRodney W. Grimes 		ip++;
2659b50d902SRodney W. Grimes 		if (ip >= iftot + MAXIF - 2)
2669b50d902SRodney W. Grimes 			break;
2679b50d902SRodney W. Grimes 		off = (u_long) ifnet.if_next;
2689b50d902SRodney W. Grimes 	}
2699b50d902SRodney W. Grimes 	lastif = ip;
2709b50d902SRodney W. Grimes 
2719b50d902SRodney W. Grimes 	(void)signal(SIGALRM, catchalarm);
2729b50d902SRodney W. Grimes 	signalled = NO;
2739b50d902SRodney W. Grimes 	(void)alarm(interval);
2749b50d902SRodney W. Grimes banner:
2759b50d902SRodney W. Grimes 	printf("   input    %-6.6s    output       ", interesting->ift_name);
2769b50d902SRodney W. Grimes 	if (lastif - iftot > 0) {
2779b50d902SRodney W. Grimes 		if (dflag)
2789b50d902SRodney W. Grimes 			printf("      ");
2799b50d902SRodney W. Grimes 		printf("     input   (Total)    output");
2809b50d902SRodney W. Grimes 	}
2819b50d902SRodney W. Grimes 	for (ip = iftot; ip < iftot + MAXIF; ip++) {
2829b50d902SRodney W. Grimes 		ip->ift_ip = 0;
2839b50d902SRodney W. Grimes 		ip->ift_ie = 0;
2849b50d902SRodney W. Grimes 		ip->ift_op = 0;
2859b50d902SRodney W. Grimes 		ip->ift_oe = 0;
2869b50d902SRodney W. Grimes 		ip->ift_co = 0;
2879b50d902SRodney W. Grimes 		ip->ift_dr = 0;
2889b50d902SRodney W. Grimes 	}
2899b50d902SRodney W. Grimes 	putchar('\n');
2909b50d902SRodney W. Grimes 	printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
2919b50d902SRodney W. Grimes 		"packets", "errs", "packets", "errs", "colls");
2929b50d902SRodney W. Grimes 	if (dflag)
2939b50d902SRodney W. Grimes 		printf("%5.5s ", "drops");
2949b50d902SRodney W. Grimes 	if (lastif - iftot > 0)
2959b50d902SRodney W. Grimes 		printf(" %8.8s %5.5s %8.8s %5.5s %5.5s",
2969b50d902SRodney W. Grimes 			"packets", "errs", "packets", "errs", "colls");
2979b50d902SRodney W. Grimes 	if (dflag)
2989b50d902SRodney W. Grimes 		printf(" %5.5s", "drops");
2999b50d902SRodney W. Grimes 	putchar('\n');
3009b50d902SRodney W. Grimes 	fflush(stdout);
3019b50d902SRodney W. Grimes 	line = 0;
3029b50d902SRodney W. Grimes loop:
3039b50d902SRodney W. Grimes 	sum->ift_ip = 0;
3049b50d902SRodney W. Grimes 	sum->ift_ie = 0;
3059b50d902SRodney W. Grimes 	sum->ift_op = 0;
3069b50d902SRodney W. Grimes 	sum->ift_oe = 0;
3079b50d902SRodney W. Grimes 	sum->ift_co = 0;
3089b50d902SRodney W. Grimes 	sum->ift_dr = 0;
3099b50d902SRodney W. Grimes 	for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
3109b50d902SRodney W. Grimes 		if (kread(off, (char *)&ifnet, sizeof ifnet)) {
3119b50d902SRodney W. Grimes 			off = 0;
3129b50d902SRodney W. Grimes 			continue;
3139b50d902SRodney W. Grimes 		}
3149b50d902SRodney W. Grimes 		if (ip == interesting) {
3159b50d902SRodney W. Grimes 			printf("%8d %5d %8d %5d %5d",
3169b50d902SRodney W. Grimes 				ifnet.if_ipackets - ip->ift_ip,
3179b50d902SRodney W. Grimes 				ifnet.if_ierrors - ip->ift_ie,
3189b50d902SRodney W. Grimes 				ifnet.if_opackets - ip->ift_op,
3199b50d902SRodney W. Grimes 				ifnet.if_oerrors - ip->ift_oe,
3209b50d902SRodney W. Grimes 				ifnet.if_collisions - ip->ift_co);
3219b50d902SRodney W. Grimes 			if (dflag)
3229b50d902SRodney W. Grimes 				printf(" %5d",
3239b50d902SRodney W. Grimes 				    ifnet.if_snd.ifq_drops - ip->ift_dr);
3249b50d902SRodney W. Grimes 		}
3259b50d902SRodney W. Grimes 		ip->ift_ip = ifnet.if_ipackets;
3269b50d902SRodney W. Grimes 		ip->ift_ie = ifnet.if_ierrors;
3279b50d902SRodney W. Grimes 		ip->ift_op = ifnet.if_opackets;
3289b50d902SRodney W. Grimes 		ip->ift_oe = ifnet.if_oerrors;
3299b50d902SRodney W. Grimes 		ip->ift_co = ifnet.if_collisions;
3309b50d902SRodney W. Grimes 		ip->ift_dr = ifnet.if_snd.ifq_drops;
3319b50d902SRodney W. Grimes 		sum->ift_ip += ip->ift_ip;
3329b50d902SRodney W. Grimes 		sum->ift_ie += ip->ift_ie;
3339b50d902SRodney W. Grimes 		sum->ift_op += ip->ift_op;
3349b50d902SRodney W. Grimes 		sum->ift_oe += ip->ift_oe;
3359b50d902SRodney W. Grimes 		sum->ift_co += ip->ift_co;
3369b50d902SRodney W. Grimes 		sum->ift_dr += ip->ift_dr;
3379b50d902SRodney W. Grimes 		off = (u_long) ifnet.if_next;
3389b50d902SRodney W. Grimes 	}
3399b50d902SRodney W. Grimes 	if (lastif - iftot > 0) {
3409b50d902SRodney W. Grimes 		printf("  %8d %5d %8d %5d %5d",
3419b50d902SRodney W. Grimes 			sum->ift_ip - total->ift_ip,
3429b50d902SRodney W. Grimes 			sum->ift_ie - total->ift_ie,
3439b50d902SRodney W. Grimes 			sum->ift_op - total->ift_op,
3449b50d902SRodney W. Grimes 			sum->ift_oe - total->ift_oe,
3459b50d902SRodney W. Grimes 			sum->ift_co - total->ift_co);
3469b50d902SRodney W. Grimes 		if (dflag)
3479b50d902SRodney W. Grimes 			printf(" %5d", sum->ift_dr - total->ift_dr);
3489b50d902SRodney W. Grimes 	}
3499b50d902SRodney W. Grimes 	*total = *sum;
3509b50d902SRodney W. Grimes 	putchar('\n');
3519b50d902SRodney W. Grimes 	fflush(stdout);
3529b50d902SRodney W. Grimes 	line++;
3539b50d902SRodney W. Grimes 	oldmask = sigblock(sigmask(SIGALRM));
3549b50d902SRodney W. Grimes 	if (! signalled) {
3559b50d902SRodney W. Grimes 		sigpause(0);
3569b50d902SRodney W. Grimes 	}
3579b50d902SRodney W. Grimes 	sigsetmask(oldmask);
3589b50d902SRodney W. Grimes 	signalled = NO;
3599b50d902SRodney W. Grimes 	(void)alarm(interval);
3609b50d902SRodney W. Grimes 	if (line == 21)
3619b50d902SRodney W. Grimes 		goto banner;
3629b50d902SRodney W. Grimes 	goto loop;
3639b50d902SRodney W. Grimes 	/*NOTREACHED*/
3649b50d902SRodney W. Grimes }
3659b50d902SRodney W. Grimes 
3669b50d902SRodney W. Grimes /*
3679b50d902SRodney W. Grimes  * Called if an interval expires before sidewaysintpr has completed a loop.
3689b50d902SRodney W. Grimes  * Sets a flag to not wait for the alarm.
3699b50d902SRodney W. Grimes  */
3709b50d902SRodney W. Grimes static void
3719b50d902SRodney W. Grimes catchalarm(signo)
3729b50d902SRodney W. Grimes 	int signo;
3739b50d902SRodney W. Grimes {
3749b50d902SRodney W. Grimes 	signalled = YES;
3759b50d902SRodney W. Grimes }
376