165475bc8SDavid E. O'Brien /*- 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; 201d72dc9a7SAttilio Rao u_long idrops; 2025da9f8faSJosef Karthauser u_long collisions; 2035da9f8faSJosef Karthauser short timer; 2045da9f8faSJosef Karthauser int drops; 205a97a9922SJulian Elischer struct sockaddr *sa = NULL; 2069bf40edeSBrooks Davis char name[IFNAMSIZ]; 207445f17bbSJosef Karthauser short network_layer; 208445f17bbSJosef Karthauser short link_layer; 2099b50d902SRodney W. Grimes 2109b50d902SRodney W. Grimes if (ifnetaddr == 0) { 2119b50d902SRodney W. Grimes printf("ifnet: symbol not defined\n"); 2129b50d902SRodney W. Grimes return; 2139b50d902SRodney W. Grimes } 214b6c86f4bSBruce Evans if (interval1) { 215b6c86f4bSBruce Evans sidewaysintpr(interval1, ifnetaddr); 2169b50d902SRodney W. Grimes return; 2179b50d902SRodney W. Grimes } 21865475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead) != 0) 2199b50d902SRodney W. Grimes return; 2204d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); 22165475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) != 0) 2220e27dc05SGarrett Wollman return; 2230e27dc05SGarrett Wollman 224cf5e44f8SRuslan Ermilov if (!pfunc) { 22525d295e1SBruce M Simpson if (Wflag) 22625d295e1SBruce M Simpson printf("%-7.7s", "Name"); 22725d295e1SBruce M Simpson else 22825d295e1SBruce M Simpson printf("%-5.5s", "Name"); 229d72dc9a7SAttilio Rao printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s", 230d72dc9a7SAttilio Rao "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); 231e1e293a5SDavid Greenman if (bflag) 232e1e293a5SDavid Greenman printf(" %10.10s","Ibytes"); 233e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 234e1e293a5SDavid Greenman if (bflag) 235e1e293a5SDavid Greenman printf(" %10.10s","Obytes"); 2369b50d902SRodney W. Grimes printf(" %5s", "Coll"); 2379b50d902SRodney W. Grimes if (tflag) 2389b50d902SRodney W. Grimes printf(" %s", "Time"); 2399b50d902SRodney W. Grimes if (dflag) 2409b50d902SRodney W. Grimes printf(" %s", "Drop"); 2419b50d902SRodney W. Grimes putchar('\n'); 242cfa1ca9dSYoshinobu Inoue } 2439b50d902SRodney W. Grimes ifaddraddr = 0; 2449b50d902SRodney W. Grimes while (ifnetaddr || ifaddraddr) { 2456cc6f122SPhilippe Charnier struct sockaddr_in *sockin; 246cfa1ca9dSYoshinobu Inoue #ifdef INET6 2476cc6f122SPhilippe Charnier struct sockaddr_in6 *sockin6; 248cfa1ca9dSYoshinobu Inoue #endif 249a01e3379SDavid Malone char *cp; 2509b50d902SRodney W. Grimes int n, m; 2519b50d902SRodney W. Grimes 252445f17bbSJosef Karthauser network_layer = 0; 253445f17bbSJosef Karthauser link_layer = 0; 254445f17bbSJosef Karthauser 2559b50d902SRodney W. Grimes if (ifaddraddr == 0) { 256f6719675SBill Fenner ifnetfound = ifnetaddr; 25765475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) != 0) 2589b50d902SRodney W. Grimes return; 2599bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 2604d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); 26165475bc8SDavid E. O'Brien if (interface != 0 && strcmp(name, interface) != 0) 2629b50d902SRodney W. Grimes continue; 2639b50d902SRodney W. Grimes cp = index(name, '\0'); 264cfa1ca9dSYoshinobu Inoue 265cfa1ca9dSYoshinobu Inoue if (pfunc) { 266cfa1ca9dSYoshinobu Inoue (*pfunc)(name); 267cfa1ca9dSYoshinobu Inoue continue; 268cfa1ca9dSYoshinobu Inoue } 269cfa1ca9dSYoshinobu Inoue 2709b50d902SRodney W. Grimes if ((ifnet.if_flags&IFF_UP) == 0) 2719b50d902SRodney W. Grimes *cp++ = '*'; 2729b50d902SRodney W. Grimes *cp = '\0'; 2734d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); 2749b50d902SRodney W. Grimes } 275f6719675SBill Fenner ifaddrfound = ifaddraddr; 2765da9f8faSJosef Karthauser 2775da9f8faSJosef Karthauser /* 2785da9f8faSJosef Karthauser * Get the interface stats. These may get 2795da9f8faSJosef Karthauser * overriden below on a per-interface basis. 2805da9f8faSJosef Karthauser */ 2815da9f8faSJosef Karthauser opackets = ifnet.if_opackets; 2825da9f8faSJosef Karthauser ipackets = ifnet.if_ipackets; 2835da9f8faSJosef Karthauser obytes = ifnet.if_obytes; 2845da9f8faSJosef Karthauser ibytes = ifnet.if_ibytes; 285e1655201SRuslan Ermilov omcasts = ifnet.if_omcasts; 286e1655201SRuslan Ermilov imcasts = ifnet.if_imcasts; 2875da9f8faSJosef Karthauser oerrors = ifnet.if_oerrors; 2885da9f8faSJosef Karthauser ierrors = ifnet.if_ierrors; 289d72dc9a7SAttilio Rao idrops = ifnet.if_iqdrops; 2905da9f8faSJosef Karthauser collisions = ifnet.if_collisions; 2915da9f8faSJosef Karthauser timer = ifnet.if_timer; 2925da9f8faSJosef Karthauser drops = ifnet.if_snd.ifq_drops; 2935da9f8faSJosef Karthauser 2949b50d902SRodney W. Grimes if (ifaddraddr == 0) { 29525d295e1SBruce M Simpson if (Wflag) 29625d295e1SBruce M Simpson printf("%-7.7s", name); 29725d295e1SBruce M Simpson else 29825d295e1SBruce M Simpson printf("%-5.5s", name); 29925d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 300acb60e59SRuslan Ermilov printf("%-13.13s ", "none"); 301dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", "none"); 3029b50d902SRodney W. Grimes } else { 30365475bc8SDavid E. O'Brien if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr) 30465475bc8SDavid E. O'Brien != 0) { 3059b50d902SRodney W. Grimes ifaddraddr = 0; 3069b50d902SRodney W. Grimes continue; 3079b50d902SRodney W. Grimes } 3089b50d902SRodney W. Grimes #define CP(x) ((char *)(x)) 3099b50d902SRodney W. Grimes cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 310a97a9922SJulian Elischer CP(&ifaddr); 311a97a9922SJulian Elischer sa = (struct sockaddr *)cp; 312d44ddba9SRuslan Ermilov if (af != AF_UNSPEC && sa->sa_family != af) { 313d44ddba9SRuslan Ermilov ifaddraddr = 314d44ddba9SRuslan Ermilov (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 315d44ddba9SRuslan Ermilov continue; 316d44ddba9SRuslan Ermilov } 31725d295e1SBruce M Simpson if (Wflag) 31825d295e1SBruce M Simpson printf("%-7.7s", name); 31925d295e1SBruce M Simpson else 32025d295e1SBruce M Simpson printf("%-5.5s", name); 32125d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 3229b50d902SRodney W. Grimes switch (sa->sa_family) { 3239b50d902SRodney W. Grimes case AF_UNSPEC: 324cc6a66f2SJulian Elischer printf("%-13.13s ", "none"); 3259b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 3269b50d902SRodney W. Grimes break; 3279b50d902SRodney W. Grimes case AF_INET: 3286cc6f122SPhilippe Charnier sockin = (struct sockaddr_in *)sa; 3299b50d902SRodney W. Grimes #ifdef notdef 3309b50d902SRodney W. Grimes /* can't use inet_makeaddr because kernel 3319b50d902SRodney W. Grimes * keeps nets unshifted. 3329b50d902SRodney W. Grimes */ 3339b50d902SRodney W. Grimes in = inet_makeaddr(ifaddr.in.ia_subnet, 3349b50d902SRodney W. Grimes INADDR_ANY); 33509a67ffaSStefan Eßer printf("%-13.13s ", netname(in.s_addr, 3369b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3379b50d902SRodney W. Grimes #else 338acb60e59SRuslan Ermilov printf("%-13.13s ", 3399b50d902SRodney W. Grimes netname(htonl(ifaddr.in.ia_subnet), 3409b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3419b50d902SRodney W. Grimes #endif 342dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", 3436cc6f122SPhilippe Charnier routename(sockin->sin_addr.s_addr)); 344445f17bbSJosef Karthauser 345445f17bbSJosef Karthauser network_layer = 1; 3469b50d902SRodney W. Grimes break; 347cfa1ca9dSYoshinobu Inoue #ifdef INET6 348cfa1ca9dSYoshinobu Inoue case AF_INET6: 3496cc6f122SPhilippe Charnier sockin6 = (struct sockaddr_in6 *)sa; 350acb60e59SRuslan Ermilov printf("%-13.13s ", 351cfa1ca9dSYoshinobu Inoue netname6(&ifaddr.in6.ia_addr, 352cfa1ca9dSYoshinobu Inoue &ifaddr.in6.ia_prefixmask.sin6_addr)); 353cfa1ca9dSYoshinobu Inoue printf("%-17.17s ", 354a01e3379SDavid Malone inet_ntop(AF_INET6, 3556cc6f122SPhilippe Charnier &sockin6->sin6_addr, 356cfa1ca9dSYoshinobu Inoue ntop_buf, sizeof(ntop_buf))); 357445f17bbSJosef Karthauser 358445f17bbSJosef Karthauser network_layer = 1; 359cfa1ca9dSYoshinobu Inoue break; 360cfa1ca9dSYoshinobu Inoue #endif /*INET6*/ 361cc6a66f2SJulian Elischer case AF_IPX: 362cc6a66f2SJulian Elischer { 363cc6a66f2SJulian Elischer struct sockaddr_ipx *sipx = 364cc6a66f2SJulian Elischer (struct sockaddr_ipx *)sa; 365cc6a66f2SJulian Elischer u_long net; 366cc6a66f2SJulian Elischer char netnum[10]; 367cc6a66f2SJulian Elischer 368cc6a66f2SJulian Elischer *(union ipx_net *) &net = sipx->sipx_addr.x_net; 36922694ebaSBruce Evans sprintf(netnum, "%lx", (u_long)ntohl(net)); 370cc6a66f2SJulian Elischer printf("ipx:%-8s ", netnum); 371cc6a66f2SJulian Elischer /* printf("ipx:%-8s ", netname(net, 0L)); */ 372acb60e59SRuslan Ermilov printf("%-17s ", 373cc6a66f2SJulian Elischer ipx_phost((struct sockaddr *)sipx)); 374cc6a66f2SJulian Elischer } 3756f9cdfceSMatthew N. Dodd 3766f9cdfceSMatthew N. Dodd network_layer = 1; 377cc6a66f2SJulian Elischer break; 3786ffcfd6cSJulian Elischer 3796ffcfd6cSJulian Elischer case AF_APPLETALK: 380a8d37845SJulian Elischer printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); 381acb60e59SRuslan Ermilov printf("%-11.11s ",atalk_print(sa,0x0b) ); 3826ffcfd6cSJulian Elischer break; 3839b50d902SRodney W. Grimes case AF_LINK: 3849b50d902SRodney W. Grimes { 3859b50d902SRodney W. Grimes struct sockaddr_dl *sdl = 3869b50d902SRodney W. Grimes (struct sockaddr_dl *)sa; 387cfa1ca9dSYoshinobu Inoue char linknum[10]; 3889b50d902SRodney W. Grimes cp = (char *)LLADDR(sdl); 3899b50d902SRodney W. Grimes n = sdl->sdl_alen; 390cfa1ca9dSYoshinobu Inoue sprintf(linknum, "<Link#%d>", sdl->sdl_index); 391acb60e59SRuslan Ermilov m = printf("%-13.13s ", linknum); 3929b50d902SRodney W. Grimes } 3939b50d902SRodney W. Grimes goto hexprint; 3949b50d902SRodney W. Grimes default: 3959b50d902SRodney W. Grimes m = printf("(%d)", sa->sa_family); 3969b50d902SRodney W. Grimes for (cp = sa->sa_len + (char *)sa; 3979b50d902SRodney W. Grimes --cp > sa->sa_data && (*cp == 0);) {} 3989b50d902SRodney W. Grimes n = cp - sa->sa_data + 1; 3999b50d902SRodney W. Grimes cp = sa->sa_data; 4009b50d902SRodney W. Grimes hexprint: 4019b50d902SRodney W. Grimes while (--n >= 0) 402541f2562SDavid Greenman m += printf("%02x%c", *cp++ & 0xff, 403e54ca68cSJordan K. Hubbard n > 0 ? ':' : ' '); 404acb60e59SRuslan Ermilov m = 32 - m; 4059b50d902SRodney W. Grimes while (m-- > 0) 4069b50d902SRodney W. Grimes putchar(' '); 407445f17bbSJosef Karthauser 408445f17bbSJosef Karthauser link_layer = 1; 4099b50d902SRodney W. Grimes break; 4109b50d902SRodney W. Grimes } 4115da9f8faSJosef Karthauser 4125da9f8faSJosef Karthauser /* 4135da9f8faSJosef Karthauser * Fixup the statistics for interfaces that 4145da9f8faSJosef Karthauser * update stats for their network addresses 4155da9f8faSJosef Karthauser */ 416445f17bbSJosef Karthauser if (network_layer) { 4175da9f8faSJosef Karthauser opackets = ifaddr.in.ia_ifa.if_opackets; 4185da9f8faSJosef Karthauser ipackets = ifaddr.in.ia_ifa.if_ipackets; 4195da9f8faSJosef Karthauser obytes = ifaddr.in.ia_ifa.if_obytes; 4205da9f8faSJosef Karthauser ibytes = ifaddr.in.ia_ifa.if_ibytes; 4215da9f8faSJosef Karthauser } 4225da9f8faSJosef Karthauser 4234d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 4249b50d902SRodney W. Grimes } 4255da9f8faSJosef Karthauser 426445f17bbSJosef Karthauser show_stat("lu", 8, ipackets, link_layer|network_layer); 427445f17bbSJosef Karthauser show_stat("lu", 5, ierrors, link_layer); 428d72dc9a7SAttilio Rao show_stat("lu", 5, idrops, link_layer); 4297c23a867SGleb Smirnoff if (bflag) 430445f17bbSJosef Karthauser show_stat("lu", 10, ibytes, link_layer|network_layer); 4317c23a867SGleb Smirnoff 432445f17bbSJosef Karthauser show_stat("lu", 8, opackets, link_layer|network_layer); 433445f17bbSJosef Karthauser show_stat("lu", 5, oerrors, link_layer); 4347c23a867SGleb Smirnoff if (bflag) 435445f17bbSJosef Karthauser show_stat("lu", 10, obytes, link_layer|network_layer); 4367c23a867SGleb Smirnoff 4371f575ce8SBruce Evans show_stat("NRSlu", 5, collisions, link_layer); 4387c23a867SGleb Smirnoff if (tflag) 4391f575ce8SBruce Evans show_stat("LSd", 4, timer, link_layer); 4407c23a867SGleb Smirnoff if (dflag) 4411f575ce8SBruce Evans show_stat("LSd", 4, drops, link_layer); 4429b50d902SRodney W. Grimes putchar('\n'); 4431f575ce8SBruce Evans 444f6719675SBill Fenner if (aflag && ifaddrfound) { 445f6719675SBill Fenner /* 446f6719675SBill Fenner * Print family's multicast addresses 447f6719675SBill Fenner */ 4484d51ef63SPoul-Henning Kamp struct ifmultiaddr *multiaddr; 44975fb8770SGarrett Wollman struct ifmultiaddr ifma; 45075fb8770SGarrett Wollman union { 45175fb8770SGarrett Wollman struct sockaddr sa; 45275fb8770SGarrett Wollman struct sockaddr_in in; 453cfa1ca9dSYoshinobu Inoue #ifdef INET6 454cfa1ca9dSYoshinobu Inoue struct sockaddr_in6 in6; 455cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 45675fb8770SGarrett Wollman struct sockaddr_dl dl; 45775fb8770SGarrett Wollman } msa; 45875fb8770SGarrett Wollman const char *fmt; 459f6719675SBill Fenner 4606817526dSPoul-Henning Kamp TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) { 4610b23654bSPoul-Henning Kamp if (kread((u_long)multiaddr, (char *)&ifma, 46265475bc8SDavid E. O'Brien sizeof ifma) != 0) 463f6719675SBill Fenner break; 4640b23654bSPoul-Henning Kamp multiaddr = &ifma; 46575fb8770SGarrett Wollman if (kread((u_long)ifma.ifma_addr, (char *)&msa, 46665475bc8SDavid E. O'Brien sizeof msa) != 0) 46775fb8770SGarrett Wollman break; 46875fb8770SGarrett Wollman if (msa.sa.sa_family != sa->sa_family) 46975fb8770SGarrett Wollman continue; 47075fb8770SGarrett Wollman 47175fb8770SGarrett Wollman fmt = 0; 47275fb8770SGarrett Wollman switch (msa.sa.sa_family) { 47375fb8770SGarrett Wollman case AF_INET: 47475fb8770SGarrett Wollman fmt = routename(msa.in.sin_addr.s_addr); 47575fb8770SGarrett Wollman break; 476cfa1ca9dSYoshinobu Inoue #ifdef INET6 477cfa1ca9dSYoshinobu Inoue case AF_INET6: 478bce2e7c8SRuslan Ermilov printf("%*s %-19.19s(refs: %d)\n", 479bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", 480cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, 481cfa1ca9dSYoshinobu Inoue &msa.in6.sin6_addr, 482cfa1ca9dSYoshinobu Inoue ntop_buf, 483cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf)), 484cfa1ca9dSYoshinobu Inoue ifma.ifma_refcount); 485b9d92bf5SBill Fenner break; 486cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 487f6719675SBill Fenner case AF_LINK: 488b9d92bf5SBill Fenner switch (msa.dl.sdl_type) { 489f6719675SBill Fenner case IFT_ETHER: 49075fb8770SGarrett Wollman case IFT_FDDI: 49175fb8770SGarrett Wollman fmt = ether_ntoa( 49275fb8770SGarrett Wollman (struct ether_addr *) 49375fb8770SGarrett Wollman LLADDR(&msa.dl)); 49475fb8770SGarrett Wollman break; 495f6719675SBill Fenner } 496f6719675SBill Fenner break; 497f6719675SBill Fenner } 498e1655201SRuslan Ermilov if (fmt) { 499e1655201SRuslan Ermilov printf("%*s %-17.17s", 500bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", fmt); 501e1655201SRuslan Ermilov if (msa.sa.sa_family == AF_LINK) { 502e1655201SRuslan Ermilov printf(" %8lu", imcasts); 503e1655201SRuslan Ermilov printf("%*s", 504e1655201SRuslan Ermilov bflag ? 17 : 6, ""); 505e1655201SRuslan Ermilov printf(" %8lu", omcasts); 506e1655201SRuslan Ermilov } 507e1655201SRuslan Ermilov putchar('\n'); 508e1655201SRuslan Ermilov } 509f6719675SBill Fenner } 510f6719675SBill Fenner } 5119b50d902SRodney W. Grimes } 5129b50d902SRodney W. Grimes } 5139b50d902SRodney W. Grimes 5149b50d902SRodney W. Grimes struct iftot { 5154d51ef63SPoul-Henning Kamp SLIST_ENTRY(iftot) chain; 5169bf40edeSBrooks Davis char ift_name[IFNAMSIZ]; /* interface name */ 517890bc2a5SDoug Rabson u_long ift_ip; /* input packets */ 518890bc2a5SDoug Rabson u_long ift_ie; /* input errors */ 519d72dc9a7SAttilio Rao u_long ift_id; /* input drops */ 520890bc2a5SDoug Rabson u_long ift_op; /* output packets */ 521890bc2a5SDoug Rabson u_long ift_oe; /* output errors */ 522890bc2a5SDoug Rabson u_long ift_co; /* collisions */ 523e1e293a5SDavid Greenman u_int ift_dr; /* drops */ 524890bc2a5SDoug Rabson u_long ift_ib; /* input bytes */ 525890bc2a5SDoug Rabson u_long ift_ob; /* output bytes */ 526591c194aSGuido van Rooij }; 5279b50d902SRodney W. Grimes 5289b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 5299b50d902SRodney W. Grimes 5309b50d902SRodney W. Grimes /* 5319b50d902SRodney W. Grimes * Print a running summary of interface statistics. 532b6c86f4bSBruce Evans * Repeat display every interval1 seconds, showing statistics 533b6c86f4bSBruce Evans * collected over that interval. Assumes that interval1 is non-zero. 5349b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 5350e27dc05SGarrett Wollman * XXX - should be rewritten to use ifmib(4). 5369b50d902SRodney W. Grimes */ 5379b50d902SRodney W. Grimes static void 538b6c86f4bSBruce Evans sidewaysintpr(int interval1, u_long off) 5399b50d902SRodney W. Grimes { 5409b50d902SRodney W. Grimes struct ifnet ifnet; 5419b50d902SRodney W. Grimes u_long firstifnet; 5420e27dc05SGarrett Wollman struct ifnethead ifnethead; 54393547b07SBruce Evans struct itimerval interval_it; 544591c194aSGuido van Rooij struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; 545a01e3379SDavid Malone int line; 5460b87c915SDavid Greenman int oldmask, first; 5470b87c915SDavid Greenman u_long interesting_off; 5489b50d902SRodney W. Grimes 54965475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnethead, sizeof ifnethead) != 0) 5509b50d902SRodney W. Grimes return; 5514d51ef63SPoul-Henning Kamp firstifnet = (u_long)TAILQ_FIRST(&ifnethead); 5520e27dc05SGarrett Wollman 553591c194aSGuido van Rooij if ((iftot = malloc(sizeof(struct iftot))) == NULL) { 554591c194aSGuido van Rooij printf("malloc failed\n"); 555591c194aSGuido van Rooij exit(1); 556591c194aSGuido van Rooij } 557591c194aSGuido van Rooij memset(iftot, 0, sizeof(struct iftot)); 558591c194aSGuido van Rooij 5590b87c915SDavid Greenman interesting = NULL; 5600b87c915SDavid Greenman interesting_off = 0; 5619b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off;) { 5629bf40edeSBrooks Davis char name[IFNAMSIZ]; 5639b50d902SRodney W. Grimes 56465475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnet, sizeof ifnet) != 0) 5659b50d902SRodney W. Grimes break; 5669bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 5670b87c915SDavid Greenman if (interface && strcmp(name, interface) == 0) { 5689b50d902SRodney W. Grimes interesting = ip; 5690b87c915SDavid Greenman interesting_off = off; 5700b87c915SDavid Greenman } 571ec3b72e9SRobert Drehmel snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);; 572591c194aSGuido van Rooij if ((ipn = malloc(sizeof(struct iftot))) == NULL) { 573591c194aSGuido van Rooij printf("malloc failed\n"); 574591c194aSGuido van Rooij exit(1); 575591c194aSGuido van Rooij } 576591c194aSGuido van Rooij memset(ipn, 0, sizeof(struct iftot)); 5774d51ef63SPoul-Henning Kamp SLIST_NEXT(ip, chain) = ipn; 578591c194aSGuido van Rooij ip = ipn; 5794d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 5809b50d902SRodney W. Grimes } 581c6358a5eSRuslan Ermilov if (interface && interesting == NULL) 582c6358a5eSRuslan Ermilov errx(1, "%s: unknown interface", interface); 583591c194aSGuido van Rooij if ((total = malloc(sizeof(struct iftot))) == NULL) { 584591c194aSGuido van Rooij printf("malloc failed\n"); 585591c194aSGuido van Rooij exit(1); 586591c194aSGuido van Rooij } 587591c194aSGuido van Rooij memset(total, 0, sizeof(struct iftot)); 588591c194aSGuido van Rooij if ((sum = malloc(sizeof(struct iftot))) == NULL) { 589591c194aSGuido van Rooij printf("malloc failed\n"); 590591c194aSGuido van Rooij exit(1); 591591c194aSGuido van Rooij } 592591c194aSGuido van Rooij memset(sum, 0, sizeof(struct iftot)); 593591c194aSGuido van Rooij 5949b50d902SRodney W. Grimes (void)signal(SIGALRM, catchalarm); 5959b50d902SRodney W. Grimes signalled = NO; 59693547b07SBruce Evans interval_it.it_interval.tv_sec = interval1; 59793547b07SBruce Evans interval_it.it_interval.tv_usec = 0; 59893547b07SBruce Evans interval_it.it_value = interval_it.it_interval; 59993547b07SBruce Evans setitimer(ITIMER_REAL, &interval_it, NULL); 6000b87c915SDavid Greenman first = 1; 6010b87c915SDavid Greenman banner: 6020b87c915SDavid Greenman printf("%17s %14s %16s", "input", 6030b87c915SDavid Greenman interesting ? interesting->ift_name : "(Total)", "output"); 6049b50d902SRodney W. Grimes putchar('\n'); 605d72dc9a7SAttilio Rao printf("%10s %5s %5s %10s %10s %5s %10s %5s", 606d72dc9a7SAttilio Rao "packets", "errs", "idrops", "bytes", "packets", "errs", "bytes", 607d72dc9a7SAttilio Rao "colls"); 6089b50d902SRodney W. Grimes if (dflag) 6099b50d902SRodney W. Grimes printf(" %5.5s", "drops"); 6109b50d902SRodney W. Grimes putchar('\n'); 6119b50d902SRodney W. Grimes fflush(stdout); 6129b50d902SRodney W. Grimes line = 0; 6139b50d902SRodney W. Grimes loop: 6140b87c915SDavid Greenman if (interesting != NULL) { 6150b87c915SDavid Greenman ip = interesting; 61665475bc8SDavid E. O'Brien if (kread(interesting_off, (char *)&ifnet, sizeof ifnet) != 0) { 6170b87c915SDavid Greenman printf("???\n"); 6180b87c915SDavid Greenman exit(1); 6190b87c915SDavid Greenman }; 6200b87c915SDavid Greenman if (!first) { 6217c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1); 6227c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1); 623d72dc9a7SAttilio Rao show_stat("lu", 5, ifnet.if_iqdrops - ip->ift_id, 1); 6247c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1); 6257c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1); 6267c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1); 6277c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1); 6281f575ce8SBruce Evans show_stat("NRSlu", 5, 6291f575ce8SBruce Evans ifnet.if_collisions - ip->ift_co, 1); 6300b87c915SDavid Greenman if (dflag) 6311f575ce8SBruce Evans show_stat("LSu", 5, 6327c23a867SGleb Smirnoff ifnet.if_snd.ifq_drops - ip->ift_dr, 1); 6330b87c915SDavid Greenman } 6340b87c915SDavid Greenman ip->ift_ip = ifnet.if_ipackets; 6350b87c915SDavid Greenman ip->ift_ie = ifnet.if_ierrors; 6360b87c915SDavid Greenman ip->ift_ib = ifnet.if_ibytes; 6370b87c915SDavid Greenman ip->ift_op = ifnet.if_opackets; 6380b87c915SDavid Greenman ip->ift_oe = ifnet.if_oerrors; 6390b87c915SDavid Greenman ip->ift_ob = ifnet.if_obytes; 6400b87c915SDavid Greenman ip->ift_co = ifnet.if_collisions; 6410b87c915SDavid Greenman ip->ift_dr = ifnet.if_snd.ifq_drops; 6420b87c915SDavid Greenman } else { 6439b50d902SRodney W. Grimes sum->ift_ip = 0; 6449b50d902SRodney W. Grimes sum->ift_ie = 0; 645d72dc9a7SAttilio Rao sum->ift_id = 0; 6460b87c915SDavid Greenman sum->ift_ib = 0; 6479b50d902SRodney W. Grimes sum->ift_op = 0; 6489b50d902SRodney W. Grimes sum->ift_oe = 0; 6490b87c915SDavid Greenman sum->ift_ob = 0; 6509b50d902SRodney W. Grimes sum->ift_co = 0; 6519b50d902SRodney W. Grimes sum->ift_dr = 0; 6524d51ef63SPoul-Henning Kamp for (off = firstifnet, ip = iftot; 6534d51ef63SPoul-Henning Kamp off && SLIST_NEXT(ip, chain) != NULL; 6544d51ef63SPoul-Henning Kamp ip = SLIST_NEXT(ip, chain)) { 65565475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnet, sizeof ifnet) != 0) { 6569b50d902SRodney W. Grimes off = 0; 6579b50d902SRodney W. Grimes continue; 6589b50d902SRodney W. Grimes } 6590b87c915SDavid Greenman sum->ift_ip += ifnet.if_ipackets; 6600b87c915SDavid Greenman sum->ift_ie += ifnet.if_ierrors; 661d72dc9a7SAttilio Rao sum->ift_id += ifnet.if_iqdrops; 6620b87c915SDavid Greenman sum->ift_ib += ifnet.if_ibytes; 6630b87c915SDavid Greenman sum->ift_op += ifnet.if_opackets; 6640b87c915SDavid Greenman sum->ift_oe += ifnet.if_oerrors; 6650b87c915SDavid Greenman sum->ift_ob += ifnet.if_obytes; 6660b87c915SDavid Greenman sum->ift_co += ifnet.if_collisions; 6670b87c915SDavid Greenman sum->ift_dr += ifnet.if_snd.ifq_drops; 6684d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 6699b50d902SRodney W. Grimes } 6700b87c915SDavid Greenman if (!first) { 6717c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1); 6727c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1); 673d72dc9a7SAttilio Rao show_stat("lu", 5, sum->ift_id - total->ift_id, 1); 6747c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1); 6757c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_op - total->ift_op, 1); 6767c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1); 6777c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1); 6781f575ce8SBruce Evans show_stat("NRSlu", 5, sum->ift_co - total->ift_co, 1); 6799b50d902SRodney W. Grimes if (dflag) 6801f575ce8SBruce Evans show_stat("LSu", 5, 6817c23a867SGleb Smirnoff sum->ift_dr - total->ift_dr, 1); 6829b50d902SRodney W. Grimes } 6839b50d902SRodney W. Grimes *total = *sum; 6840b87c915SDavid Greenman } 6850b87c915SDavid Greenman if (!first) 6869b50d902SRodney W. Grimes putchar('\n'); 6879b50d902SRodney W. Grimes fflush(stdout); 6889b50d902SRodney W. Grimes oldmask = sigblock(sigmask(SIGALRM)); 68993547b07SBruce Evans while (!signalled) 6909b50d902SRodney W. Grimes sigpause(0); 6919b50d902SRodney W. Grimes signalled = NO; 69293547b07SBruce Evans sigsetmask(oldmask); 6930b87c915SDavid Greenman line++; 6940b87c915SDavid Greenman first = 0; 6959b50d902SRodney W. Grimes if (line == 21) 6969b50d902SRodney W. Grimes goto banner; 6970b87c915SDavid Greenman else 6989b50d902SRodney W. Grimes goto loop; 6999b50d902SRodney W. Grimes /*NOTREACHED*/ 7009b50d902SRodney W. Grimes } 7019b50d902SRodney W. Grimes 7029b50d902SRodney W. Grimes /* 70393547b07SBruce Evans * Set a flag to indicate that a signal from the periodic itimer has been 70493547b07SBruce Evans * caught. 7059b50d902SRodney W. Grimes */ 7069b50d902SRodney W. Grimes static void 707f964d60dSAssar Westerlund catchalarm(int signo __unused) 7089b50d902SRodney W. Grimes { 7099b50d902SRodney W. Grimes signalled = YES; 7109b50d902SRodney W. Grimes } 711