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> 71821df508SXin LI #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 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 } 21765475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead) != 0) 2189b50d902SRodney W. Grimes return; 2194d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); 22065475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) != 0) 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"); 228d72dc9a7SAttilio Rao printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s", 229d72dc9a7SAttilio Rao "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); 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 (dflag) 2379b50d902SRodney W. Grimes printf(" %s", "Drop"); 2389b50d902SRodney W. Grimes putchar('\n'); 239cfa1ca9dSYoshinobu Inoue } 2409b50d902SRodney W. Grimes ifaddraddr = 0; 2419b50d902SRodney W. Grimes while (ifnetaddr || ifaddraddr) { 2426cc6f122SPhilippe Charnier struct sockaddr_in *sockin; 243cfa1ca9dSYoshinobu Inoue #ifdef INET6 2446cc6f122SPhilippe Charnier struct sockaddr_in6 *sockin6; 245cfa1ca9dSYoshinobu Inoue #endif 246a01e3379SDavid Malone char *cp; 2479b50d902SRodney W. Grimes int n, m; 2489b50d902SRodney W. Grimes 249445f17bbSJosef Karthauser network_layer = 0; 250445f17bbSJosef Karthauser link_layer = 0; 251445f17bbSJosef Karthauser 2529b50d902SRodney W. Grimes if (ifaddraddr == 0) { 253f6719675SBill Fenner ifnetfound = ifnetaddr; 25465475bc8SDavid E. O'Brien if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) != 0) 2559b50d902SRodney W. Grimes return; 2569bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 2574d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); 25865475bc8SDavid E. O'Brien if (interface != 0 && strcmp(name, interface) != 0) 2599b50d902SRodney W. Grimes continue; 2609b50d902SRodney W. Grimes cp = index(name, '\0'); 261cfa1ca9dSYoshinobu Inoue 262cfa1ca9dSYoshinobu Inoue if (pfunc) { 263cfa1ca9dSYoshinobu Inoue (*pfunc)(name); 264cfa1ca9dSYoshinobu Inoue continue; 265cfa1ca9dSYoshinobu Inoue } 266cfa1ca9dSYoshinobu Inoue 2679b50d902SRodney W. Grimes if ((ifnet.if_flags&IFF_UP) == 0) 2689b50d902SRodney W. Grimes *cp++ = '*'; 2699b50d902SRodney W. Grimes *cp = '\0'; 2704d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); 2719b50d902SRodney W. Grimes } 272f6719675SBill Fenner ifaddrfound = ifaddraddr; 2735da9f8faSJosef Karthauser 2745da9f8faSJosef Karthauser /* 2755da9f8faSJosef Karthauser * Get the interface stats. These may get 2765da9f8faSJosef Karthauser * overriden below on a per-interface basis. 2775da9f8faSJosef Karthauser */ 2785da9f8faSJosef Karthauser opackets = ifnet.if_opackets; 2795da9f8faSJosef Karthauser ipackets = ifnet.if_ipackets; 2805da9f8faSJosef Karthauser obytes = ifnet.if_obytes; 2815da9f8faSJosef Karthauser ibytes = ifnet.if_ibytes; 282e1655201SRuslan Ermilov omcasts = ifnet.if_omcasts; 283e1655201SRuslan Ermilov imcasts = ifnet.if_imcasts; 2845da9f8faSJosef Karthauser oerrors = ifnet.if_oerrors; 2855da9f8faSJosef Karthauser ierrors = ifnet.if_ierrors; 286d72dc9a7SAttilio Rao idrops = ifnet.if_iqdrops; 2875da9f8faSJosef Karthauser collisions = ifnet.if_collisions; 2885da9f8faSJosef Karthauser drops = ifnet.if_snd.ifq_drops; 2895da9f8faSJosef Karthauser 2909b50d902SRodney W. Grimes if (ifaddraddr == 0) { 29125d295e1SBruce M Simpson if (Wflag) 29225d295e1SBruce M Simpson printf("%-7.7s", name); 29325d295e1SBruce M Simpson else 29425d295e1SBruce M Simpson printf("%-5.5s", name); 29525d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 296acb60e59SRuslan Ermilov printf("%-13.13s ", "none"); 297dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", "none"); 2989b50d902SRodney W. Grimes } else { 29965475bc8SDavid E. O'Brien if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr) 30065475bc8SDavid E. O'Brien != 0) { 3019b50d902SRodney W. Grimes ifaddraddr = 0; 3029b50d902SRodney W. Grimes continue; 3039b50d902SRodney W. Grimes } 3049b50d902SRodney W. Grimes #define CP(x) ((char *)(x)) 3059b50d902SRodney W. Grimes cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 306a97a9922SJulian Elischer CP(&ifaddr); 307a97a9922SJulian Elischer sa = (struct sockaddr *)cp; 308d44ddba9SRuslan Ermilov if (af != AF_UNSPEC && sa->sa_family != af) { 309d44ddba9SRuslan Ermilov ifaddraddr = 310d44ddba9SRuslan Ermilov (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 311d44ddba9SRuslan Ermilov continue; 312d44ddba9SRuslan Ermilov } 31325d295e1SBruce M Simpson if (Wflag) 31425d295e1SBruce M Simpson printf("%-7.7s", name); 31525d295e1SBruce M Simpson else 31625d295e1SBruce M Simpson printf("%-5.5s", name); 31725d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 3189b50d902SRodney W. Grimes switch (sa->sa_family) { 3199b50d902SRodney W. Grimes case AF_UNSPEC: 320cc6a66f2SJulian Elischer printf("%-13.13s ", "none"); 3219b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 3229b50d902SRodney W. Grimes break; 3239b50d902SRodney W. Grimes case AF_INET: 3246cc6f122SPhilippe Charnier sockin = (struct sockaddr_in *)sa; 3259b50d902SRodney W. Grimes #ifdef notdef 3269b50d902SRodney W. Grimes /* can't use inet_makeaddr because kernel 3279b50d902SRodney W. Grimes * keeps nets unshifted. 3289b50d902SRodney W. Grimes */ 3299b50d902SRodney W. Grimes in = inet_makeaddr(ifaddr.in.ia_subnet, 3309b50d902SRodney W. Grimes INADDR_ANY); 33109a67ffaSStefan Eßer printf("%-13.13s ", netname(in.s_addr, 3329b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3339b50d902SRodney W. Grimes #else 334acb60e59SRuslan Ermilov printf("%-13.13s ", 3359b50d902SRodney W. Grimes netname(htonl(ifaddr.in.ia_subnet), 3369b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3379b50d902SRodney W. Grimes #endif 338dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", 3396cc6f122SPhilippe Charnier routename(sockin->sin_addr.s_addr)); 340445f17bbSJosef Karthauser 341445f17bbSJosef Karthauser network_layer = 1; 3429b50d902SRodney W. Grimes break; 343cfa1ca9dSYoshinobu Inoue #ifdef INET6 344cfa1ca9dSYoshinobu Inoue case AF_INET6: 3456cc6f122SPhilippe Charnier sockin6 = (struct sockaddr_in6 *)sa; 346acb60e59SRuslan Ermilov printf("%-13.13s ", 347cfa1ca9dSYoshinobu Inoue netname6(&ifaddr.in6.ia_addr, 348cfa1ca9dSYoshinobu Inoue &ifaddr.in6.ia_prefixmask.sin6_addr)); 349cfa1ca9dSYoshinobu Inoue printf("%-17.17s ", 350a01e3379SDavid Malone inet_ntop(AF_INET6, 3516cc6f122SPhilippe Charnier &sockin6->sin6_addr, 352cfa1ca9dSYoshinobu Inoue ntop_buf, sizeof(ntop_buf))); 353445f17bbSJosef Karthauser 354445f17bbSJosef Karthauser network_layer = 1; 355cfa1ca9dSYoshinobu Inoue break; 356cfa1ca9dSYoshinobu Inoue #endif /*INET6*/ 357cc6a66f2SJulian Elischer case AF_IPX: 358cc6a66f2SJulian Elischer { 359cc6a66f2SJulian Elischer struct sockaddr_ipx *sipx = 360cc6a66f2SJulian Elischer (struct sockaddr_ipx *)sa; 361cc6a66f2SJulian Elischer u_long net; 362cc6a66f2SJulian Elischer char netnum[10]; 363cc6a66f2SJulian Elischer 364cc6a66f2SJulian Elischer *(union ipx_net *) &net = sipx->sipx_addr.x_net; 36522694ebaSBruce Evans sprintf(netnum, "%lx", (u_long)ntohl(net)); 366cc6a66f2SJulian Elischer printf("ipx:%-8s ", netnum); 367cc6a66f2SJulian Elischer /* printf("ipx:%-8s ", netname(net, 0L)); */ 368acb60e59SRuslan Ermilov printf("%-17s ", 369cc6a66f2SJulian Elischer ipx_phost((struct sockaddr *)sipx)); 370cc6a66f2SJulian Elischer } 3716f9cdfceSMatthew N. Dodd 3726f9cdfceSMatthew N. Dodd network_layer = 1; 373cc6a66f2SJulian Elischer break; 3746ffcfd6cSJulian Elischer 3756ffcfd6cSJulian Elischer case AF_APPLETALK: 376a8d37845SJulian Elischer printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); 377acb60e59SRuslan Ermilov printf("%-11.11s ",atalk_print(sa,0x0b) ); 3786ffcfd6cSJulian Elischer break; 3799b50d902SRodney W. Grimes case AF_LINK: 3809b50d902SRodney W. Grimes { 3819b50d902SRodney W. Grimes struct sockaddr_dl *sdl = 3829b50d902SRodney W. Grimes (struct sockaddr_dl *)sa; 383cfa1ca9dSYoshinobu Inoue char linknum[10]; 3849b50d902SRodney W. Grimes cp = (char *)LLADDR(sdl); 3859b50d902SRodney W. Grimes n = sdl->sdl_alen; 386cfa1ca9dSYoshinobu Inoue sprintf(linknum, "<Link#%d>", sdl->sdl_index); 387acb60e59SRuslan Ermilov m = printf("%-13.13s ", linknum); 3889b50d902SRodney W. Grimes } 3899b50d902SRodney W. Grimes goto hexprint; 3909b50d902SRodney W. Grimes default: 3919b50d902SRodney W. Grimes m = printf("(%d)", sa->sa_family); 3929b50d902SRodney W. Grimes for (cp = sa->sa_len + (char *)sa; 3939b50d902SRodney W. Grimes --cp > sa->sa_data && (*cp == 0);) {} 3949b50d902SRodney W. Grimes n = cp - sa->sa_data + 1; 3959b50d902SRodney W. Grimes cp = sa->sa_data; 3969b50d902SRodney W. Grimes hexprint: 3979b50d902SRodney W. Grimes while (--n >= 0) 398541f2562SDavid Greenman m += printf("%02x%c", *cp++ & 0xff, 399e54ca68cSJordan K. Hubbard n > 0 ? ':' : ' '); 400acb60e59SRuslan Ermilov m = 32 - m; 4019b50d902SRodney W. Grimes while (m-- > 0) 4029b50d902SRodney W. Grimes putchar(' '); 403445f17bbSJosef Karthauser 404445f17bbSJosef Karthauser link_layer = 1; 4059b50d902SRodney W. Grimes break; 4069b50d902SRodney W. Grimes } 4075da9f8faSJosef Karthauser 4085da9f8faSJosef Karthauser /* 4095da9f8faSJosef Karthauser * Fixup the statistics for interfaces that 4105da9f8faSJosef Karthauser * update stats for their network addresses 4115da9f8faSJosef Karthauser */ 412445f17bbSJosef Karthauser if (network_layer) { 4135da9f8faSJosef Karthauser opackets = ifaddr.in.ia_ifa.if_opackets; 4145da9f8faSJosef Karthauser ipackets = ifaddr.in.ia_ifa.if_ipackets; 4155da9f8faSJosef Karthauser obytes = ifaddr.in.ia_ifa.if_obytes; 4165da9f8faSJosef Karthauser ibytes = ifaddr.in.ia_ifa.if_ibytes; 4175da9f8faSJosef Karthauser } 4185da9f8faSJosef Karthauser 4194d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 4209b50d902SRodney W. Grimes } 4215da9f8faSJosef Karthauser 422445f17bbSJosef Karthauser show_stat("lu", 8, ipackets, link_layer|network_layer); 423445f17bbSJosef Karthauser show_stat("lu", 5, ierrors, link_layer); 424d72dc9a7SAttilio Rao show_stat("lu", 5, idrops, 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 (dflag) 4351f575ce8SBruce Evans show_stat("LSd", 4, drops, link_layer); 4369b50d902SRodney W. Grimes putchar('\n'); 4371f575ce8SBruce Evans 438f6719675SBill Fenner if (aflag && ifaddrfound) { 439f6719675SBill Fenner /* 440f6719675SBill Fenner * Print family's multicast addresses 441f6719675SBill Fenner */ 4424d51ef63SPoul-Henning Kamp struct ifmultiaddr *multiaddr; 44375fb8770SGarrett Wollman struct ifmultiaddr ifma; 44475fb8770SGarrett Wollman union { 44575fb8770SGarrett Wollman struct sockaddr sa; 44675fb8770SGarrett Wollman struct sockaddr_in in; 447cfa1ca9dSYoshinobu Inoue #ifdef INET6 448cfa1ca9dSYoshinobu Inoue struct sockaddr_in6 in6; 449cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 45075fb8770SGarrett Wollman struct sockaddr_dl dl; 45175fb8770SGarrett Wollman } msa; 45275fb8770SGarrett Wollman const char *fmt; 453f6719675SBill Fenner 4546817526dSPoul-Henning Kamp TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) { 4550b23654bSPoul-Henning Kamp if (kread((u_long)multiaddr, (char *)&ifma, 45665475bc8SDavid E. O'Brien sizeof ifma) != 0) 457f6719675SBill Fenner break; 4580b23654bSPoul-Henning Kamp multiaddr = &ifma; 45975fb8770SGarrett Wollman if (kread((u_long)ifma.ifma_addr, (char *)&msa, 46065475bc8SDavid E. O'Brien sizeof msa) != 0) 46175fb8770SGarrett Wollman break; 46275fb8770SGarrett Wollman if (msa.sa.sa_family != sa->sa_family) 46375fb8770SGarrett Wollman continue; 46475fb8770SGarrett Wollman 46575fb8770SGarrett Wollman fmt = 0; 46675fb8770SGarrett Wollman switch (msa.sa.sa_family) { 46775fb8770SGarrett Wollman case AF_INET: 46875fb8770SGarrett Wollman fmt = routename(msa.in.sin_addr.s_addr); 46975fb8770SGarrett Wollman break; 470cfa1ca9dSYoshinobu Inoue #ifdef INET6 471cfa1ca9dSYoshinobu Inoue case AF_INET6: 472bce2e7c8SRuslan Ermilov printf("%*s %-19.19s(refs: %d)\n", 473bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", 474cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, 475cfa1ca9dSYoshinobu Inoue &msa.in6.sin6_addr, 476cfa1ca9dSYoshinobu Inoue ntop_buf, 477cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf)), 478cfa1ca9dSYoshinobu Inoue ifma.ifma_refcount); 479b9d92bf5SBill Fenner break; 480cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 481f6719675SBill Fenner case AF_LINK: 482b9d92bf5SBill Fenner switch (msa.dl.sdl_type) { 483f6719675SBill Fenner case IFT_ETHER: 48475fb8770SGarrett Wollman case IFT_FDDI: 48575fb8770SGarrett Wollman fmt = ether_ntoa( 48675fb8770SGarrett Wollman (struct ether_addr *) 48775fb8770SGarrett Wollman LLADDR(&msa.dl)); 48875fb8770SGarrett Wollman break; 489f6719675SBill Fenner } 490f6719675SBill Fenner break; 491f6719675SBill Fenner } 492e1655201SRuslan Ermilov if (fmt) { 493e1655201SRuslan Ermilov printf("%*s %-17.17s", 494bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", fmt); 495e1655201SRuslan Ermilov if (msa.sa.sa_family == AF_LINK) { 496e1655201SRuslan Ermilov printf(" %8lu", imcasts); 497e1655201SRuslan Ermilov printf("%*s", 498e1655201SRuslan Ermilov bflag ? 17 : 6, ""); 499e1655201SRuslan Ermilov printf(" %8lu", omcasts); 500e1655201SRuslan Ermilov } 501e1655201SRuslan Ermilov putchar('\n'); 502e1655201SRuslan Ermilov } 503f6719675SBill Fenner } 504f6719675SBill Fenner } 5059b50d902SRodney W. Grimes } 5069b50d902SRodney W. Grimes } 5079b50d902SRodney W. Grimes 5089b50d902SRodney W. Grimes struct iftot { 5094d51ef63SPoul-Henning Kamp SLIST_ENTRY(iftot) chain; 5109bf40edeSBrooks Davis char ift_name[IFNAMSIZ]; /* interface name */ 511890bc2a5SDoug Rabson u_long ift_ip; /* input packets */ 512890bc2a5SDoug Rabson u_long ift_ie; /* input errors */ 513d72dc9a7SAttilio Rao u_long ift_id; /* input drops */ 514890bc2a5SDoug Rabson u_long ift_op; /* output packets */ 515890bc2a5SDoug Rabson u_long ift_oe; /* output errors */ 516890bc2a5SDoug Rabson u_long ift_co; /* collisions */ 517e1e293a5SDavid Greenman u_int ift_dr; /* drops */ 518890bc2a5SDoug Rabson u_long ift_ib; /* input bytes */ 519890bc2a5SDoug Rabson u_long ift_ob; /* output bytes */ 520591c194aSGuido van Rooij }; 5219b50d902SRodney W. Grimes 5229b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 5239b50d902SRodney W. Grimes 5249b50d902SRodney W. Grimes /* 5259b50d902SRodney W. Grimes * Print a running summary of interface statistics. 526b6c86f4bSBruce Evans * Repeat display every interval1 seconds, showing statistics 527b6c86f4bSBruce Evans * collected over that interval. Assumes that interval1 is non-zero. 5289b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 5290e27dc05SGarrett Wollman * XXX - should be rewritten to use ifmib(4). 5309b50d902SRodney W. Grimes */ 5319b50d902SRodney W. Grimes static void 532b6c86f4bSBruce Evans sidewaysintpr(int interval1, u_long off) 5339b50d902SRodney W. Grimes { 5349b50d902SRodney W. Grimes struct ifnet ifnet; 5359b50d902SRodney W. Grimes u_long firstifnet; 5360e27dc05SGarrett Wollman struct ifnethead ifnethead; 53793547b07SBruce Evans struct itimerval interval_it; 538591c194aSGuido van Rooij struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; 539a01e3379SDavid Malone int line; 5400b87c915SDavid Greenman int oldmask, first; 5410b87c915SDavid Greenman u_long interesting_off; 5429b50d902SRodney W. Grimes 54365475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnethead, sizeof ifnethead) != 0) 5449b50d902SRodney W. Grimes return; 5454d51ef63SPoul-Henning Kamp firstifnet = (u_long)TAILQ_FIRST(&ifnethead); 5460e27dc05SGarrett Wollman 547591c194aSGuido van Rooij if ((iftot = malloc(sizeof(struct iftot))) == NULL) { 548591c194aSGuido van Rooij printf("malloc failed\n"); 549591c194aSGuido van Rooij exit(1); 550591c194aSGuido van Rooij } 551591c194aSGuido van Rooij memset(iftot, 0, sizeof(struct iftot)); 552591c194aSGuido van Rooij 5530b87c915SDavid Greenman interesting = NULL; 5540b87c915SDavid Greenman interesting_off = 0; 5559b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off;) { 5569bf40edeSBrooks Davis char name[IFNAMSIZ]; 5579b50d902SRodney W. Grimes 55865475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnet, sizeof ifnet) != 0) 5599b50d902SRodney W. Grimes break; 5609bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 5610b87c915SDavid Greenman if (interface && strcmp(name, interface) == 0) { 5629b50d902SRodney W. Grimes interesting = ip; 5630b87c915SDavid Greenman interesting_off = off; 5640b87c915SDavid Greenman } 565ec3b72e9SRobert Drehmel snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);; 566591c194aSGuido van Rooij if ((ipn = malloc(sizeof(struct iftot))) == NULL) { 567591c194aSGuido van Rooij printf("malloc failed\n"); 568591c194aSGuido van Rooij exit(1); 569591c194aSGuido van Rooij } 570591c194aSGuido van Rooij memset(ipn, 0, sizeof(struct iftot)); 5714d51ef63SPoul-Henning Kamp SLIST_NEXT(ip, chain) = ipn; 572591c194aSGuido van Rooij ip = ipn; 5734d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 5749b50d902SRodney W. Grimes } 575c6358a5eSRuslan Ermilov if (interface && interesting == NULL) 576c6358a5eSRuslan Ermilov errx(1, "%s: unknown interface", interface); 577591c194aSGuido van Rooij if ((total = malloc(sizeof(struct iftot))) == NULL) { 578591c194aSGuido van Rooij printf("malloc failed\n"); 579591c194aSGuido van Rooij exit(1); 580591c194aSGuido van Rooij } 581591c194aSGuido van Rooij memset(total, 0, sizeof(struct iftot)); 582591c194aSGuido van Rooij if ((sum = malloc(sizeof(struct iftot))) == NULL) { 583591c194aSGuido van Rooij printf("malloc failed\n"); 584591c194aSGuido van Rooij exit(1); 585591c194aSGuido van Rooij } 586591c194aSGuido van Rooij memset(sum, 0, sizeof(struct iftot)); 587591c194aSGuido van Rooij 5889b50d902SRodney W. Grimes (void)signal(SIGALRM, catchalarm); 5899b50d902SRodney W. Grimes signalled = NO; 59093547b07SBruce Evans interval_it.it_interval.tv_sec = interval1; 59193547b07SBruce Evans interval_it.it_interval.tv_usec = 0; 59293547b07SBruce Evans interval_it.it_value = interval_it.it_interval; 59393547b07SBruce Evans setitimer(ITIMER_REAL, &interval_it, NULL); 5940b87c915SDavid Greenman first = 1; 5950b87c915SDavid Greenman banner: 5960b87c915SDavid Greenman printf("%17s %14s %16s", "input", 5970b87c915SDavid Greenman interesting ? interesting->ift_name : "(Total)", "output"); 5989b50d902SRodney W. Grimes putchar('\n'); 599d72dc9a7SAttilio Rao printf("%10s %5s %5s %10s %10s %5s %10s %5s", 600d72dc9a7SAttilio Rao "packets", "errs", "idrops", "bytes", "packets", "errs", "bytes", 601d72dc9a7SAttilio Rao "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; 61065475bc8SDavid E. O'Brien if (kread(interesting_off, (char *)&ifnet, sizeof ifnet) != 0) { 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); 617d72dc9a7SAttilio Rao show_stat("lu", 5, ifnet.if_iqdrops - ip->ift_id, 1); 6187c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1); 6197c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1); 6207c23a867SGleb Smirnoff show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1); 6217c23a867SGleb Smirnoff show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1); 6221f575ce8SBruce Evans show_stat("NRSlu", 5, 6231f575ce8SBruce Evans ifnet.if_collisions - ip->ift_co, 1); 6240b87c915SDavid Greenman if (dflag) 6251f575ce8SBruce Evans show_stat("LSu", 5, 6267c23a867SGleb Smirnoff ifnet.if_snd.ifq_drops - ip->ift_dr, 1); 6270b87c915SDavid Greenman } 6280b87c915SDavid Greenman ip->ift_ip = ifnet.if_ipackets; 6290b87c915SDavid Greenman ip->ift_ie = ifnet.if_ierrors; 6300b87c915SDavid Greenman ip->ift_ib = ifnet.if_ibytes; 6310b87c915SDavid Greenman ip->ift_op = ifnet.if_opackets; 6320b87c915SDavid Greenman ip->ift_oe = ifnet.if_oerrors; 6330b87c915SDavid Greenman ip->ift_ob = ifnet.if_obytes; 6340b87c915SDavid Greenman ip->ift_co = ifnet.if_collisions; 6350b87c915SDavid Greenman ip->ift_dr = ifnet.if_snd.ifq_drops; 6360b87c915SDavid Greenman } else { 6379b50d902SRodney W. Grimes sum->ift_ip = 0; 6389b50d902SRodney W. Grimes sum->ift_ie = 0; 639d72dc9a7SAttilio Rao sum->ift_id = 0; 6400b87c915SDavid Greenman sum->ift_ib = 0; 6419b50d902SRodney W. Grimes sum->ift_op = 0; 6429b50d902SRodney W. Grimes sum->ift_oe = 0; 6430b87c915SDavid Greenman sum->ift_ob = 0; 6449b50d902SRodney W. Grimes sum->ift_co = 0; 6459b50d902SRodney W. Grimes sum->ift_dr = 0; 6464d51ef63SPoul-Henning Kamp for (off = firstifnet, ip = iftot; 6474d51ef63SPoul-Henning Kamp off && SLIST_NEXT(ip, chain) != NULL; 6484d51ef63SPoul-Henning Kamp ip = SLIST_NEXT(ip, chain)) { 64965475bc8SDavid E. O'Brien if (kread(off, (char *)&ifnet, sizeof ifnet) != 0) { 6509b50d902SRodney W. Grimes off = 0; 6519b50d902SRodney W. Grimes continue; 6529b50d902SRodney W. Grimes } 6530b87c915SDavid Greenman sum->ift_ip += ifnet.if_ipackets; 6540b87c915SDavid Greenman sum->ift_ie += ifnet.if_ierrors; 655d72dc9a7SAttilio Rao sum->ift_id += ifnet.if_iqdrops; 6560b87c915SDavid Greenman sum->ift_ib += ifnet.if_ibytes; 6570b87c915SDavid Greenman sum->ift_op += ifnet.if_opackets; 6580b87c915SDavid Greenman sum->ift_oe += ifnet.if_oerrors; 6590b87c915SDavid Greenman sum->ift_ob += ifnet.if_obytes; 6600b87c915SDavid Greenman sum->ift_co += ifnet.if_collisions; 6610b87c915SDavid Greenman sum->ift_dr += ifnet.if_snd.ifq_drops; 6624d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 6639b50d902SRodney W. Grimes } 6640b87c915SDavid Greenman if (!first) { 6657c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1); 6667c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1); 667d72dc9a7SAttilio Rao show_stat("lu", 5, sum->ift_id - total->ift_id, 1); 6687c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1); 6697c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_op - total->ift_op, 1); 6707c23a867SGleb Smirnoff show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1); 6717c23a867SGleb Smirnoff show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1); 6721f575ce8SBruce Evans show_stat("NRSlu", 5, sum->ift_co - total->ift_co, 1); 6739b50d902SRodney W. Grimes if (dflag) 6741f575ce8SBruce Evans show_stat("LSu", 5, 6757c23a867SGleb Smirnoff sum->ift_dr - total->ift_dr, 1); 6769b50d902SRodney W. Grimes } 6779b50d902SRodney W. Grimes *total = *sum; 6780b87c915SDavid Greenman } 6790b87c915SDavid Greenman if (!first) 6809b50d902SRodney W. Grimes putchar('\n'); 6819b50d902SRodney W. Grimes fflush(stdout); 6829b50d902SRodney W. Grimes oldmask = sigblock(sigmask(SIGALRM)); 68393547b07SBruce Evans while (!signalled) 6849b50d902SRodney W. Grimes sigpause(0); 6859b50d902SRodney W. Grimes signalled = NO; 68693547b07SBruce Evans sigsetmask(oldmask); 6870b87c915SDavid Greenman line++; 6880b87c915SDavid Greenman first = 0; 6899b50d902SRodney W. Grimes if (line == 21) 6909b50d902SRodney W. Grimes goto banner; 6910b87c915SDavid Greenman else 6929b50d902SRodney W. Grimes goto loop; 6939b50d902SRodney W. Grimes /*NOTREACHED*/ 6949b50d902SRodney W. Grimes } 6959b50d902SRodney W. Grimes 6969b50d902SRodney W. Grimes /* 69793547b07SBruce Evans * Set a flag to indicate that a signal from the periodic itimer has been 69893547b07SBruce Evans * caught. 6999b50d902SRodney W. Grimes */ 7009b50d902SRodney W. Grimes static void 701f964d60dSAssar Westerlund catchalarm(int signo __unused) 7029b50d902SRodney W. Grimes { 7039b50d902SRodney W. Grimes signalled = YES; 7049b50d902SRodney W. Grimes } 705