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> 460024d1dbSLuigi Rizzo #include <sys/sysctl.h> 47628d2ac1SGarrett Wollman #include <sys/time.h> 489b50d902SRodney W. Grimes 499b50d902SRodney W. Grimes #include <net/if.h> 5087669425SGarrett Wollman #include <net/if_var.h> 519b50d902SRodney W. Grimes #include <net/if_dl.h> 52f6719675SBill Fenner #include <net/if_types.h> 530024d1dbSLuigi Rizzo #include <net/bridge.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> 679b50d902SRodney W. Grimes #include <stdio.h> 68591c194aSGuido van Rooij #include <stdlib.h> 699b50d902SRodney W. Grimes #include <string.h> 709b50d902SRodney W. Grimes #include <unistd.h> 719b50d902SRodney W. Grimes 729b50d902SRodney W. Grimes #include "netstat.h" 739b50d902SRodney W. Grimes 749b50d902SRodney W. Grimes #define YES 1 759b50d902SRodney W. Grimes #define NO 0 769b50d902SRodney W. Grimes 775e051718SAssar Westerlund static void sidewaysintpr (u_int, u_long); 785e051718SAssar Westerlund static void catchalarm (int); 799b50d902SRodney W. Grimes 80cfa1ca9dSYoshinobu Inoue #ifdef INET6 81cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */ 82cfa1ca9dSYoshinobu Inoue static int bdg_done; 83cfa1ca9dSYoshinobu Inoue #endif 84cfa1ca9dSYoshinobu Inoue 85f964d60dSAssar Westerlund /* print bridge statistics */ 860024d1dbSLuigi Rizzo void 87a01e3379SDavid Malone bdg_stats(u_long dummy __unused, const char *name, int af1 __unused) 880024d1dbSLuigi Rizzo { 89890bc2a5SDoug Rabson int i; 90890bc2a5SDoug Rabson size_t slen ; 910024d1dbSLuigi Rizzo struct bdg_stats s ; 920024d1dbSLuigi Rizzo int mib[4] ; 930024d1dbSLuigi Rizzo 940024d1dbSLuigi Rizzo slen = sizeof(s); 950024d1dbSLuigi Rizzo 960024d1dbSLuigi Rizzo mib[0] = CTL_NET ; 970024d1dbSLuigi Rizzo mib[1] = PF_LINK ; 980024d1dbSLuigi Rizzo mib[2] = IFT_ETHER ; 990024d1dbSLuigi Rizzo mib[3] = PF_BDG ; 1000024d1dbSLuigi Rizzo if (sysctl(mib,4, &s,&slen,NULL,0)==-1) 1010024d1dbSLuigi Rizzo return ; /* no bridging */ 102cfa1ca9dSYoshinobu Inoue #ifdef INET6 103cfa1ca9dSYoshinobu Inoue if (bdg_done != 0) 104cfa1ca9dSYoshinobu Inoue return; 105cfa1ca9dSYoshinobu Inoue else 106cfa1ca9dSYoshinobu Inoue bdg_done = 1; 107cfa1ca9dSYoshinobu Inoue #endif 1080024d1dbSLuigi Rizzo printf("-- Bridging statistics (%s) --\n", name) ; 1090024d1dbSLuigi Rizzo printf( 1100024d1dbSLuigi Rizzo "Name In Out Forward Drop Bcast Mcast Local Unknown\n"); 1110024d1dbSLuigi Rizzo for (i = 0 ; i < 16 ; i++) { 1120024d1dbSLuigi Rizzo if (s.s[i].name[0]) 113f41f949dSMatthew Dillon printf("%-6s %9ld%9ld%9ld%9ld%9ld%9ld%9ld%9ld\n", 1140024d1dbSLuigi Rizzo s.s[i].name, 1150024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_IN], 1160024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_OUT], 1170024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_FORWARD], 1180024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_DROP], 1190024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_BCAST], 1200024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_MCAST], 1210024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_LOCAL], 1220024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_UNKNOWN] ); 1230024d1dbSLuigi Rizzo } 1240024d1dbSLuigi Rizzo } 1250024d1dbSLuigi Rizzo 1262e37c5a3SMax Laier /* 1272e37c5a3SMax Laier * Dump pfsync statistics structure. 1282e37c5a3SMax Laier */ 1292e37c5a3SMax Laier void 1302e37c5a3SMax Laier pfsync_stats(u_long off __unused, const char *name, int af1 __unused) 1312e37c5a3SMax Laier { 1322e37c5a3SMax Laier struct pfsyncstats pfsyncstat, zerostat; 1332e37c5a3SMax Laier size_t len = sizeof(struct pfsyncstats); 134445f17bbSJosef Karthauser 1352e37c5a3SMax Laier if (zflag) 1362e37c5a3SMax Laier memset(&zerostat, 0, len); 1372e37c5a3SMax Laier if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len, 1382e37c5a3SMax Laier zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 1392e37c5a3SMax Laier if (errno != ENOENT) 1402e37c5a3SMax Laier warn("sysctl: net.inet.pfsync.stats"); 1412e37c5a3SMax Laier return; 1422e37c5a3SMax Laier } 143445f17bbSJosef Karthauser 1442e37c5a3SMax Laier printf("%s:\n", name); 1452e37c5a3SMax Laier 1462e37c5a3SMax Laier #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ 1472e37c5a3SMax Laier printf(m, (unsigned long long)pfsyncstat.f, plural(pfsyncstat.f)) 1482e37c5a3SMax Laier #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ 1492e37c5a3SMax Laier printf(m, (unsigned long long)pfsyncstat.f) 1502e37c5a3SMax Laier 1512e37c5a3SMax Laier p(pfsyncs_ipackets, "\t%llu packet%s received (IPv4)\n"); 1522e37c5a3SMax Laier p(pfsyncs_ipackets6, "\t%llu packet%s received (IPv6)\n"); 1532e37c5a3SMax Laier p(pfsyncs_badif, "\t\t%llu packet%s discarded for bad interface\n"); 1542e37c5a3SMax Laier p(pfsyncs_badttl, "\t\t%llu packet%s discarded for bad ttl\n"); 1552e37c5a3SMax Laier p(pfsyncs_hdrops, "\t\t%llu packet%s shorter than header\n"); 1562e37c5a3SMax Laier p(pfsyncs_badver, "\t\t%llu packet%s discarded for bad version\n"); 1572e37c5a3SMax Laier p(pfsyncs_badauth, "\t\t%llu packet%s discarded for bad HMAC\n"); 1582e37c5a3SMax Laier p(pfsyncs_badact,"\t\t%llu packet%s discarded for bad action\n"); 1592e37c5a3SMax Laier p(pfsyncs_badlen, "\t\t%llu packet%s discarded for short packet\n"); 1602e37c5a3SMax Laier p(pfsyncs_badval, "\t\t%llu state%s discarded for bad values\n"); 1612e37c5a3SMax Laier p(pfsyncs_stale, "\t\t%llu stale state%s\n"); 1622e37c5a3SMax Laier p(pfsyncs_badstate, "\t\t%llu failed state lookup/insert%s\n"); 1632e37c5a3SMax Laier p(pfsyncs_opackets, "\t%llu packet%s sent (IPv4)\n"); 1642e37c5a3SMax Laier p(pfsyncs_opackets6, "\t%llu packet%s sent (IPv6)\n"); 1652e37c5a3SMax Laier p2(pfsyncs_onomem, "\t\t%llu send failed due to mbuf memory error\n"); 1662e37c5a3SMax Laier p2(pfsyncs_oerrors, "\t\t%llu send error\n"); 1672e37c5a3SMax Laier #undef p 1682e37c5a3SMax Laier #undef p2 1692e37c5a3SMax Laier } 170445f17bbSJosef Karthauser 171445f17bbSJosef Karthauser /* 172445f17bbSJosef Karthauser * Display a formatted value, or a '-' in the same space. 173445f17bbSJosef Karthauser */ 1745e051718SAssar Westerlund static void 175f964d60dSAssar Westerlund show_stat(const char *fmt, int width, u_long value, short showvalue) 176445f17bbSJosef Karthauser { 177445f17bbSJosef Karthauser char newfmt[32]; 178445f17bbSJosef Karthauser 179c2dfd19fSGleb Smirnoff if (showvalue == 0) { 180c2dfd19fSGleb Smirnoff /* Print just dash. */ 181445f17bbSJosef Karthauser sprintf(newfmt, "%%%ds ", width); 182445f17bbSJosef Karthauser printf(newfmt, "-"); 183c2dfd19fSGleb Smirnoff return; 184445f17bbSJosef Karthauser } 185445f17bbSJosef Karthauser 186c2dfd19fSGleb Smirnoff if (hflag) { 187c2dfd19fSGleb Smirnoff char buf[5]; 188445f17bbSJosef Karthauser 189c2dfd19fSGleb Smirnoff /* Format in human readable form. */ 190c2dfd19fSGleb Smirnoff humanize_number(buf, sizeof(buf), (int64_t)value, "", 191c2dfd19fSGleb Smirnoff HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); 192c2dfd19fSGleb Smirnoff sprintf(newfmt, "%%%ds ", width); 193c2dfd19fSGleb Smirnoff printf(newfmt, buf); 194c2dfd19fSGleb Smirnoff } else { 195c2dfd19fSGleb Smirnoff /* Construct the format string. */ 196c2dfd19fSGleb Smirnoff sprintf(newfmt, "%%%d%s ", width, fmt); 197c2dfd19fSGleb Smirnoff printf(newfmt, value); 198c2dfd19fSGleb Smirnoff } 199c2dfd19fSGleb Smirnoff } 200445f17bbSJosef Karthauser 2019b50d902SRodney W. Grimes /* 2029b50d902SRodney W. Grimes * Print a description of the network interfaces. 2039b50d902SRodney W. Grimes */ 2049b50d902SRodney W. Grimes void 205e65dd7bcSMark Murray intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) 2069b50d902SRodney W. Grimes { 2079b50d902SRodney W. Grimes struct ifnet ifnet; 2080e27dc05SGarrett Wollman struct ifnethead ifnethead; 2099b50d902SRodney W. Grimes union { 2109b50d902SRodney W. Grimes struct ifaddr ifa; 2119b50d902SRodney W. Grimes struct in_ifaddr in; 212cfa1ca9dSYoshinobu Inoue #ifdef INET6 213cfa1ca9dSYoshinobu Inoue struct in6_ifaddr in6; 214cfa1ca9dSYoshinobu Inoue #endif 215cc6a66f2SJulian Elischer struct ipx_ifaddr ipx; 2169b50d902SRodney W. Grimes } ifaddr; 2179b50d902SRodney W. Grimes u_long ifaddraddr; 218f6719675SBill Fenner u_long ifaddrfound; 219f6719675SBill Fenner u_long ifnetfound; 2205da9f8faSJosef Karthauser u_long opackets; 2215da9f8faSJosef Karthauser u_long ipackets; 2225da9f8faSJosef Karthauser u_long obytes; 2235da9f8faSJosef Karthauser u_long ibytes; 224e1655201SRuslan Ermilov u_long omcasts; 225e1655201SRuslan Ermilov u_long imcasts; 2265da9f8faSJosef Karthauser u_long oerrors; 2275da9f8faSJosef Karthauser u_long ierrors; 2285da9f8faSJosef Karthauser u_long collisions; 2295da9f8faSJosef Karthauser short timer; 2305da9f8faSJosef Karthauser int drops; 231a97a9922SJulian Elischer struct sockaddr *sa = NULL; 2329bf40edeSBrooks Davis char name[IFNAMSIZ]; 233445f17bbSJosef Karthauser short network_layer; 234445f17bbSJosef Karthauser short link_layer; 2359b50d902SRodney W. Grimes 2369b50d902SRodney W. Grimes if (ifnetaddr == 0) { 2379b50d902SRodney W. Grimes printf("ifnet: symbol not defined\n"); 2389b50d902SRodney W. Grimes return; 2399b50d902SRodney W. Grimes } 240e65dd7bcSMark Murray if (_interval) { 241e65dd7bcSMark Murray sidewaysintpr((unsigned)_interval, ifnetaddr); 2429b50d902SRodney W. Grimes return; 2439b50d902SRodney W. Grimes } 2440e27dc05SGarrett Wollman if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) 2459b50d902SRodney W. Grimes return; 2464d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); 2470e27dc05SGarrett Wollman if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 2480e27dc05SGarrett Wollman return; 2490e27dc05SGarrett Wollman 250cf5e44f8SRuslan Ermilov if (!pfunc) { 25125d295e1SBruce M Simpson if (Wflag) 25225d295e1SBruce M Simpson printf("%-7.7s", "Name"); 25325d295e1SBruce M Simpson else 25425d295e1SBruce M Simpson printf("%-5.5s", "Name"); 25525d295e1SBruce M Simpson printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s", 25625d295e1SBruce M Simpson "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 257e1e293a5SDavid Greenman if (bflag) 258e1e293a5SDavid Greenman printf(" %10.10s","Ibytes"); 259e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 260e1e293a5SDavid Greenman if (bflag) 261e1e293a5SDavid Greenman printf(" %10.10s","Obytes"); 2629b50d902SRodney W. Grimes printf(" %5s", "Coll"); 2639b50d902SRodney W. Grimes if (tflag) 2649b50d902SRodney W. Grimes printf(" %s", "Time"); 2659b50d902SRodney W. Grimes if (dflag) 2669b50d902SRodney W. Grimes printf(" %s", "Drop"); 2679b50d902SRodney W. Grimes putchar('\n'); 268cfa1ca9dSYoshinobu Inoue } 2699b50d902SRodney W. Grimes ifaddraddr = 0; 2709b50d902SRodney W. Grimes while (ifnetaddr || ifaddraddr) { 2716cc6f122SPhilippe Charnier struct sockaddr_in *sockin; 272cfa1ca9dSYoshinobu Inoue #ifdef INET6 2736cc6f122SPhilippe Charnier struct sockaddr_in6 *sockin6; 274cfa1ca9dSYoshinobu Inoue #endif 275a01e3379SDavid Malone char *cp; 2769b50d902SRodney W. Grimes int n, m; 2779b50d902SRodney W. Grimes 278445f17bbSJosef Karthauser network_layer = 0; 279445f17bbSJosef Karthauser link_layer = 0; 280445f17bbSJosef Karthauser 2819b50d902SRodney W. Grimes if (ifaddraddr == 0) { 282f6719675SBill Fenner ifnetfound = ifnetaddr; 2839bf40edeSBrooks Davis if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 2849b50d902SRodney W. Grimes return; 2859bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 2864d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); 2871b72e71cSDavid Greenman if (interface != 0 && (strcmp(name, interface) != 0)) 2889b50d902SRodney W. Grimes continue; 2899b50d902SRodney W. Grimes cp = index(name, '\0'); 290cfa1ca9dSYoshinobu Inoue 291cfa1ca9dSYoshinobu Inoue if (pfunc) { 292cfa1ca9dSYoshinobu Inoue (*pfunc)(name); 293cfa1ca9dSYoshinobu Inoue continue; 294cfa1ca9dSYoshinobu Inoue } 295cfa1ca9dSYoshinobu Inoue 2969b50d902SRodney W. Grimes if ((ifnet.if_flags&IFF_UP) == 0) 2979b50d902SRodney W. Grimes *cp++ = '*'; 2989b50d902SRodney W. Grimes *cp = '\0'; 2994d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); 3009b50d902SRodney W. Grimes } 301f6719675SBill Fenner ifaddrfound = ifaddraddr; 3025da9f8faSJosef Karthauser 3035da9f8faSJosef Karthauser /* 3045da9f8faSJosef Karthauser * Get the interface stats. These may get 3055da9f8faSJosef Karthauser * overriden below on a per-interface basis. 3065da9f8faSJosef Karthauser */ 3075da9f8faSJosef Karthauser opackets = ifnet.if_opackets; 3085da9f8faSJosef Karthauser ipackets = ifnet.if_ipackets; 3095da9f8faSJosef Karthauser obytes = ifnet.if_obytes; 3105da9f8faSJosef Karthauser ibytes = ifnet.if_ibytes; 311e1655201SRuslan Ermilov omcasts = ifnet.if_omcasts; 312e1655201SRuslan Ermilov imcasts = ifnet.if_imcasts; 3135da9f8faSJosef Karthauser oerrors = ifnet.if_oerrors; 3145da9f8faSJosef Karthauser ierrors = ifnet.if_ierrors; 3155da9f8faSJosef Karthauser collisions = ifnet.if_collisions; 3165da9f8faSJosef Karthauser timer = ifnet.if_timer; 3175da9f8faSJosef Karthauser drops = ifnet.if_snd.ifq_drops; 3185da9f8faSJosef Karthauser 3199b50d902SRodney W. Grimes if (ifaddraddr == 0) { 32025d295e1SBruce M Simpson if (Wflag) 32125d295e1SBruce M Simpson printf("%-7.7s", name); 32225d295e1SBruce M Simpson else 32325d295e1SBruce M Simpson printf("%-5.5s", name); 32425d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 325acb60e59SRuslan Ermilov printf("%-13.13s ", "none"); 326dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", "none"); 3279b50d902SRodney W. Grimes } else { 3289b50d902SRodney W. Grimes if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) { 3299b50d902SRodney W. Grimes ifaddraddr = 0; 3309b50d902SRodney W. Grimes continue; 3319b50d902SRodney W. Grimes } 3329b50d902SRodney W. Grimes #define CP(x) ((char *)(x)) 3339b50d902SRodney W. Grimes cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 334a97a9922SJulian Elischer CP(&ifaddr); 335a97a9922SJulian Elischer sa = (struct sockaddr *)cp; 336d44ddba9SRuslan Ermilov if (af != AF_UNSPEC && sa->sa_family != af) { 337d44ddba9SRuslan Ermilov ifaddraddr = 338d44ddba9SRuslan Ermilov (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 339d44ddba9SRuslan Ermilov continue; 340d44ddba9SRuslan Ermilov } 34125d295e1SBruce M Simpson if (Wflag) 34225d295e1SBruce M Simpson printf("%-7.7s", name); 34325d295e1SBruce M Simpson else 34425d295e1SBruce M Simpson printf("%-5.5s", name); 34525d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 3469b50d902SRodney W. Grimes switch (sa->sa_family) { 3479b50d902SRodney W. Grimes case AF_UNSPEC: 348cc6a66f2SJulian Elischer printf("%-13.13s ", "none"); 3499b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 3509b50d902SRodney W. Grimes break; 3519b50d902SRodney W. Grimes case AF_INET: 3526cc6f122SPhilippe Charnier sockin = (struct sockaddr_in *)sa; 3539b50d902SRodney W. Grimes #ifdef notdef 3549b50d902SRodney W. Grimes /* can't use inet_makeaddr because kernel 3559b50d902SRodney W. Grimes * keeps nets unshifted. 3569b50d902SRodney W. Grimes */ 3579b50d902SRodney W. Grimes in = inet_makeaddr(ifaddr.in.ia_subnet, 3589b50d902SRodney W. Grimes INADDR_ANY); 35909a67ffaSStefan Eßer printf("%-13.13s ", netname(in.s_addr, 3609b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3619b50d902SRodney W. Grimes #else 362acb60e59SRuslan Ermilov printf("%-13.13s ", 3639b50d902SRodney W. Grimes netname(htonl(ifaddr.in.ia_subnet), 3649b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3659b50d902SRodney W. Grimes #endif 366dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", 3676cc6f122SPhilippe Charnier routename(sockin->sin_addr.s_addr)); 368445f17bbSJosef Karthauser 369445f17bbSJosef Karthauser network_layer = 1; 3709b50d902SRodney W. Grimes break; 371cfa1ca9dSYoshinobu Inoue #ifdef INET6 372cfa1ca9dSYoshinobu Inoue case AF_INET6: 3736cc6f122SPhilippe Charnier sockin6 = (struct sockaddr_in6 *)sa; 374acb60e59SRuslan Ermilov printf("%-13.13s ", 375cfa1ca9dSYoshinobu Inoue netname6(&ifaddr.in6.ia_addr, 376cfa1ca9dSYoshinobu Inoue &ifaddr.in6.ia_prefixmask.sin6_addr)); 377cfa1ca9dSYoshinobu Inoue printf("%-17.17s ", 378a01e3379SDavid Malone inet_ntop(AF_INET6, 3796cc6f122SPhilippe Charnier &sockin6->sin6_addr, 380cfa1ca9dSYoshinobu Inoue ntop_buf, sizeof(ntop_buf))); 381445f17bbSJosef Karthauser 382445f17bbSJosef Karthauser network_layer = 1; 383cfa1ca9dSYoshinobu Inoue break; 384cfa1ca9dSYoshinobu Inoue #endif /*INET6*/ 385cc6a66f2SJulian Elischer case AF_IPX: 386cc6a66f2SJulian Elischer { 387cc6a66f2SJulian Elischer struct sockaddr_ipx *sipx = 388cc6a66f2SJulian Elischer (struct sockaddr_ipx *)sa; 389cc6a66f2SJulian Elischer u_long net; 390cc6a66f2SJulian Elischer char netnum[10]; 391cc6a66f2SJulian Elischer 392cc6a66f2SJulian Elischer *(union ipx_net *) &net = sipx->sipx_addr.x_net; 39322694ebaSBruce Evans sprintf(netnum, "%lx", (u_long)ntohl(net)); 394cc6a66f2SJulian Elischer printf("ipx:%-8s ", netnum); 395cc6a66f2SJulian Elischer /* printf("ipx:%-8s ", netname(net, 0L)); */ 396acb60e59SRuslan Ermilov printf("%-17s ", 397cc6a66f2SJulian Elischer ipx_phost((struct sockaddr *)sipx)); 398cc6a66f2SJulian Elischer } 3996f9cdfceSMatthew N. Dodd 4006f9cdfceSMatthew N. Dodd network_layer = 1; 401cc6a66f2SJulian Elischer break; 4026ffcfd6cSJulian Elischer 4036ffcfd6cSJulian Elischer case AF_APPLETALK: 404a8d37845SJulian Elischer printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); 405acb60e59SRuslan Ermilov printf("%-11.11s ",atalk_print(sa,0x0b) ); 4066ffcfd6cSJulian Elischer break; 4079b50d902SRodney W. Grimes case AF_LINK: 4089b50d902SRodney W. Grimes { 4099b50d902SRodney W. Grimes struct sockaddr_dl *sdl = 4109b50d902SRodney W. Grimes (struct sockaddr_dl *)sa; 411cfa1ca9dSYoshinobu Inoue char linknum[10]; 4129b50d902SRodney W. Grimes cp = (char *)LLADDR(sdl); 4139b50d902SRodney W. Grimes n = sdl->sdl_alen; 414cfa1ca9dSYoshinobu Inoue sprintf(linknum, "<Link#%d>", sdl->sdl_index); 415acb60e59SRuslan Ermilov m = printf("%-13.13s ", linknum); 4169b50d902SRodney W. Grimes } 4179b50d902SRodney W. Grimes goto hexprint; 4189b50d902SRodney W. Grimes default: 4199b50d902SRodney W. Grimes m = printf("(%d)", sa->sa_family); 4209b50d902SRodney W. Grimes for (cp = sa->sa_len + (char *)sa; 4219b50d902SRodney W. Grimes --cp > sa->sa_data && (*cp == 0);) {} 4229b50d902SRodney W. Grimes n = cp - sa->sa_data + 1; 4239b50d902SRodney W. Grimes cp = sa->sa_data; 4249b50d902SRodney W. Grimes hexprint: 4259b50d902SRodney W. Grimes while (--n >= 0) 426541f2562SDavid Greenman m += printf("%02x%c", *cp++ & 0xff, 427e54ca68cSJordan K. Hubbard n > 0 ? ':' : ' '); 428acb60e59SRuslan Ermilov m = 32 - m; 4299b50d902SRodney W. Grimes while (m-- > 0) 4309b50d902SRodney W. Grimes putchar(' '); 431445f17bbSJosef Karthauser 432445f17bbSJosef Karthauser link_layer = 1; 4339b50d902SRodney W. Grimes break; 4349b50d902SRodney W. Grimes } 4355da9f8faSJosef Karthauser 4365da9f8faSJosef Karthauser /* 4375da9f8faSJosef Karthauser * Fixup the statistics for interfaces that 4385da9f8faSJosef Karthauser * update stats for their network addresses 4395da9f8faSJosef Karthauser */ 440445f17bbSJosef Karthauser if (network_layer) { 4415da9f8faSJosef Karthauser opackets = ifaddr.in.ia_ifa.if_opackets; 4425da9f8faSJosef Karthauser ipackets = ifaddr.in.ia_ifa.if_ipackets; 4435da9f8faSJosef Karthauser obytes = ifaddr.in.ia_ifa.if_obytes; 4445da9f8faSJosef Karthauser ibytes = ifaddr.in.ia_ifa.if_ibytes; 4455da9f8faSJosef Karthauser } 4465da9f8faSJosef Karthauser 4474d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 4489b50d902SRodney W. Grimes } 4495da9f8faSJosef Karthauser 450445f17bbSJosef Karthauser show_stat("lu", 8, ipackets, link_layer|network_layer); 451445f17bbSJosef Karthauser show_stat("lu", 5, ierrors, link_layer); 4527c23a867SGleb Smirnoff if (bflag) 453445f17bbSJosef Karthauser show_stat("lu", 10, ibytes, link_layer|network_layer); 4547c23a867SGleb Smirnoff 455445f17bbSJosef Karthauser show_stat("lu", 8, opackets, link_layer|network_layer); 456445f17bbSJosef Karthauser show_stat("lu", 5, oerrors, link_layer); 4577c23a867SGleb Smirnoff if (bflag) 458445f17bbSJosef Karthauser show_stat("lu", 10, obytes, link_layer|network_layer); 4597c23a867SGleb Smirnoff 460445f17bbSJosef Karthauser show_stat("lu", 5, collisions, link_layer); 4617c23a867SGleb Smirnoff if (tflag) 462445f17bbSJosef Karthauser show_stat("d", 3, timer, link_layer); 4637c23a867SGleb Smirnoff 4647c23a867SGleb Smirnoff if (dflag) 465445f17bbSJosef Karthauser show_stat("d", 3, drops, link_layer); 4667c23a867SGleb Smirnoff 4679b50d902SRodney W. Grimes putchar('\n'); 468f6719675SBill Fenner if (aflag && ifaddrfound) { 469f6719675SBill Fenner /* 470f6719675SBill Fenner * Print family's multicast addresses 471f6719675SBill Fenner */ 4724d51ef63SPoul-Henning Kamp struct ifmultiaddr *multiaddr; 47375fb8770SGarrett Wollman struct ifmultiaddr ifma; 47475fb8770SGarrett Wollman union { 47575fb8770SGarrett Wollman struct sockaddr sa; 47675fb8770SGarrett Wollman struct sockaddr_in in; 477cfa1ca9dSYoshinobu Inoue #ifdef INET6 478cfa1ca9dSYoshinobu Inoue struct sockaddr_in6 in6; 479cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 48075fb8770SGarrett Wollman struct sockaddr_dl dl; 48175fb8770SGarrett Wollman } msa; 48275fb8770SGarrett Wollman const char *fmt; 483f6719675SBill Fenner 4846817526dSPoul-Henning Kamp TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) { 4850b23654bSPoul-Henning Kamp if (kread((u_long)multiaddr, (char *)&ifma, 48675fb8770SGarrett Wollman sizeof ifma)) 487f6719675SBill Fenner break; 4880b23654bSPoul-Henning Kamp multiaddr = &ifma; 48975fb8770SGarrett Wollman if (kread((u_long)ifma.ifma_addr, (char *)&msa, 49075fb8770SGarrett Wollman sizeof msa)) 49175fb8770SGarrett Wollman break; 49275fb8770SGarrett Wollman if (msa.sa.sa_family != sa->sa_family) 49375fb8770SGarrett Wollman continue; 49475fb8770SGarrett Wollman 49575fb8770SGarrett Wollman fmt = 0; 49675fb8770SGarrett Wollman switch (msa.sa.sa_family) { 49775fb8770SGarrett Wollman case AF_INET: 49875fb8770SGarrett Wollman fmt = routename(msa.in.sin_addr.s_addr); 49975fb8770SGarrett Wollman break; 500cfa1ca9dSYoshinobu Inoue #ifdef INET6 501cfa1ca9dSYoshinobu Inoue case AF_INET6: 502bce2e7c8SRuslan Ermilov printf("%*s %-19.19s(refs: %d)\n", 503bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", 504cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, 505cfa1ca9dSYoshinobu Inoue &msa.in6.sin6_addr, 506cfa1ca9dSYoshinobu Inoue ntop_buf, 507cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf)), 508cfa1ca9dSYoshinobu Inoue ifma.ifma_refcount); 509b9d92bf5SBill Fenner break; 510cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 511f6719675SBill Fenner case AF_LINK: 512b9d92bf5SBill Fenner switch (msa.dl.sdl_type) { 513f6719675SBill Fenner case IFT_ETHER: 51475fb8770SGarrett Wollman case IFT_FDDI: 51575fb8770SGarrett Wollman fmt = ether_ntoa( 51675fb8770SGarrett Wollman (struct ether_addr *) 51775fb8770SGarrett Wollman LLADDR(&msa.dl)); 51875fb8770SGarrett Wollman break; 519f6719675SBill Fenner } 520f6719675SBill Fenner break; 521f6719675SBill Fenner } 522e1655201SRuslan Ermilov if (fmt) { 523e1655201SRuslan Ermilov printf("%*s %-17.17s", 524bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", fmt); 525e1655201SRuslan Ermilov if (msa.sa.sa_family == AF_LINK) { 526e1655201SRuslan Ermilov printf(" %8lu", imcasts); 527e1655201SRuslan Ermilov printf("%*s", 528e1655201SRuslan Ermilov bflag ? 17 : 6, ""); 529e1655201SRuslan Ermilov printf(" %8lu", omcasts); 530e1655201SRuslan Ermilov } 531e1655201SRuslan Ermilov putchar('\n'); 532e1655201SRuslan Ermilov } 533f6719675SBill Fenner } 534f6719675SBill Fenner } 5359b50d902SRodney W. Grimes } 5369b50d902SRodney W. Grimes } 5379b50d902SRodney W. Grimes 5389b50d902SRodney W. Grimes struct iftot { 5394d51ef63SPoul-Henning Kamp SLIST_ENTRY(iftot) chain; 5409bf40edeSBrooks Davis char ift_name[IFNAMSIZ]; /* interface name */ 541890bc2a5SDoug Rabson u_long ift_ip; /* input packets */ 542890bc2a5SDoug Rabson u_long ift_ie; /* input errors */ 543890bc2a5SDoug Rabson u_long ift_op; /* output packets */ 544890bc2a5SDoug Rabson u_long ift_oe; /* output errors */ 545890bc2a5SDoug Rabson u_long ift_co; /* collisions */ 546e1e293a5SDavid Greenman u_int ift_dr; /* drops */ 547890bc2a5SDoug Rabson u_long ift_ib; /* input bytes */ 548890bc2a5SDoug Rabson u_long ift_ob; /* output bytes */ 549591c194aSGuido van Rooij }; 5509b50d902SRodney W. Grimes 5519b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 5529b50d902SRodney W. Grimes 5539b50d902SRodney W. Grimes /* 5549b50d902SRodney W. Grimes * Print a running summary of interface statistics. 5559b50d902SRodney W. Grimes * Repeat display every interval seconds, showing statistics 5569b50d902SRodney W. Grimes * collected over that interval. Assumes that interval is non-zero. 5579b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 5580e27dc05SGarrett Wollman * XXX - should be rewritten to use ifmib(4). 5599b50d902SRodney W. Grimes */ 5609b50d902SRodney W. Grimes static void 561a01e3379SDavid Malone sidewaysintpr(unsigned interval1, u_long off) 5629b50d902SRodney W. Grimes { 5639b50d902SRodney W. Grimes struct ifnet ifnet; 5649b50d902SRodney W. Grimes u_long firstifnet; 5650e27dc05SGarrett Wollman struct ifnethead ifnethead; 566591c194aSGuido van Rooij struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; 567a01e3379SDavid Malone int line; 5680b87c915SDavid Greenman int oldmask, first; 5690b87c915SDavid Greenman u_long interesting_off; 5709b50d902SRodney W. Grimes 5710e27dc05SGarrett Wollman if (kread(off, (char *)&ifnethead, sizeof ifnethead)) 5729b50d902SRodney W. Grimes return; 5734d51ef63SPoul-Henning Kamp firstifnet = (u_long)TAILQ_FIRST(&ifnethead); 5740e27dc05SGarrett Wollman 575591c194aSGuido van Rooij if ((iftot = malloc(sizeof(struct iftot))) == NULL) { 576591c194aSGuido van Rooij printf("malloc failed\n"); 577591c194aSGuido van Rooij exit(1); 578591c194aSGuido van Rooij } 579591c194aSGuido van Rooij memset(iftot, 0, sizeof(struct iftot)); 580591c194aSGuido van Rooij 5810b87c915SDavid Greenman interesting = NULL; 5820b87c915SDavid Greenman interesting_off = 0; 5839b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off;) { 5849bf40edeSBrooks Davis char name[IFNAMSIZ]; 5859b50d902SRodney W. Grimes 5869b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) 5879b50d902SRodney W. Grimes break; 5889bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 5890b87c915SDavid Greenman if (interface && strcmp(name, interface) == 0) { 5909b50d902SRodney W. Grimes interesting = ip; 5910b87c915SDavid Greenman interesting_off = off; 5920b87c915SDavid Greenman } 593ec3b72e9SRobert Drehmel snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);; 594591c194aSGuido van Rooij if ((ipn = malloc(sizeof(struct iftot))) == NULL) { 595591c194aSGuido van Rooij printf("malloc failed\n"); 596591c194aSGuido van Rooij exit(1); 597591c194aSGuido van Rooij } 598591c194aSGuido van Rooij memset(ipn, 0, sizeof(struct iftot)); 5994d51ef63SPoul-Henning Kamp SLIST_NEXT(ip, chain) = ipn; 600591c194aSGuido van Rooij ip = ipn; 6014d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 6029b50d902SRodney W. Grimes } 603c6358a5eSRuslan Ermilov if (interface && interesting == NULL) 604c6358a5eSRuslan Ermilov errx(1, "%s: unknown interface", interface); 605591c194aSGuido van Rooij if ((total = malloc(sizeof(struct iftot))) == NULL) { 606591c194aSGuido van Rooij printf("malloc failed\n"); 607591c194aSGuido van Rooij exit(1); 608591c194aSGuido van Rooij } 609591c194aSGuido van Rooij memset(total, 0, sizeof(struct iftot)); 610591c194aSGuido van Rooij if ((sum = malloc(sizeof(struct iftot))) == NULL) { 611591c194aSGuido van Rooij printf("malloc failed\n"); 612591c194aSGuido van Rooij exit(1); 613591c194aSGuido van Rooij } 614591c194aSGuido van Rooij memset(sum, 0, sizeof(struct iftot)); 615591c194aSGuido van Rooij 6169b50d902SRodney W. Grimes (void)signal(SIGALRM, catchalarm); 6179b50d902SRodney W. Grimes signalled = NO; 618a01e3379SDavid Malone (void)alarm(interval1); 6190b87c915SDavid Greenman first = 1; 6200b87c915SDavid Greenman banner: 6210b87c915SDavid Greenman printf("%17s %14s %16s", "input", 6220b87c915SDavid Greenman interesting ? interesting->ift_name : "(Total)", "output"); 6239b50d902SRodney W. Grimes putchar('\n'); 6240b87c915SDavid Greenman printf("%10s %5s %10s %10s %5s %10s %5s", 6250b87c915SDavid Greenman "packets", "errs", "bytes", "packets", "errs", "bytes", "colls"); 6269b50d902SRodney W. Grimes if (dflag) 6279b50d902SRodney W. Grimes printf(" %5.5s", "drops"); 6289b50d902SRodney W. Grimes putchar('\n'); 6299b50d902SRodney W. Grimes fflush(stdout); 6309b50d902SRodney W. Grimes line = 0; 6319b50d902SRodney W. Grimes loop: 6320b87c915SDavid Greenman if (interesting != NULL) { 6330b87c915SDavid Greenman ip = interesting; 6340b87c915SDavid Greenman if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) { 6350b87c915SDavid Greenman printf("???\n"); 6360b87c915SDavid Greenman exit(1); 6370b87c915SDavid Greenman }; 6380b87c915SDavid Greenman if (!first) { 6397c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1); 6407c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1); 6417c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1); 6427c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1); 6437c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1); 6447c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1); 6457c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_collisions - ip->ift_co, 1); 6460b87c915SDavid Greenman if (dflag) 6477c23a867SGleb Smirnoff show_stat("u", 5, 6487c23a867SGleb Smirnoff ifnet.if_snd.ifq_drops - ip->ift_dr, 1); 6490b87c915SDavid Greenman } 6500b87c915SDavid Greenman ip->ift_ip = ifnet.if_ipackets; 6510b87c915SDavid Greenman ip->ift_ie = ifnet.if_ierrors; 6520b87c915SDavid Greenman ip->ift_ib = ifnet.if_ibytes; 6530b87c915SDavid Greenman ip->ift_op = ifnet.if_opackets; 6540b87c915SDavid Greenman ip->ift_oe = ifnet.if_oerrors; 6550b87c915SDavid Greenman ip->ift_ob = ifnet.if_obytes; 6560b87c915SDavid Greenman ip->ift_co = ifnet.if_collisions; 6570b87c915SDavid Greenman ip->ift_dr = ifnet.if_snd.ifq_drops; 6580b87c915SDavid Greenman } else { 6599b50d902SRodney W. Grimes sum->ift_ip = 0; 6609b50d902SRodney W. Grimes sum->ift_ie = 0; 6610b87c915SDavid Greenman sum->ift_ib = 0; 6629b50d902SRodney W. Grimes sum->ift_op = 0; 6639b50d902SRodney W. Grimes sum->ift_oe = 0; 6640b87c915SDavid Greenman sum->ift_ob = 0; 6659b50d902SRodney W. Grimes sum->ift_co = 0; 6669b50d902SRodney W. Grimes sum->ift_dr = 0; 6674d51ef63SPoul-Henning Kamp for (off = firstifnet, ip = iftot; 6684d51ef63SPoul-Henning Kamp off && SLIST_NEXT(ip, chain) != NULL; 6694d51ef63SPoul-Henning Kamp ip = SLIST_NEXT(ip, chain)) { 6709b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) { 6719b50d902SRodney W. Grimes off = 0; 6729b50d902SRodney W. Grimes continue; 6739b50d902SRodney W. Grimes } 6740b87c915SDavid Greenman sum->ift_ip += ifnet.if_ipackets; 6750b87c915SDavid Greenman sum->ift_ie += ifnet.if_ierrors; 6760b87c915SDavid Greenman sum->ift_ib += ifnet.if_ibytes; 6770b87c915SDavid Greenman sum->ift_op += ifnet.if_opackets; 6780b87c915SDavid Greenman sum->ift_oe += ifnet.if_oerrors; 6790b87c915SDavid Greenman sum->ift_ob += ifnet.if_obytes; 6800b87c915SDavid Greenman sum->ift_co += ifnet.if_collisions; 6810b87c915SDavid Greenman sum->ift_dr += ifnet.if_snd.ifq_drops; 6824d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 6839b50d902SRodney W. Grimes } 6840b87c915SDavid Greenman if (!first) { 6857c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1); 6867c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1); 6877c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1); 6887c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_op - total->ift_op, 1); 6897c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1); 6907c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1); 6917c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_co - total->ift_co, 1); 6929b50d902SRodney W. Grimes if (dflag) 6937c23a867SGleb Smirnoff show_stat("u", 5, 6947c23a867SGleb Smirnoff sum->ift_dr - total->ift_dr, 1); 6959b50d902SRodney W. Grimes } 6969b50d902SRodney W. Grimes *total = *sum; 6970b87c915SDavid Greenman } 6980b87c915SDavid Greenman if (!first) 6999b50d902SRodney W. Grimes putchar('\n'); 7009b50d902SRodney W. Grimes fflush(stdout); 7019b50d902SRodney W. Grimes oldmask = sigblock(sigmask(SIGALRM)); 7029b50d902SRodney W. Grimes if (! signalled) { 7039b50d902SRodney W. Grimes sigpause(0); 7049b50d902SRodney W. Grimes } 7059b50d902SRodney W. Grimes sigsetmask(oldmask); 7069b50d902SRodney W. Grimes signalled = NO; 707a01e3379SDavid Malone (void)alarm(interval1); 7080b87c915SDavid Greenman line++; 7090b87c915SDavid Greenman first = 0; 7109b50d902SRodney W. Grimes if (line == 21) 7119b50d902SRodney W. Grimes goto banner; 7120b87c915SDavid Greenman else 7139b50d902SRodney W. Grimes goto loop; 7149b50d902SRodney W. Grimes /*NOTREACHED*/ 7159b50d902SRodney W. Grimes } 7169b50d902SRodney W. Grimes 7179b50d902SRodney W. Grimes /* 7189b50d902SRodney W. Grimes * Called if an interval expires before sidewaysintpr has completed a loop. 7199b50d902SRodney W. Grimes * Sets a flag to not wait for the alarm. 7209b50d902SRodney W. Grimes */ 7219b50d902SRodney W. Grimes static void 722f964d60dSAssar Westerlund catchalarm(int signo __unused) 7239b50d902SRodney W. Grimes { 7249b50d902SRodney W. Grimes signalled = YES; 7259b50d902SRodney W. Grimes } 726