xref: /freebsd/usr.bin/netstat/if.c (revision feda1a4372d5e340da97042375dfb783dea52eda)
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 
346cc6f122SPhilippe Charnier #if 0
359b50d902SRodney W. Grimes #ifndef lint
3605ddff6eSPeter Wemm static char sccsid[] = "@(#)if.c	8.3 (Berkeley) 4/28/95";
379b50d902SRodney W. Grimes #endif /* not lint */
386cc6f122SPhilippe Charnier #endif
396cc6f122SPhilippe Charnier 
406cc6f122SPhilippe Charnier #include <sys/cdefs.h>
416cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$");
429b50d902SRodney W. Grimes 
439b50d902SRodney W. Grimes #include <sys/types.h>
449b50d902SRodney W. Grimes #include <sys/protosw.h>
459b50d902SRodney W. Grimes #include <sys/socket.h>
46feda1a43SJohn Baldwin #include <sys/socketvar.h>
470024d1dbSLuigi Rizzo #include <sys/sysctl.h>
48628d2ac1SGarrett Wollman #include <sys/time.h>
499b50d902SRodney W. Grimes 
509b50d902SRodney W. Grimes #include <net/if.h>
5187669425SGarrett Wollman #include <net/if_var.h>
529b50d902SRodney W. Grimes #include <net/if_dl.h>
53f6719675SBill Fenner #include <net/if_types.h>
5475fb8770SGarrett Wollman #include <net/ethernet.h>
552e37c5a3SMax Laier #include <net/pfvar.h>
562e37c5a3SMax Laier #include <net/if_pfsync.h>
579b50d902SRodney W. Grimes #include <netinet/in.h>
589b50d902SRodney W. Grimes #include <netinet/in_var.h>
59cc6a66f2SJulian Elischer #include <netipx/ipx.h>
60cc6a66f2SJulian Elischer #include <netipx/ipx_if.h>
619b50d902SRodney W. Grimes #include <arpa/inet.h>
629b50d902SRodney W. Grimes 
632e37c5a3SMax Laier #include <err.h>
642e37c5a3SMax Laier #include <errno.h>
65c2dfd19fSGleb Smirnoff #include <libutil.h>
669b50d902SRodney W. Grimes #include <signal.h>
677b95a1ebSYaroslav Tykhiy #include <stdint.h>
689b50d902SRodney W. Grimes #include <stdio.h>
69591c194aSGuido van Rooij #include <stdlib.h>
709b50d902SRodney W. Grimes #include <string.h>
719b50d902SRodney W. Grimes #include <unistd.h>
729b50d902SRodney W. Grimes 
739b50d902SRodney W. Grimes #include "netstat.h"
749b50d902SRodney W. Grimes 
759b50d902SRodney W. Grimes #define	YES	1
769b50d902SRodney W. Grimes #define	NO	0
779b50d902SRodney W. Grimes 
78b6c86f4bSBruce Evans static void sidewaysintpr(int, u_long);
795e051718SAssar Westerlund static void catchalarm(int);
809b50d902SRodney W. Grimes 
81cfa1ca9dSYoshinobu Inoue #ifdef INET6
82cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN];		/* for inet_ntop() */
83cfa1ca9dSYoshinobu Inoue #endif
84cfa1ca9dSYoshinobu Inoue 
852e37c5a3SMax Laier /*
862e37c5a3SMax Laier  * Dump pfsync statistics structure.
872e37c5a3SMax Laier  */
882e37c5a3SMax Laier void
89feda1a43SJohn Baldwin pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
902e37c5a3SMax Laier {
912e37c5a3SMax Laier 	struct pfsyncstats pfsyncstat, zerostat;
922e37c5a3SMax Laier 	size_t len = sizeof(struct pfsyncstats);
93445f17bbSJosef Karthauser 
94feda1a43SJohn Baldwin 	if (live) {
952e37c5a3SMax Laier 		if (zflag)
962e37c5a3SMax Laier 			memset(&zerostat, 0, len);
972e37c5a3SMax Laier 		if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len,
982e37c5a3SMax Laier 		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
992e37c5a3SMax Laier 			if (errno != ENOENT)
1002e37c5a3SMax Laier 				warn("sysctl: net.inet.pfsync.stats");
1012e37c5a3SMax Laier 			return;
1022e37c5a3SMax Laier 		}
103feda1a43SJohn Baldwin 	} else
104feda1a43SJohn Baldwin 		kread(off, &pfsyncstat, len);
105445f17bbSJosef Karthauser 
1062e37c5a3SMax Laier 	printf("%s:\n", name);
1072e37c5a3SMax Laier 
1082e37c5a3SMax Laier #define p(f, m) if (pfsyncstat.f || sflag <= 1) \
1097b95a1ebSYaroslav Tykhiy 	printf(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f))
1102e37c5a3SMax Laier #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \
1117b95a1ebSYaroslav Tykhiy 	printf(m, (uintmax_t)pfsyncstat.f)
1122e37c5a3SMax Laier 
1137b95a1ebSYaroslav Tykhiy 	p(pfsyncs_ipackets, "\t%ju packet%s received (IPv4)\n");
1147b95a1ebSYaroslav Tykhiy 	p(pfsyncs_ipackets6, "\t%ju packet%s received (IPv6)\n");
1157b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badif, "\t\t%ju packet%s discarded for bad interface\n");
1167b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badttl, "\t\t%ju packet%s discarded for bad ttl\n");
1177b95a1ebSYaroslav Tykhiy 	p(pfsyncs_hdrops, "\t\t%ju packet%s shorter than header\n");
1187b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badver, "\t\t%ju packet%s discarded for bad version\n");
1197b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badauth, "\t\t%ju packet%s discarded for bad HMAC\n");
1207b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badact,"\t\t%ju packet%s discarded for bad action\n");
1217b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badlen, "\t\t%ju packet%s discarded for short packet\n");
1227b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badval, "\t\t%ju state%s discarded for bad values\n");
1237b95a1ebSYaroslav Tykhiy 	p(pfsyncs_stale, "\t\t%ju stale state%s\n");
1247b95a1ebSYaroslav Tykhiy 	p(pfsyncs_badstate, "\t\t%ju failed state lookup/insert%s\n");
1257b95a1ebSYaroslav Tykhiy 	p(pfsyncs_opackets, "\t%ju packet%s sent (IPv4)\n");
1267b95a1ebSYaroslav Tykhiy 	p(pfsyncs_opackets6, "\t%ju packet%s sent (IPv6)\n");
1277b95a1ebSYaroslav Tykhiy 	p2(pfsyncs_onomem, "\t\t%ju send failed due to mbuf memory error\n");
1287b95a1ebSYaroslav Tykhiy 	p2(pfsyncs_oerrors, "\t\t%ju send error\n");
1292e37c5a3SMax Laier #undef p
1302e37c5a3SMax Laier #undef p2
1312e37c5a3SMax Laier }
132445f17bbSJosef Karthauser 
133445f17bbSJosef Karthauser /*
134445f17bbSJosef Karthauser  * Display a formatted value, or a '-' in the same space.
135445f17bbSJosef Karthauser  */
1365e051718SAssar Westerlund static void
137f964d60dSAssar Westerlund show_stat(const char *fmt, int width, u_long value, short showvalue)
138445f17bbSJosef Karthauser {
1391f575ce8SBruce Evans 	const char *lsep, *rsep;
140445f17bbSJosef Karthauser 	char newfmt[32];
141445f17bbSJosef Karthauser 
1421f575ce8SBruce Evans 	lsep = "";
1431f575ce8SBruce Evans 	if (strncmp(fmt, "LS", 2) == 0) {
1441f575ce8SBruce Evans 		lsep = " ";
1451f575ce8SBruce Evans 		fmt += 2;
1461f575ce8SBruce Evans 	}
1471f575ce8SBruce Evans 	rsep = " ";
1481f575ce8SBruce Evans 	if (strncmp(fmt, "NRS", 3) == 0) {
1491f575ce8SBruce Evans 		rsep = "";
1501f575ce8SBruce Evans 		fmt += 3;
1511f575ce8SBruce Evans 	}
152c2dfd19fSGleb Smirnoff 	if (showvalue == 0) {
153c2dfd19fSGleb Smirnoff 		/* Print just dash. */
1541f575ce8SBruce Evans 		sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
155445f17bbSJosef Karthauser 		printf(newfmt, "-");
156c2dfd19fSGleb Smirnoff 		return;
157445f17bbSJosef Karthauser 	}
158445f17bbSJosef Karthauser 
159c2dfd19fSGleb Smirnoff 	if (hflag) {
160c2dfd19fSGleb Smirnoff 		char buf[5];
161445f17bbSJosef Karthauser 
162c2dfd19fSGleb Smirnoff 		/* Format in human readable form. */
163c2dfd19fSGleb Smirnoff 		humanize_number(buf, sizeof(buf), (int64_t)value, "",
164c2dfd19fSGleb Smirnoff 		    HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
1651f575ce8SBruce Evans 		sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
166c2dfd19fSGleb Smirnoff 		printf(newfmt, buf);
167c2dfd19fSGleb Smirnoff 	} else {
168c2dfd19fSGleb Smirnoff 		/* Construct the format string. */
1691f575ce8SBruce Evans 		sprintf(newfmt, "%s%%%d%s%s", lsep, width, fmt, rsep);
170c2dfd19fSGleb Smirnoff 		printf(newfmt, value);
171c2dfd19fSGleb Smirnoff 	}
172c2dfd19fSGleb Smirnoff }
173445f17bbSJosef Karthauser 
1749b50d902SRodney W. Grimes /*
1759b50d902SRodney W. Grimes  * Print a description of the network interfaces.
1769b50d902SRodney W. Grimes  */
1779b50d902SRodney W. Grimes void
178b6c86f4bSBruce Evans intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
1799b50d902SRodney W. Grimes {
1809b50d902SRodney W. Grimes 	struct ifnet ifnet;
1810e27dc05SGarrett Wollman 	struct ifnethead ifnethead;
1829b50d902SRodney W. Grimes 	union {
1839b50d902SRodney W. Grimes 		struct ifaddr ifa;
1849b50d902SRodney W. Grimes 		struct in_ifaddr in;
185cfa1ca9dSYoshinobu Inoue #ifdef INET6
186cfa1ca9dSYoshinobu Inoue 		struct in6_ifaddr in6;
187cfa1ca9dSYoshinobu Inoue #endif
188cc6a66f2SJulian Elischer 		struct ipx_ifaddr ipx;
1899b50d902SRodney W. Grimes 	} ifaddr;
1909b50d902SRodney W. Grimes 	u_long ifaddraddr;
191f6719675SBill Fenner 	u_long ifaddrfound;
192f6719675SBill Fenner 	u_long ifnetfound;
1935da9f8faSJosef Karthauser 	u_long opackets;
1945da9f8faSJosef Karthauser 	u_long ipackets;
1955da9f8faSJosef Karthauser 	u_long obytes;
1965da9f8faSJosef Karthauser 	u_long ibytes;
197e1655201SRuslan Ermilov 	u_long omcasts;
198e1655201SRuslan Ermilov 	u_long imcasts;
1995da9f8faSJosef Karthauser 	u_long oerrors;
2005da9f8faSJosef Karthauser 	u_long ierrors;
2015da9f8faSJosef Karthauser 	u_long collisions;
2025da9f8faSJosef Karthauser 	short timer;
2035da9f8faSJosef Karthauser 	int drops;
204a97a9922SJulian Elischer 	struct sockaddr *sa = NULL;
2059bf40edeSBrooks Davis 	char name[IFNAMSIZ];
206445f17bbSJosef Karthauser 	short network_layer;
207445f17bbSJosef Karthauser 	short link_layer;
2089b50d902SRodney W. Grimes 
2099b50d902SRodney W. Grimes 	if (ifnetaddr == 0) {
2109b50d902SRodney W. Grimes 		printf("ifnet: symbol not defined\n");
2119b50d902SRodney W. Grimes 		return;
2129b50d902SRodney W. Grimes 	}
213b6c86f4bSBruce Evans 	if (interval1) {
214b6c86f4bSBruce Evans 		sidewaysintpr(interval1, ifnetaddr);
2159b50d902SRodney W. Grimes 		return;
2169b50d902SRodney W. Grimes 	}
2170e27dc05SGarrett Wollman 	if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead))
2189b50d902SRodney W. Grimes 		return;
2194d51ef63SPoul-Henning Kamp 	ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
2200e27dc05SGarrett Wollman 	if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
2210e27dc05SGarrett Wollman 		return;
2220e27dc05SGarrett Wollman 
223cf5e44f8SRuslan Ermilov 	if (!pfunc) {
22425d295e1SBruce M Simpson 		if (Wflag)
22525d295e1SBruce M Simpson 			printf("%-7.7s", "Name");
22625d295e1SBruce M Simpson 		else
22725d295e1SBruce M Simpson 			printf("%-5.5s", "Name");
22825d295e1SBruce M Simpson 		printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s",
22925d295e1SBruce M Simpson 		    "Mtu", "Network", "Address", "Ipkts", "Ierrs");
230e1e293a5SDavid Greenman 		if (bflag)
231e1e293a5SDavid Greenman 			printf(" %10.10s","Ibytes");
232e1e293a5SDavid Greenman 		printf(" %8.8s %5.5s", "Opkts", "Oerrs");
233e1e293a5SDavid Greenman 		if (bflag)
234e1e293a5SDavid Greenman 			printf(" %10.10s","Obytes");
2359b50d902SRodney W. Grimes 		printf(" %5s", "Coll");
2369b50d902SRodney W. Grimes 		if (tflag)
2379b50d902SRodney W. Grimes 			printf(" %s", "Time");
2389b50d902SRodney W. Grimes 		if (dflag)
2399b50d902SRodney W. Grimes 			printf(" %s", "Drop");
2409b50d902SRodney W. Grimes 		putchar('\n');
241cfa1ca9dSYoshinobu Inoue 	}
2429b50d902SRodney W. Grimes 	ifaddraddr = 0;
2439b50d902SRodney W. Grimes 	while (ifnetaddr || ifaddraddr) {
2446cc6f122SPhilippe Charnier 		struct sockaddr_in *sockin;
245cfa1ca9dSYoshinobu Inoue #ifdef INET6
2466cc6f122SPhilippe Charnier 		struct sockaddr_in6 *sockin6;
247cfa1ca9dSYoshinobu Inoue #endif
248a01e3379SDavid Malone 		char *cp;
2499b50d902SRodney W. Grimes 		int n, m;
2509b50d902SRodney W. Grimes 
251445f17bbSJosef Karthauser 		network_layer = 0;
252445f17bbSJosef Karthauser 		link_layer = 0;
253445f17bbSJosef Karthauser 
2549b50d902SRodney W. Grimes 		if (ifaddraddr == 0) {
255f6719675SBill Fenner 			ifnetfound = ifnetaddr;
2569bf40edeSBrooks Davis 			if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
2579b50d902SRodney W. Grimes 				return;
2589bf40edeSBrooks Davis 			strlcpy(name, ifnet.if_xname, sizeof(name));
2594d51ef63SPoul-Henning Kamp 			ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
2601b72e71cSDavid Greenman 			if (interface != 0 && (strcmp(name, interface) != 0))
2619b50d902SRodney W. Grimes 				continue;
2629b50d902SRodney W. Grimes 			cp = index(name, '\0');
263cfa1ca9dSYoshinobu Inoue 
264cfa1ca9dSYoshinobu Inoue 			if (pfunc) {
265cfa1ca9dSYoshinobu Inoue 				(*pfunc)(name);
266cfa1ca9dSYoshinobu Inoue 				continue;
267cfa1ca9dSYoshinobu Inoue 			}
268cfa1ca9dSYoshinobu Inoue 
2699b50d902SRodney W. Grimes 			if ((ifnet.if_flags&IFF_UP) == 0)
2709b50d902SRodney W. Grimes 				*cp++ = '*';
2719b50d902SRodney W. Grimes 			*cp = '\0';
2724d51ef63SPoul-Henning Kamp 			ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead);
2739b50d902SRodney W. Grimes 		}
274f6719675SBill Fenner 		ifaddrfound = ifaddraddr;
2755da9f8faSJosef Karthauser 
2765da9f8faSJosef Karthauser 		/*
2775da9f8faSJosef Karthauser 		 * Get the interface stats.  These may get
2785da9f8faSJosef Karthauser 		 * overriden below on a per-interface basis.
2795da9f8faSJosef Karthauser 		 */
2805da9f8faSJosef Karthauser 		opackets = ifnet.if_opackets;
2815da9f8faSJosef Karthauser 		ipackets = ifnet.if_ipackets;
2825da9f8faSJosef Karthauser 		obytes = ifnet.if_obytes;
2835da9f8faSJosef Karthauser 		ibytes = ifnet.if_ibytes;
284e1655201SRuslan Ermilov 		omcasts = ifnet.if_omcasts;
285e1655201SRuslan Ermilov 		imcasts = ifnet.if_imcasts;
2865da9f8faSJosef Karthauser 		oerrors = ifnet.if_oerrors;
2875da9f8faSJosef Karthauser 		ierrors = ifnet.if_ierrors;
2885da9f8faSJosef Karthauser 		collisions = ifnet.if_collisions;
2895da9f8faSJosef Karthauser 		timer = ifnet.if_timer;
2905da9f8faSJosef Karthauser 		drops = ifnet.if_snd.ifq_drops;
2915da9f8faSJosef Karthauser 
2929b50d902SRodney W. Grimes 		if (ifaddraddr == 0) {
29325d295e1SBruce M Simpson 			if (Wflag)
29425d295e1SBruce M Simpson 				printf("%-7.7s", name);
29525d295e1SBruce M Simpson 			else
29625d295e1SBruce M Simpson 				printf("%-5.5s", name);
29725d295e1SBruce M Simpson 			printf(" %5lu ", ifnet.if_mtu);
298acb60e59SRuslan Ermilov 			printf("%-13.13s ", "none");
299dd1f8b9bSMatthew N. Dodd 			printf("%-17.17s ", "none");
3009b50d902SRodney W. Grimes 		} else {
3019b50d902SRodney W. Grimes 			if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) {
3029b50d902SRodney W. Grimes 				ifaddraddr = 0;
3039b50d902SRodney W. Grimes 				continue;
3049b50d902SRodney W. Grimes 			}
3059b50d902SRodney W. Grimes #define CP(x) ((char *)(x))
3069b50d902SRodney W. Grimes 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
307a97a9922SJulian Elischer 				CP(&ifaddr);
308a97a9922SJulian Elischer 			sa = (struct sockaddr *)cp;
309d44ddba9SRuslan Ermilov 			if (af != AF_UNSPEC && sa->sa_family != af) {
310d44ddba9SRuslan Ermilov 				ifaddraddr =
311d44ddba9SRuslan Ermilov 				    (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
312d44ddba9SRuslan Ermilov 				continue;
313d44ddba9SRuslan Ermilov 			}
31425d295e1SBruce M Simpson 			if (Wflag)
31525d295e1SBruce M Simpson 				printf("%-7.7s", name);
31625d295e1SBruce M Simpson 			else
31725d295e1SBruce M Simpson 				printf("%-5.5s", name);
31825d295e1SBruce M Simpson 			printf(" %5lu ", ifnet.if_mtu);
3199b50d902SRodney W. Grimes 			switch (sa->sa_family) {
3209b50d902SRodney W. Grimes 			case AF_UNSPEC:
321cc6a66f2SJulian Elischer 				printf("%-13.13s ", "none");
3229b50d902SRodney W. Grimes 				printf("%-15.15s ", "none");
3239b50d902SRodney W. Grimes 				break;
3249b50d902SRodney W. Grimes 			case AF_INET:
3256cc6f122SPhilippe Charnier 				sockin = (struct sockaddr_in *)sa;
3269b50d902SRodney W. Grimes #ifdef notdef
3279b50d902SRodney W. Grimes 				/* can't use inet_makeaddr because kernel
3289b50d902SRodney W. Grimes 				 * keeps nets unshifted.
3299b50d902SRodney W. Grimes 				 */
3309b50d902SRodney W. Grimes 				in = inet_makeaddr(ifaddr.in.ia_subnet,
3319b50d902SRodney W. Grimes 					INADDR_ANY);
33209a67ffaSStefan Eßer 				printf("%-13.13s ", netname(in.s_addr,
3339b50d902SRodney W. Grimes 				    ifaddr.in.ia_subnetmask));
3349b50d902SRodney W. Grimes #else
335acb60e59SRuslan Ermilov 				printf("%-13.13s ",
3369b50d902SRodney W. Grimes 				    netname(htonl(ifaddr.in.ia_subnet),
3379b50d902SRodney W. Grimes 				    ifaddr.in.ia_subnetmask));
3389b50d902SRodney W. Grimes #endif
339dd1f8b9bSMatthew N. Dodd 				printf("%-17.17s ",
3406cc6f122SPhilippe Charnier 				    routename(sockin->sin_addr.s_addr));
341445f17bbSJosef Karthauser 
342445f17bbSJosef Karthauser 				network_layer = 1;
3439b50d902SRodney W. Grimes 				break;
344cfa1ca9dSYoshinobu Inoue #ifdef INET6
345cfa1ca9dSYoshinobu Inoue 			case AF_INET6:
3466cc6f122SPhilippe Charnier 				sockin6 = (struct sockaddr_in6 *)sa;
347acb60e59SRuslan Ermilov 				printf("%-13.13s ",
348cfa1ca9dSYoshinobu Inoue 				       netname6(&ifaddr.in6.ia_addr,
349cfa1ca9dSYoshinobu Inoue 						&ifaddr.in6.ia_prefixmask.sin6_addr));
350cfa1ca9dSYoshinobu Inoue 				printf("%-17.17s ",
351a01e3379SDavid Malone 				    inet_ntop(AF_INET6,
3526cc6f122SPhilippe Charnier 					&sockin6->sin6_addr,
353cfa1ca9dSYoshinobu Inoue 					ntop_buf, sizeof(ntop_buf)));
354445f17bbSJosef Karthauser 
355445f17bbSJosef Karthauser 				network_layer = 1;
356cfa1ca9dSYoshinobu Inoue 				break;
357cfa1ca9dSYoshinobu Inoue #endif /*INET6*/
358cc6a66f2SJulian Elischer 			case AF_IPX:
359cc6a66f2SJulian Elischer 				{
360cc6a66f2SJulian Elischer 				struct sockaddr_ipx *sipx =
361cc6a66f2SJulian Elischer 					(struct sockaddr_ipx *)sa;
362cc6a66f2SJulian Elischer 				u_long net;
363cc6a66f2SJulian Elischer 				char netnum[10];
364cc6a66f2SJulian Elischer 
365cc6a66f2SJulian Elischer 				*(union ipx_net *) &net = sipx->sipx_addr.x_net;
36622694ebaSBruce Evans 				sprintf(netnum, "%lx", (u_long)ntohl(net));
367cc6a66f2SJulian Elischer 				printf("ipx:%-8s  ", netnum);
368cc6a66f2SJulian Elischer /*				printf("ipx:%-8s ", netname(net, 0L)); */
369acb60e59SRuslan Ermilov 				printf("%-17s ",
370cc6a66f2SJulian Elischer 				    ipx_phost((struct sockaddr *)sipx));
371cc6a66f2SJulian Elischer 				}
3726f9cdfceSMatthew N. Dodd 
3736f9cdfceSMatthew N. Dodd 				network_layer = 1;
374cc6a66f2SJulian Elischer 				break;
3756ffcfd6cSJulian Elischer 
3766ffcfd6cSJulian Elischer 			case AF_APPLETALK:
377a8d37845SJulian Elischer 				printf("atalk:%-12.12s ",atalk_print(sa,0x10) );
378acb60e59SRuslan Ermilov 				printf("%-11.11s  ",atalk_print(sa,0x0b) );
3796ffcfd6cSJulian Elischer 				break;
3809b50d902SRodney W. Grimes 			case AF_LINK:
3819b50d902SRodney W. Grimes 				{
3829b50d902SRodney W. Grimes 				struct sockaddr_dl *sdl =
3839b50d902SRodney W. Grimes 					(struct sockaddr_dl *)sa;
384cfa1ca9dSYoshinobu Inoue 				char linknum[10];
3859b50d902SRodney W. Grimes 				cp = (char *)LLADDR(sdl);
3869b50d902SRodney W. Grimes 				n = sdl->sdl_alen;
387cfa1ca9dSYoshinobu Inoue 				sprintf(linknum, "<Link#%d>", sdl->sdl_index);
388acb60e59SRuslan Ermilov 				m = printf("%-13.13s ", linknum);
3899b50d902SRodney W. Grimes 				}
3909b50d902SRodney W. Grimes 				goto hexprint;
3919b50d902SRodney W. Grimes 			default:
3929b50d902SRodney W. Grimes 				m = printf("(%d)", sa->sa_family);
3939b50d902SRodney W. Grimes 				for (cp = sa->sa_len + (char *)sa;
3949b50d902SRodney W. Grimes 					--cp > sa->sa_data && (*cp == 0);) {}
3959b50d902SRodney W. Grimes 				n = cp - sa->sa_data + 1;
3969b50d902SRodney W. Grimes 				cp = sa->sa_data;
3979b50d902SRodney W. Grimes 			hexprint:
3989b50d902SRodney W. Grimes 				while (--n >= 0)
399541f2562SDavid Greenman 					m += printf("%02x%c", *cp++ & 0xff,
400e54ca68cSJordan K. Hubbard 						    n > 0 ? ':' : ' ');
401acb60e59SRuslan Ermilov 				m = 32 - m;
4029b50d902SRodney W. Grimes 				while (m-- > 0)
4039b50d902SRodney W. Grimes 					putchar(' ');
404445f17bbSJosef Karthauser 
405445f17bbSJosef Karthauser 				link_layer = 1;
4069b50d902SRodney W. Grimes 				break;
4079b50d902SRodney W. Grimes 			}
4085da9f8faSJosef Karthauser 
4095da9f8faSJosef Karthauser 			/*
4105da9f8faSJosef Karthauser 			 * Fixup the statistics for interfaces that
4115da9f8faSJosef Karthauser 			 * update stats for their network addresses
4125da9f8faSJosef Karthauser 			 */
413445f17bbSJosef Karthauser 			if (network_layer) {
4145da9f8faSJosef Karthauser 				opackets = ifaddr.in.ia_ifa.if_opackets;
4155da9f8faSJosef Karthauser 				ipackets = ifaddr.in.ia_ifa.if_ipackets;
4165da9f8faSJosef Karthauser 				obytes = ifaddr.in.ia_ifa.if_obytes;
4175da9f8faSJosef Karthauser 				ibytes = ifaddr.in.ia_ifa.if_ibytes;
4185da9f8faSJosef Karthauser 			}
4195da9f8faSJosef Karthauser 
4204d51ef63SPoul-Henning Kamp 			ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
4219b50d902SRodney W. Grimes 		}
4225da9f8faSJosef Karthauser 
423445f17bbSJosef Karthauser 		show_stat("lu", 8, ipackets, link_layer|network_layer);
424445f17bbSJosef Karthauser 		show_stat("lu", 5, ierrors, link_layer);
4257c23a867SGleb Smirnoff 		if (bflag)
426445f17bbSJosef Karthauser 			show_stat("lu", 10, ibytes, link_layer|network_layer);
4277c23a867SGleb Smirnoff 
428445f17bbSJosef Karthauser 		show_stat("lu", 8, opackets, link_layer|network_layer);
429445f17bbSJosef Karthauser 		show_stat("lu", 5, oerrors, link_layer);
4307c23a867SGleb Smirnoff 		if (bflag)
431445f17bbSJosef Karthauser 			show_stat("lu", 10, obytes, link_layer|network_layer);
4327c23a867SGleb Smirnoff 
4331f575ce8SBruce Evans 		show_stat("NRSlu", 5, collisions, link_layer);
4347c23a867SGleb Smirnoff 		if (tflag)
4351f575ce8SBruce Evans 			show_stat("LSd", 4, timer, link_layer);
4367c23a867SGleb Smirnoff 		if (dflag)
4371f575ce8SBruce Evans 			show_stat("LSd", 4, drops, link_layer);
4389b50d902SRodney W. Grimes 		putchar('\n');
4391f575ce8SBruce Evans 
440f6719675SBill Fenner 		if (aflag && ifaddrfound) {
441f6719675SBill Fenner 			/*
442f6719675SBill Fenner 			 * Print family's multicast addresses
443f6719675SBill Fenner 			 */
4444d51ef63SPoul-Henning Kamp 			struct ifmultiaddr *multiaddr;
44575fb8770SGarrett Wollman 			struct ifmultiaddr ifma;
44675fb8770SGarrett Wollman 			union {
44775fb8770SGarrett Wollman 				struct sockaddr sa;
44875fb8770SGarrett Wollman 				struct sockaddr_in in;
449cfa1ca9dSYoshinobu Inoue #ifdef INET6
450cfa1ca9dSYoshinobu Inoue 				struct sockaddr_in6 in6;
451cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
45275fb8770SGarrett Wollman 				struct sockaddr_dl dl;
45375fb8770SGarrett Wollman 			} msa;
45475fb8770SGarrett Wollman 			const char *fmt;
455f6719675SBill Fenner 
4566817526dSPoul-Henning Kamp 			TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
4570b23654bSPoul-Henning Kamp 				if (kread((u_long)multiaddr, (char *)&ifma,
45875fb8770SGarrett Wollman 					  sizeof ifma))
459f6719675SBill Fenner 					break;
4600b23654bSPoul-Henning Kamp 				multiaddr = &ifma;
46175fb8770SGarrett Wollman 				if (kread((u_long)ifma.ifma_addr, (char *)&msa,
46275fb8770SGarrett Wollman 					  sizeof msa))
46375fb8770SGarrett Wollman 					break;
46475fb8770SGarrett Wollman 				if (msa.sa.sa_family != sa->sa_family)
46575fb8770SGarrett Wollman 					continue;
46675fb8770SGarrett Wollman 
46775fb8770SGarrett Wollman 				fmt = 0;
46875fb8770SGarrett Wollman 				switch (msa.sa.sa_family) {
46975fb8770SGarrett Wollman 				case AF_INET:
47075fb8770SGarrett Wollman 					fmt = routename(msa.in.sin_addr.s_addr);
47175fb8770SGarrett Wollman 					break;
472cfa1ca9dSYoshinobu Inoue #ifdef INET6
473cfa1ca9dSYoshinobu Inoue 				case AF_INET6:
474bce2e7c8SRuslan Ermilov 					printf("%*s %-19.19s(refs: %d)\n",
475bce2e7c8SRuslan Ermilov 					       Wflag ? 27 : 25, "",
476cfa1ca9dSYoshinobu Inoue 					       inet_ntop(AF_INET6,
477cfa1ca9dSYoshinobu Inoue 							 &msa.in6.sin6_addr,
478cfa1ca9dSYoshinobu Inoue 							 ntop_buf,
479cfa1ca9dSYoshinobu Inoue 							 sizeof(ntop_buf)),
480cfa1ca9dSYoshinobu Inoue 					       ifma.ifma_refcount);
481b9d92bf5SBill Fenner 					break;
482cfa1ca9dSYoshinobu Inoue #endif /* INET6 */
483f6719675SBill Fenner 				case AF_LINK:
484b9d92bf5SBill Fenner 					switch (msa.dl.sdl_type) {
485f6719675SBill Fenner 					case IFT_ETHER:
48675fb8770SGarrett Wollman 					case IFT_FDDI:
48775fb8770SGarrett Wollman 						fmt = ether_ntoa(
48875fb8770SGarrett Wollman 							(struct ether_addr *)
48975fb8770SGarrett Wollman 							LLADDR(&msa.dl));
49075fb8770SGarrett Wollman 						break;
491f6719675SBill Fenner 					}
492f6719675SBill Fenner 					break;
493f6719675SBill Fenner 				}
494e1655201SRuslan Ermilov 				if (fmt) {
495e1655201SRuslan Ermilov 					printf("%*s %-17.17s",
496bce2e7c8SRuslan Ermilov 					    Wflag ? 27 : 25, "", fmt);
497e1655201SRuslan Ermilov 					if (msa.sa.sa_family == AF_LINK) {
498e1655201SRuslan Ermilov 						printf(" %8lu", imcasts);
499e1655201SRuslan Ermilov 						printf("%*s",
500e1655201SRuslan Ermilov 						    bflag ? 17 : 6, "");
501e1655201SRuslan Ermilov 						printf(" %8lu", omcasts);
502e1655201SRuslan Ermilov 					}
503e1655201SRuslan Ermilov 					putchar('\n');
504e1655201SRuslan Ermilov 				}
505f6719675SBill Fenner 			}
506f6719675SBill Fenner 		}
5079b50d902SRodney W. Grimes 	}
5089b50d902SRodney W. Grimes }
5099b50d902SRodney W. Grimes 
5109b50d902SRodney W. Grimes struct	iftot {
5114d51ef63SPoul-Henning Kamp 	SLIST_ENTRY(iftot) chain;
5129bf40edeSBrooks Davis 	char	ift_name[IFNAMSIZ];	/* interface name */
513890bc2a5SDoug Rabson 	u_long	ift_ip;			/* input packets */
514890bc2a5SDoug Rabson 	u_long	ift_ie;			/* input errors */
515890bc2a5SDoug Rabson 	u_long	ift_op;			/* output packets */
516890bc2a5SDoug Rabson 	u_long	ift_oe;			/* output errors */
517890bc2a5SDoug Rabson 	u_long	ift_co;			/* collisions */
518e1e293a5SDavid Greenman 	u_int	ift_dr;			/* drops */
519890bc2a5SDoug Rabson 	u_long	ift_ib;			/* input bytes */
520890bc2a5SDoug Rabson 	u_long	ift_ob;			/* output bytes */
521591c194aSGuido van Rooij };
5229b50d902SRodney W. Grimes 
5239b50d902SRodney W. Grimes u_char	signalled;			/* set if alarm goes off "early" */
5249b50d902SRodney W. Grimes 
5259b50d902SRodney W. Grimes /*
5269b50d902SRodney W. Grimes  * Print a running summary of interface statistics.
527b6c86f4bSBruce Evans  * Repeat display every interval1 seconds, showing statistics
528b6c86f4bSBruce Evans  * collected over that interval.  Assumes that interval1 is non-zero.
5299b50d902SRodney W. Grimes  * First line printed at top of screen is always cumulative.
5300e27dc05SGarrett Wollman  * XXX - should be rewritten to use ifmib(4).
5319b50d902SRodney W. Grimes  */
5329b50d902SRodney W. Grimes static void
533b6c86f4bSBruce Evans sidewaysintpr(int interval1, u_long off)
5349b50d902SRodney W. Grimes {
5359b50d902SRodney W. Grimes 	struct ifnet ifnet;
5369b50d902SRodney W. Grimes 	u_long firstifnet;
5370e27dc05SGarrett Wollman 	struct ifnethead ifnethead;
53893547b07SBruce Evans 	struct itimerval interval_it;
539591c194aSGuido van Rooij 	struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
540a01e3379SDavid Malone 	int line;
5410b87c915SDavid Greenman 	int oldmask, first;
5420b87c915SDavid Greenman 	u_long interesting_off;
5439b50d902SRodney W. Grimes 
5440e27dc05SGarrett Wollman 	if (kread(off, (char *)&ifnethead, sizeof ifnethead))
5459b50d902SRodney W. Grimes 		return;
5464d51ef63SPoul-Henning Kamp 	firstifnet = (u_long)TAILQ_FIRST(&ifnethead);
5470e27dc05SGarrett Wollman 
548591c194aSGuido van Rooij 	if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
549591c194aSGuido van Rooij 		printf("malloc failed\n");
550591c194aSGuido van Rooij 		exit(1);
551591c194aSGuido van Rooij 	}
552591c194aSGuido van Rooij 	memset(iftot, 0, sizeof(struct iftot));
553591c194aSGuido van Rooij 
5540b87c915SDavid Greenman 	interesting = NULL;
5550b87c915SDavid Greenman 	interesting_off = 0;
5569b50d902SRodney W. Grimes 	for (off = firstifnet, ip = iftot; off;) {
5579bf40edeSBrooks Davis 		char name[IFNAMSIZ];
5589b50d902SRodney W. Grimes 
5599b50d902SRodney W. Grimes 		if (kread(off, (char *)&ifnet, sizeof ifnet))
5609b50d902SRodney W. Grimes 			break;
5619bf40edeSBrooks Davis 		strlcpy(name, ifnet.if_xname, sizeof(name));
5620b87c915SDavid Greenman 		if (interface && strcmp(name, interface) == 0) {
5639b50d902SRodney W. Grimes 			interesting = ip;
5640b87c915SDavid Greenman 			interesting_off = off;
5650b87c915SDavid Greenman 		}
566ec3b72e9SRobert Drehmel 		snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);;
567591c194aSGuido van Rooij 		if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
568591c194aSGuido van Rooij 			printf("malloc failed\n");
569591c194aSGuido van Rooij 			exit(1);
570591c194aSGuido van Rooij 		}
571591c194aSGuido van Rooij 		memset(ipn, 0, sizeof(struct iftot));
5724d51ef63SPoul-Henning Kamp 		SLIST_NEXT(ip, chain) = ipn;
573591c194aSGuido van Rooij 		ip = ipn;
5744d51ef63SPoul-Henning Kamp 		off = (u_long)TAILQ_NEXT(&ifnet, if_link);
5759b50d902SRodney W. Grimes 	}
576c6358a5eSRuslan Ermilov 	if (interface && interesting == NULL)
577c6358a5eSRuslan Ermilov 		errx(1, "%s: unknown interface", interface);
578591c194aSGuido van Rooij 	if ((total = malloc(sizeof(struct iftot))) == NULL) {
579591c194aSGuido van Rooij 		printf("malloc failed\n");
580591c194aSGuido van Rooij 		exit(1);
581591c194aSGuido van Rooij 	}
582591c194aSGuido van Rooij 	memset(total, 0, sizeof(struct iftot));
583591c194aSGuido van Rooij 	if ((sum = malloc(sizeof(struct iftot))) == NULL) {
584591c194aSGuido van Rooij 		printf("malloc failed\n");
585591c194aSGuido van Rooij 		exit(1);
586591c194aSGuido van Rooij 	}
587591c194aSGuido van Rooij 	memset(sum, 0, sizeof(struct iftot));
588591c194aSGuido van Rooij 
5899b50d902SRodney W. Grimes 	(void)signal(SIGALRM, catchalarm);
5909b50d902SRodney W. Grimes 	signalled = NO;
59193547b07SBruce Evans 	interval_it.it_interval.tv_sec = interval1;
59293547b07SBruce Evans 	interval_it.it_interval.tv_usec = 0;
59393547b07SBruce Evans 	interval_it.it_value = interval_it.it_interval;
59493547b07SBruce Evans 	setitimer(ITIMER_REAL, &interval_it, NULL);
5950b87c915SDavid Greenman 	first = 1;
5960b87c915SDavid Greenman banner:
5970b87c915SDavid Greenman 	printf("%17s %14s %16s", "input",
5980b87c915SDavid Greenman 	    interesting ? interesting->ift_name : "(Total)", "output");
5999b50d902SRodney W. Grimes 	putchar('\n');
6000b87c915SDavid Greenman 	printf("%10s %5s %10s %10s %5s %10s %5s",
6010b87c915SDavid Greenman 	    "packets", "errs", "bytes", "packets", "errs", "bytes", "colls");
6029b50d902SRodney W. Grimes 	if (dflag)
6039b50d902SRodney W. Grimes 		printf(" %5.5s", "drops");
6049b50d902SRodney W. Grimes 	putchar('\n');
6059b50d902SRodney W. Grimes 	fflush(stdout);
6069b50d902SRodney W. Grimes 	line = 0;
6079b50d902SRodney W. Grimes loop:
6080b87c915SDavid Greenman 	if (interesting != NULL) {
6090b87c915SDavid Greenman 		ip = interesting;
6100b87c915SDavid Greenman 		if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) {
6110b87c915SDavid Greenman 			printf("???\n");
6120b87c915SDavid Greenman 			exit(1);
6130b87c915SDavid Greenman 		};
6140b87c915SDavid Greenman 		if (!first) {
6157c23a867SGleb Smirnoff 			show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1);
6167c23a867SGleb Smirnoff 			show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1);
6177c23a867SGleb Smirnoff 			show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1);
6187c23a867SGleb Smirnoff 			show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1);
6197c23a867SGleb Smirnoff 			show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1);
6207c23a867SGleb Smirnoff 			show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1);
6211f575ce8SBruce Evans 			show_stat("NRSlu", 5,
6221f575ce8SBruce Evans 			    ifnet.if_collisions - ip->ift_co, 1);
6230b87c915SDavid Greenman 			if (dflag)
6241f575ce8SBruce Evans 				show_stat("LSu", 5,
6257c23a867SGleb Smirnoff 				    ifnet.if_snd.ifq_drops - ip->ift_dr, 1);
6260b87c915SDavid Greenman 		}
6270b87c915SDavid Greenman 		ip->ift_ip = ifnet.if_ipackets;
6280b87c915SDavid Greenman 		ip->ift_ie = ifnet.if_ierrors;
6290b87c915SDavid Greenman 		ip->ift_ib = ifnet.if_ibytes;
6300b87c915SDavid Greenman 		ip->ift_op = ifnet.if_opackets;
6310b87c915SDavid Greenman 		ip->ift_oe = ifnet.if_oerrors;
6320b87c915SDavid Greenman 		ip->ift_ob = ifnet.if_obytes;
6330b87c915SDavid Greenman 		ip->ift_co = ifnet.if_collisions;
6340b87c915SDavid Greenman 		ip->ift_dr = ifnet.if_snd.ifq_drops;
6350b87c915SDavid Greenman 	} else {
6369b50d902SRodney W. Grimes 		sum->ift_ip = 0;
6379b50d902SRodney W. Grimes 		sum->ift_ie = 0;
6380b87c915SDavid Greenman 		sum->ift_ib = 0;
6399b50d902SRodney W. Grimes 		sum->ift_op = 0;
6409b50d902SRodney W. Grimes 		sum->ift_oe = 0;
6410b87c915SDavid Greenman 		sum->ift_ob = 0;
6429b50d902SRodney W. Grimes 		sum->ift_co = 0;
6439b50d902SRodney W. Grimes 		sum->ift_dr = 0;
6444d51ef63SPoul-Henning Kamp 		for (off = firstifnet, ip = iftot;
6454d51ef63SPoul-Henning Kamp 		     off && SLIST_NEXT(ip, chain) != NULL;
6464d51ef63SPoul-Henning Kamp 		     ip = SLIST_NEXT(ip, chain)) {
6479b50d902SRodney W. Grimes 			if (kread(off, (char *)&ifnet, sizeof ifnet)) {
6489b50d902SRodney W. Grimes 				off = 0;
6499b50d902SRodney W. Grimes 				continue;
6509b50d902SRodney W. Grimes 			}
6510b87c915SDavid Greenman 			sum->ift_ip += ifnet.if_ipackets;
6520b87c915SDavid Greenman 			sum->ift_ie += ifnet.if_ierrors;
6530b87c915SDavid Greenman 			sum->ift_ib += ifnet.if_ibytes;
6540b87c915SDavid Greenman 			sum->ift_op += ifnet.if_opackets;
6550b87c915SDavid Greenman 			sum->ift_oe += ifnet.if_oerrors;
6560b87c915SDavid Greenman 			sum->ift_ob += ifnet.if_obytes;
6570b87c915SDavid Greenman 			sum->ift_co += ifnet.if_collisions;
6580b87c915SDavid Greenman 			sum->ift_dr += ifnet.if_snd.ifq_drops;
6594d51ef63SPoul-Henning Kamp 			off = (u_long)TAILQ_NEXT(&ifnet, if_link);
6609b50d902SRodney W. Grimes 		}
6610b87c915SDavid Greenman 		if (!first) {
6627c23a867SGleb Smirnoff 			show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1);
6637c23a867SGleb Smirnoff 			show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1);
6647c23a867SGleb Smirnoff 			show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1);
6657c23a867SGleb Smirnoff 			show_stat("lu", 10, sum->ift_op - total->ift_op, 1);
6667c23a867SGleb Smirnoff 			show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1);
6677c23a867SGleb Smirnoff 			show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1);
6681f575ce8SBruce Evans 			show_stat("NRSlu", 5, sum->ift_co - total->ift_co, 1);
6699b50d902SRodney W. Grimes 			if (dflag)
6701f575ce8SBruce Evans 				show_stat("LSu", 5,
6717c23a867SGleb Smirnoff 				    sum->ift_dr - total->ift_dr, 1);
6729b50d902SRodney W. Grimes 		}
6739b50d902SRodney W. Grimes 		*total = *sum;
6740b87c915SDavid Greenman 	}
6750b87c915SDavid Greenman 	if (!first)
6769b50d902SRodney W. Grimes 		putchar('\n');
6779b50d902SRodney W. Grimes 	fflush(stdout);
6789b50d902SRodney W. Grimes 	oldmask = sigblock(sigmask(SIGALRM));
67993547b07SBruce Evans 	while (!signalled)
6809b50d902SRodney W. Grimes 		sigpause(0);
6819b50d902SRodney W. Grimes 	signalled = NO;
68293547b07SBruce Evans 	sigsetmask(oldmask);
6830b87c915SDavid Greenman 	line++;
6840b87c915SDavid Greenman 	first = 0;
6859b50d902SRodney W. Grimes 	if (line == 21)
6869b50d902SRodney W. Grimes 		goto banner;
6870b87c915SDavid Greenman 	else
6889b50d902SRodney W. Grimes 		goto loop;
6899b50d902SRodney W. Grimes 	/*NOTREACHED*/
6909b50d902SRodney W. Grimes }
6919b50d902SRodney W. Grimes 
6929b50d902SRodney W. Grimes /*
69393547b07SBruce Evans  * Set a flag to indicate that a signal from the periodic itimer has been
69493547b07SBruce Evans  * caught.
6959b50d902SRodney W. Grimes  */
6969b50d902SRodney W. Grimes static void
697f964d60dSAssar Westerlund catchalarm(int signo __unused)
6989b50d902SRodney W. Grimes {
6999b50d902SRodney W. Grimes 	signalled = YES;
7009b50d902SRodney W. Grimes }
701