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> 659b50d902SRodney W. Grimes #include <signal.h> 669b50d902SRodney W. Grimes #include <stdio.h> 67591c194aSGuido van Rooij #include <stdlib.h> 689b50d902SRodney W. Grimes #include <string.h> 699b50d902SRodney W. Grimes #include <unistd.h> 709b50d902SRodney W. Grimes 719b50d902SRodney W. Grimes #include "netstat.h" 729b50d902SRodney W. Grimes 739b50d902SRodney W. Grimes #define YES 1 749b50d902SRodney W. Grimes #define NO 0 759b50d902SRodney W. Grimes 765e051718SAssar Westerlund static void sidewaysintpr (u_int, u_long); 775e051718SAssar Westerlund static void catchalarm (int); 789b50d902SRodney W. Grimes 79cfa1ca9dSYoshinobu Inoue #ifdef INET6 80cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */ 81cfa1ca9dSYoshinobu Inoue static int bdg_done; 82cfa1ca9dSYoshinobu Inoue #endif 83cfa1ca9dSYoshinobu Inoue 84f964d60dSAssar Westerlund /* print bridge statistics */ 850024d1dbSLuigi Rizzo void 86a01e3379SDavid Malone bdg_stats(u_long dummy __unused, const char *name, int af1 __unused) 870024d1dbSLuigi Rizzo { 88890bc2a5SDoug Rabson int i; 89890bc2a5SDoug Rabson size_t slen ; 900024d1dbSLuigi Rizzo struct bdg_stats s ; 910024d1dbSLuigi Rizzo int mib[4] ; 920024d1dbSLuigi Rizzo 930024d1dbSLuigi Rizzo slen = sizeof(s); 940024d1dbSLuigi Rizzo 950024d1dbSLuigi Rizzo mib[0] = CTL_NET ; 960024d1dbSLuigi Rizzo mib[1] = PF_LINK ; 970024d1dbSLuigi Rizzo mib[2] = IFT_ETHER ; 980024d1dbSLuigi Rizzo mib[3] = PF_BDG ; 990024d1dbSLuigi Rizzo if (sysctl(mib,4, &s,&slen,NULL,0)==-1) 1000024d1dbSLuigi Rizzo return ; /* no bridging */ 101cfa1ca9dSYoshinobu Inoue #ifdef INET6 102cfa1ca9dSYoshinobu Inoue if (bdg_done != 0) 103cfa1ca9dSYoshinobu Inoue return; 104cfa1ca9dSYoshinobu Inoue else 105cfa1ca9dSYoshinobu Inoue bdg_done = 1; 106cfa1ca9dSYoshinobu Inoue #endif 1070024d1dbSLuigi Rizzo printf("-- Bridging statistics (%s) --\n", name) ; 1080024d1dbSLuigi Rizzo printf( 1090024d1dbSLuigi Rizzo "Name In Out Forward Drop Bcast Mcast Local Unknown\n"); 1100024d1dbSLuigi Rizzo for (i = 0 ; i < 16 ; i++) { 1110024d1dbSLuigi Rizzo if (s.s[i].name[0]) 112f41f949dSMatthew Dillon printf("%-6s %9ld%9ld%9ld%9ld%9ld%9ld%9ld%9ld\n", 1130024d1dbSLuigi Rizzo s.s[i].name, 1140024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_IN], 1150024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_OUT], 1160024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_FORWARD], 1170024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_DROP], 1180024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_BCAST], 1190024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_MCAST], 1200024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_LOCAL], 1210024d1dbSLuigi Rizzo s.s[i].p_in[(int)BDG_UNKNOWN] ); 1220024d1dbSLuigi Rizzo } 1230024d1dbSLuigi Rizzo } 1240024d1dbSLuigi Rizzo 1252e37c5a3SMax Laier /* 1262e37c5a3SMax Laier * Dump pfsync statistics structure. 1272e37c5a3SMax Laier */ 1282e37c5a3SMax Laier void 1292e37c5a3SMax Laier pfsync_stats(u_long off __unused, const char *name, int af1 __unused) 1302e37c5a3SMax Laier { 1312e37c5a3SMax Laier struct pfsyncstats pfsyncstat, zerostat; 1322e37c5a3SMax Laier size_t len = sizeof(struct pfsyncstats); 133445f17bbSJosef Karthauser 1342e37c5a3SMax Laier if (zflag) 1352e37c5a3SMax Laier memset(&zerostat, 0, len); 1362e37c5a3SMax Laier if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len, 1372e37c5a3SMax Laier zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 1382e37c5a3SMax Laier if (errno != ENOENT) 1392e37c5a3SMax Laier warn("sysctl: net.inet.pfsync.stats"); 1402e37c5a3SMax Laier return; 1412e37c5a3SMax Laier } 142445f17bbSJosef Karthauser 1432e37c5a3SMax Laier printf("%s:\n", name); 1442e37c5a3SMax Laier 1452e37c5a3SMax Laier #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ 1462e37c5a3SMax Laier printf(m, (unsigned long long)pfsyncstat.f, plural(pfsyncstat.f)) 1472e37c5a3SMax Laier #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ 1482e37c5a3SMax Laier printf(m, (unsigned long long)pfsyncstat.f) 1492e37c5a3SMax Laier 1502e37c5a3SMax Laier p(pfsyncs_ipackets, "\t%llu packet%s received (IPv4)\n"); 1512e37c5a3SMax Laier p(pfsyncs_ipackets6, "\t%llu packet%s received (IPv6)\n"); 1522e37c5a3SMax Laier p(pfsyncs_badif, "\t\t%llu packet%s discarded for bad interface\n"); 1532e37c5a3SMax Laier p(pfsyncs_badttl, "\t\t%llu packet%s discarded for bad ttl\n"); 1542e37c5a3SMax Laier p(pfsyncs_hdrops, "\t\t%llu packet%s shorter than header\n"); 1552e37c5a3SMax Laier p(pfsyncs_badver, "\t\t%llu packet%s discarded for bad version\n"); 1562e37c5a3SMax Laier p(pfsyncs_badauth, "\t\t%llu packet%s discarded for bad HMAC\n"); 1572e37c5a3SMax Laier p(pfsyncs_badact,"\t\t%llu packet%s discarded for bad action\n"); 1582e37c5a3SMax Laier p(pfsyncs_badlen, "\t\t%llu packet%s discarded for short packet\n"); 1592e37c5a3SMax Laier p(pfsyncs_badval, "\t\t%llu state%s discarded for bad values\n"); 1602e37c5a3SMax Laier p(pfsyncs_stale, "\t\t%llu stale state%s\n"); 1612e37c5a3SMax Laier p(pfsyncs_badstate, "\t\t%llu failed state lookup/insert%s\n"); 1622e37c5a3SMax Laier p(pfsyncs_opackets, "\t%llu packet%s sent (IPv4)\n"); 1632e37c5a3SMax Laier p(pfsyncs_opackets6, "\t%llu packet%s sent (IPv6)\n"); 1642e37c5a3SMax Laier p2(pfsyncs_onomem, "\t\t%llu send failed due to mbuf memory error\n"); 1652e37c5a3SMax Laier p2(pfsyncs_oerrors, "\t\t%llu send error\n"); 1662e37c5a3SMax Laier #undef p 1672e37c5a3SMax Laier #undef p2 1682e37c5a3SMax Laier } 169445f17bbSJosef Karthauser 170445f17bbSJosef Karthauser /* 171445f17bbSJosef Karthauser * Display a formatted value, or a '-' in the same space. 172445f17bbSJosef Karthauser */ 1735e051718SAssar Westerlund static void 174f964d60dSAssar Westerlund show_stat(const char *fmt, int width, u_long value, short showvalue) 175445f17bbSJosef Karthauser { 176445f17bbSJosef Karthauser char newfmt[32]; 177445f17bbSJosef Karthauser 178445f17bbSJosef Karthauser /* Construct the format string */ 179445f17bbSJosef Karthauser if (showvalue) { 180445f17bbSJosef Karthauser sprintf(newfmt, "%%%d%s", width, fmt); 181445f17bbSJosef Karthauser printf(newfmt, value); 182445f17bbSJosef Karthauser } else { 183445f17bbSJosef Karthauser sprintf(newfmt, "%%%ds", width); 184445f17bbSJosef Karthauser printf(newfmt, "-"); 185445f17bbSJosef Karthauser } 186445f17bbSJosef Karthauser } 187445f17bbSJosef Karthauser 188445f17bbSJosef Karthauser 189445f17bbSJosef Karthauser 1909b50d902SRodney W. Grimes /* 1919b50d902SRodney W. Grimes * Print a description of the network interfaces. 1929b50d902SRodney W. Grimes */ 1939b50d902SRodney W. Grimes void 194e65dd7bcSMark Murray intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) 1959b50d902SRodney W. Grimes { 1969b50d902SRodney W. Grimes struct ifnet ifnet; 1970e27dc05SGarrett Wollman struct ifnethead ifnethead; 1989b50d902SRodney W. Grimes union { 1999b50d902SRodney W. Grimes struct ifaddr ifa; 2009b50d902SRodney W. Grimes struct in_ifaddr in; 201cfa1ca9dSYoshinobu Inoue #ifdef INET6 202cfa1ca9dSYoshinobu Inoue struct in6_ifaddr in6; 203cfa1ca9dSYoshinobu Inoue #endif 204cc6a66f2SJulian Elischer struct ipx_ifaddr ipx; 2059b50d902SRodney W. Grimes } ifaddr; 2069b50d902SRodney W. Grimes u_long ifaddraddr; 207f6719675SBill Fenner u_long ifaddrfound; 208f6719675SBill Fenner u_long ifnetfound; 2095da9f8faSJosef Karthauser u_long opackets; 2105da9f8faSJosef Karthauser u_long ipackets; 2115da9f8faSJosef Karthauser u_long obytes; 2125da9f8faSJosef Karthauser u_long ibytes; 213e1655201SRuslan Ermilov u_long omcasts; 214e1655201SRuslan Ermilov u_long imcasts; 2155da9f8faSJosef Karthauser u_long oerrors; 2165da9f8faSJosef Karthauser u_long ierrors; 2175da9f8faSJosef Karthauser u_long collisions; 2185da9f8faSJosef Karthauser short timer; 2195da9f8faSJosef Karthauser int drops; 220a97a9922SJulian Elischer struct sockaddr *sa = NULL; 2219bf40edeSBrooks Davis char name[IFNAMSIZ]; 222445f17bbSJosef Karthauser short network_layer; 223445f17bbSJosef Karthauser short link_layer; 2249b50d902SRodney W. Grimes 2259b50d902SRodney W. Grimes if (ifnetaddr == 0) { 2269b50d902SRodney W. Grimes printf("ifnet: symbol not defined\n"); 2279b50d902SRodney W. Grimes return; 2289b50d902SRodney W. Grimes } 229e65dd7bcSMark Murray if (_interval) { 230e65dd7bcSMark Murray sidewaysintpr((unsigned)_interval, ifnetaddr); 2319b50d902SRodney W. Grimes return; 2329b50d902SRodney W. Grimes } 2330e27dc05SGarrett Wollman if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) 2349b50d902SRodney W. Grimes return; 2354d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); 2360e27dc05SGarrett Wollman if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 2370e27dc05SGarrett Wollman return; 2380e27dc05SGarrett Wollman 239cf5e44f8SRuslan Ermilov if (!pfunc) { 24025d295e1SBruce M Simpson if (Wflag) 24125d295e1SBruce M Simpson printf("%-7.7s", "Name"); 24225d295e1SBruce M Simpson else 24325d295e1SBruce M Simpson printf("%-5.5s", "Name"); 24425d295e1SBruce M Simpson printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s", 24525d295e1SBruce M Simpson "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 246e1e293a5SDavid Greenman if (bflag) 247e1e293a5SDavid Greenman printf(" %10.10s","Ibytes"); 248e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 249e1e293a5SDavid Greenman if (bflag) 250e1e293a5SDavid Greenman printf(" %10.10s","Obytes"); 2519b50d902SRodney W. Grimes printf(" %5s", "Coll"); 2529b50d902SRodney W. Grimes if (tflag) 2539b50d902SRodney W. Grimes printf(" %s", "Time"); 2549b50d902SRodney W. Grimes if (dflag) 2559b50d902SRodney W. Grimes printf(" %s", "Drop"); 2569b50d902SRodney W. Grimes putchar('\n'); 257cfa1ca9dSYoshinobu Inoue } 2589b50d902SRodney W. Grimes ifaddraddr = 0; 2599b50d902SRodney W. Grimes while (ifnetaddr || ifaddraddr) { 2606cc6f122SPhilippe Charnier struct sockaddr_in *sockin; 261cfa1ca9dSYoshinobu Inoue #ifdef INET6 2626cc6f122SPhilippe Charnier struct sockaddr_in6 *sockin6; 263cfa1ca9dSYoshinobu Inoue #endif 264a01e3379SDavid Malone char *cp; 2659b50d902SRodney W. Grimes int n, m; 2669b50d902SRodney W. Grimes 267445f17bbSJosef Karthauser network_layer = 0; 268445f17bbSJosef Karthauser link_layer = 0; 269445f17bbSJosef Karthauser 2709b50d902SRodney W. Grimes if (ifaddraddr == 0) { 271f6719675SBill Fenner ifnetfound = ifnetaddr; 2729bf40edeSBrooks Davis if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 2739b50d902SRodney W. Grimes return; 2749bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 2754d51ef63SPoul-Henning Kamp ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); 2761b72e71cSDavid Greenman if (interface != 0 && (strcmp(name, interface) != 0)) 2779b50d902SRodney W. Grimes continue; 2789b50d902SRodney W. Grimes cp = index(name, '\0'); 279cfa1ca9dSYoshinobu Inoue 280cfa1ca9dSYoshinobu Inoue if (pfunc) { 281cfa1ca9dSYoshinobu Inoue (*pfunc)(name); 282cfa1ca9dSYoshinobu Inoue continue; 283cfa1ca9dSYoshinobu Inoue } 284cfa1ca9dSYoshinobu Inoue 2859b50d902SRodney W. Grimes if ((ifnet.if_flags&IFF_UP) == 0) 2869b50d902SRodney W. Grimes *cp++ = '*'; 2879b50d902SRodney W. Grimes *cp = '\0'; 2884d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); 2899b50d902SRodney W. Grimes } 290f6719675SBill Fenner ifaddrfound = ifaddraddr; 2915da9f8faSJosef Karthauser 2925da9f8faSJosef Karthauser /* 2935da9f8faSJosef Karthauser * Get the interface stats. These may get 2945da9f8faSJosef Karthauser * overriden below on a per-interface basis. 2955da9f8faSJosef Karthauser */ 2965da9f8faSJosef Karthauser opackets = ifnet.if_opackets; 2975da9f8faSJosef Karthauser ipackets = ifnet.if_ipackets; 2985da9f8faSJosef Karthauser obytes = ifnet.if_obytes; 2995da9f8faSJosef Karthauser ibytes = ifnet.if_ibytes; 300e1655201SRuslan Ermilov omcasts = ifnet.if_omcasts; 301e1655201SRuslan Ermilov imcasts = ifnet.if_imcasts; 3025da9f8faSJosef Karthauser oerrors = ifnet.if_oerrors; 3035da9f8faSJosef Karthauser ierrors = ifnet.if_ierrors; 3045da9f8faSJosef Karthauser collisions = ifnet.if_collisions; 3055da9f8faSJosef Karthauser timer = ifnet.if_timer; 3065da9f8faSJosef Karthauser drops = ifnet.if_snd.ifq_drops; 3075da9f8faSJosef Karthauser 3089b50d902SRodney W. Grimes if (ifaddraddr == 0) { 30925d295e1SBruce M Simpson if (Wflag) 31025d295e1SBruce M Simpson printf("%-7.7s", name); 31125d295e1SBruce M Simpson else 31225d295e1SBruce M Simpson printf("%-5.5s", name); 31325d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 314acb60e59SRuslan Ermilov printf("%-13.13s ", "none"); 315dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", "none"); 3169b50d902SRodney W. Grimes } else { 3179b50d902SRodney W. Grimes if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) { 3189b50d902SRodney W. Grimes ifaddraddr = 0; 3199b50d902SRodney W. Grimes continue; 3209b50d902SRodney W. Grimes } 3219b50d902SRodney W. Grimes #define CP(x) ((char *)(x)) 3229b50d902SRodney W. Grimes cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 323a97a9922SJulian Elischer CP(&ifaddr); 324a97a9922SJulian Elischer sa = (struct sockaddr *)cp; 325d44ddba9SRuslan Ermilov if (af != AF_UNSPEC && sa->sa_family != af) { 326d44ddba9SRuslan Ermilov ifaddraddr = 327d44ddba9SRuslan Ermilov (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 328d44ddba9SRuslan Ermilov continue; 329d44ddba9SRuslan Ermilov } 33025d295e1SBruce M Simpson if (Wflag) 33125d295e1SBruce M Simpson printf("%-7.7s", name); 33225d295e1SBruce M Simpson else 33325d295e1SBruce M Simpson printf("%-5.5s", name); 33425d295e1SBruce M Simpson printf(" %5lu ", ifnet.if_mtu); 3359b50d902SRodney W. Grimes switch (sa->sa_family) { 3369b50d902SRodney W. Grimes case AF_UNSPEC: 337cc6a66f2SJulian Elischer printf("%-13.13s ", "none"); 3389b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 3399b50d902SRodney W. Grimes break; 3409b50d902SRodney W. Grimes case AF_INET: 3416cc6f122SPhilippe Charnier sockin = (struct sockaddr_in *)sa; 3429b50d902SRodney W. Grimes #ifdef notdef 3439b50d902SRodney W. Grimes /* can't use inet_makeaddr because kernel 3449b50d902SRodney W. Grimes * keeps nets unshifted. 3459b50d902SRodney W. Grimes */ 3469b50d902SRodney W. Grimes in = inet_makeaddr(ifaddr.in.ia_subnet, 3479b50d902SRodney W. Grimes INADDR_ANY); 34809a67ffaSStefan Eßer printf("%-13.13s ", netname(in.s_addr, 3499b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3509b50d902SRodney W. Grimes #else 351acb60e59SRuslan Ermilov printf("%-13.13s ", 3529b50d902SRodney W. Grimes netname(htonl(ifaddr.in.ia_subnet), 3539b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 3549b50d902SRodney W. Grimes #endif 355dd1f8b9bSMatthew N. Dodd printf("%-17.17s ", 3566cc6f122SPhilippe Charnier routename(sockin->sin_addr.s_addr)); 357445f17bbSJosef Karthauser 358445f17bbSJosef Karthauser network_layer = 1; 3599b50d902SRodney W. Grimes break; 360cfa1ca9dSYoshinobu Inoue #ifdef INET6 361cfa1ca9dSYoshinobu Inoue case AF_INET6: 3626cc6f122SPhilippe Charnier sockin6 = (struct sockaddr_in6 *)sa; 363acb60e59SRuslan Ermilov printf("%-13.13s ", 364cfa1ca9dSYoshinobu Inoue netname6(&ifaddr.in6.ia_addr, 365cfa1ca9dSYoshinobu Inoue &ifaddr.in6.ia_prefixmask.sin6_addr)); 366cfa1ca9dSYoshinobu Inoue printf("%-17.17s ", 367a01e3379SDavid Malone inet_ntop(AF_INET6, 3686cc6f122SPhilippe Charnier &sockin6->sin6_addr, 369cfa1ca9dSYoshinobu Inoue ntop_buf, sizeof(ntop_buf))); 370445f17bbSJosef Karthauser 371445f17bbSJosef Karthauser network_layer = 1; 372cfa1ca9dSYoshinobu Inoue break; 373cfa1ca9dSYoshinobu Inoue #endif /*INET6*/ 374cc6a66f2SJulian Elischer case AF_IPX: 375cc6a66f2SJulian Elischer { 376cc6a66f2SJulian Elischer struct sockaddr_ipx *sipx = 377cc6a66f2SJulian Elischer (struct sockaddr_ipx *)sa; 378cc6a66f2SJulian Elischer u_long net; 379cc6a66f2SJulian Elischer char netnum[10]; 380cc6a66f2SJulian Elischer 381cc6a66f2SJulian Elischer *(union ipx_net *) &net = sipx->sipx_addr.x_net; 38222694ebaSBruce Evans sprintf(netnum, "%lx", (u_long)ntohl(net)); 383cc6a66f2SJulian Elischer printf("ipx:%-8s ", netnum); 384cc6a66f2SJulian Elischer /* printf("ipx:%-8s ", netname(net, 0L)); */ 385acb60e59SRuslan Ermilov printf("%-17s ", 386cc6a66f2SJulian Elischer ipx_phost((struct sockaddr *)sipx)); 387cc6a66f2SJulian Elischer } 3886f9cdfceSMatthew N. Dodd 3896f9cdfceSMatthew N. Dodd network_layer = 1; 390cc6a66f2SJulian Elischer break; 3916ffcfd6cSJulian Elischer 3926ffcfd6cSJulian Elischer case AF_APPLETALK: 393a8d37845SJulian Elischer printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); 394acb60e59SRuslan Ermilov printf("%-11.11s ",atalk_print(sa,0x0b) ); 3956ffcfd6cSJulian Elischer break; 3969b50d902SRodney W. Grimes case AF_LINK: 3979b50d902SRodney W. Grimes { 3989b50d902SRodney W. Grimes struct sockaddr_dl *sdl = 3999b50d902SRodney W. Grimes (struct sockaddr_dl *)sa; 400cfa1ca9dSYoshinobu Inoue char linknum[10]; 4019b50d902SRodney W. Grimes cp = (char *)LLADDR(sdl); 4029b50d902SRodney W. Grimes n = sdl->sdl_alen; 403cfa1ca9dSYoshinobu Inoue sprintf(linknum, "<Link#%d>", sdl->sdl_index); 404acb60e59SRuslan Ermilov m = printf("%-13.13s ", linknum); 4059b50d902SRodney W. Grimes } 4069b50d902SRodney W. Grimes goto hexprint; 4079b50d902SRodney W. Grimes default: 4089b50d902SRodney W. Grimes m = printf("(%d)", sa->sa_family); 4099b50d902SRodney W. Grimes for (cp = sa->sa_len + (char *)sa; 4109b50d902SRodney W. Grimes --cp > sa->sa_data && (*cp == 0);) {} 4119b50d902SRodney W. Grimes n = cp - sa->sa_data + 1; 4129b50d902SRodney W. Grimes cp = sa->sa_data; 4139b50d902SRodney W. Grimes hexprint: 4149b50d902SRodney W. Grimes while (--n >= 0) 415541f2562SDavid Greenman m += printf("%02x%c", *cp++ & 0xff, 416e54ca68cSJordan K. Hubbard n > 0 ? ':' : ' '); 417acb60e59SRuslan Ermilov m = 32 - m; 4189b50d902SRodney W. Grimes while (m-- > 0) 4199b50d902SRodney W. Grimes putchar(' '); 420445f17bbSJosef Karthauser 421445f17bbSJosef Karthauser link_layer = 1; 4229b50d902SRodney W. Grimes break; 4239b50d902SRodney W. Grimes } 4245da9f8faSJosef Karthauser 4255da9f8faSJosef Karthauser /* 4265da9f8faSJosef Karthauser * Fixup the statistics for interfaces that 4275da9f8faSJosef Karthauser * update stats for their network addresses 4285da9f8faSJosef Karthauser */ 429445f17bbSJosef Karthauser if (network_layer) { 4305da9f8faSJosef Karthauser opackets = ifaddr.in.ia_ifa.if_opackets; 4315da9f8faSJosef Karthauser ipackets = ifaddr.in.ia_ifa.if_ipackets; 4325da9f8faSJosef Karthauser obytes = ifaddr.in.ia_ifa.if_obytes; 4335da9f8faSJosef Karthauser ibytes = ifaddr.in.ia_ifa.if_ibytes; 4345da9f8faSJosef Karthauser } 4355da9f8faSJosef Karthauser 4364d51ef63SPoul-Henning Kamp ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 4379b50d902SRodney W. Grimes } 4385da9f8faSJosef Karthauser 439445f17bbSJosef Karthauser show_stat("lu", 8, ipackets, link_layer|network_layer); 440445f17bbSJosef Karthauser printf(" "); 441445f17bbSJosef Karthauser show_stat("lu", 5, ierrors, link_layer); 442445f17bbSJosef Karthauser printf(" "); 443445f17bbSJosef Karthauser if (bflag) { 444445f17bbSJosef Karthauser show_stat("lu", 10, ibytes, link_layer|network_layer); 445445f17bbSJosef Karthauser printf(" "); 446445f17bbSJosef Karthauser } 447445f17bbSJosef Karthauser show_stat("lu", 8, opackets, link_layer|network_layer); 448445f17bbSJosef Karthauser printf(" "); 449445f17bbSJosef Karthauser show_stat("lu", 5, oerrors, link_layer); 450445f17bbSJosef Karthauser printf(" "); 451445f17bbSJosef Karthauser if (bflag) { 452445f17bbSJosef Karthauser show_stat("lu", 10, obytes, link_layer|network_layer); 453445f17bbSJosef Karthauser printf(" "); 454445f17bbSJosef Karthauser } 455445f17bbSJosef Karthauser show_stat("lu", 5, collisions, link_layer); 456445f17bbSJosef Karthauser if (tflag) { 457445f17bbSJosef Karthauser printf(" "); 458445f17bbSJosef Karthauser show_stat("d", 3, timer, link_layer); 459445f17bbSJosef Karthauser } 460445f17bbSJosef Karthauser if (dflag) { 461445f17bbSJosef Karthauser printf(" "); 462445f17bbSJosef Karthauser show_stat("d", 3, drops, link_layer); 463445f17bbSJosef Karthauser } 4649b50d902SRodney W. Grimes putchar('\n'); 465f6719675SBill Fenner if (aflag && ifaddrfound) { 466f6719675SBill Fenner /* 467f6719675SBill Fenner * Print family's multicast addresses 468f6719675SBill Fenner */ 4694d51ef63SPoul-Henning Kamp struct ifmultiaddr *multiaddr; 47075fb8770SGarrett Wollman struct ifmultiaddr ifma; 47175fb8770SGarrett Wollman union { 47275fb8770SGarrett Wollman struct sockaddr sa; 47375fb8770SGarrett Wollman struct sockaddr_in in; 474cfa1ca9dSYoshinobu Inoue #ifdef INET6 475cfa1ca9dSYoshinobu Inoue struct sockaddr_in6 in6; 476cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 47775fb8770SGarrett Wollman struct sockaddr_dl dl; 47875fb8770SGarrett Wollman } msa; 47975fb8770SGarrett Wollman const char *fmt; 480f6719675SBill Fenner 4816817526dSPoul-Henning Kamp TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) { 4820b23654bSPoul-Henning Kamp if (kread((u_long)multiaddr, (char *)&ifma, 48375fb8770SGarrett Wollman sizeof ifma)) 484f6719675SBill Fenner break; 4850b23654bSPoul-Henning Kamp multiaddr = &ifma; 48675fb8770SGarrett Wollman if (kread((u_long)ifma.ifma_addr, (char *)&msa, 48775fb8770SGarrett Wollman sizeof msa)) 48875fb8770SGarrett Wollman break; 48975fb8770SGarrett Wollman if (msa.sa.sa_family != sa->sa_family) 49075fb8770SGarrett Wollman continue; 49175fb8770SGarrett Wollman 49275fb8770SGarrett Wollman fmt = 0; 49375fb8770SGarrett Wollman switch (msa.sa.sa_family) { 49475fb8770SGarrett Wollman case AF_INET: 49575fb8770SGarrett Wollman fmt = routename(msa.in.sin_addr.s_addr); 49675fb8770SGarrett Wollman break; 497cfa1ca9dSYoshinobu Inoue #ifdef INET6 498cfa1ca9dSYoshinobu Inoue case AF_INET6: 499bce2e7c8SRuslan Ermilov printf("%*s %-19.19s(refs: %d)\n", 500bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", 501cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, 502cfa1ca9dSYoshinobu Inoue &msa.in6.sin6_addr, 503cfa1ca9dSYoshinobu Inoue ntop_buf, 504cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf)), 505cfa1ca9dSYoshinobu Inoue ifma.ifma_refcount); 506b9d92bf5SBill Fenner break; 507cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 508f6719675SBill Fenner case AF_LINK: 509b9d92bf5SBill Fenner switch (msa.dl.sdl_type) { 510f6719675SBill Fenner case IFT_ETHER: 51175fb8770SGarrett Wollman case IFT_FDDI: 51275fb8770SGarrett Wollman fmt = ether_ntoa( 51375fb8770SGarrett Wollman (struct ether_addr *) 51475fb8770SGarrett Wollman LLADDR(&msa.dl)); 51575fb8770SGarrett Wollman break; 516f6719675SBill Fenner } 517f6719675SBill Fenner break; 518f6719675SBill Fenner } 519e1655201SRuslan Ermilov if (fmt) { 520e1655201SRuslan Ermilov printf("%*s %-17.17s", 521bce2e7c8SRuslan Ermilov Wflag ? 27 : 25, "", fmt); 522e1655201SRuslan Ermilov if (msa.sa.sa_family == AF_LINK) { 523e1655201SRuslan Ermilov printf(" %8lu", imcasts); 524e1655201SRuslan Ermilov printf("%*s", 525e1655201SRuslan Ermilov bflag ? 17 : 6, ""); 526e1655201SRuslan Ermilov printf(" %8lu", omcasts); 527e1655201SRuslan Ermilov } 528e1655201SRuslan Ermilov putchar('\n'); 529e1655201SRuslan Ermilov } 530f6719675SBill Fenner } 531f6719675SBill Fenner } 5329b50d902SRodney W. Grimes } 5339b50d902SRodney W. Grimes } 5349b50d902SRodney W. Grimes 5359b50d902SRodney W. Grimes struct iftot { 5364d51ef63SPoul-Henning Kamp SLIST_ENTRY(iftot) chain; 5379bf40edeSBrooks Davis char ift_name[IFNAMSIZ]; /* interface name */ 538890bc2a5SDoug Rabson u_long ift_ip; /* input packets */ 539890bc2a5SDoug Rabson u_long ift_ie; /* input errors */ 540890bc2a5SDoug Rabson u_long ift_op; /* output packets */ 541890bc2a5SDoug Rabson u_long ift_oe; /* output errors */ 542890bc2a5SDoug Rabson u_long ift_co; /* collisions */ 543e1e293a5SDavid Greenman u_int ift_dr; /* drops */ 544890bc2a5SDoug Rabson u_long ift_ib; /* input bytes */ 545890bc2a5SDoug Rabson u_long ift_ob; /* output bytes */ 546591c194aSGuido van Rooij }; 5479b50d902SRodney W. Grimes 5489b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 5499b50d902SRodney W. Grimes 5509b50d902SRodney W. Grimes /* 5519b50d902SRodney W. Grimes * Print a running summary of interface statistics. 5529b50d902SRodney W. Grimes * Repeat display every interval seconds, showing statistics 5539b50d902SRodney W. Grimes * collected over that interval. Assumes that interval is non-zero. 5549b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 5550e27dc05SGarrett Wollman * XXX - should be rewritten to use ifmib(4). 5569b50d902SRodney W. Grimes */ 5579b50d902SRodney W. Grimes static void 558a01e3379SDavid Malone sidewaysintpr(unsigned interval1, u_long off) 5599b50d902SRodney W. Grimes { 5609b50d902SRodney W. Grimes struct ifnet ifnet; 5619b50d902SRodney W. Grimes u_long firstifnet; 5620e27dc05SGarrett Wollman struct ifnethead ifnethead; 563591c194aSGuido van Rooij struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; 564a01e3379SDavid Malone int line; 5650b87c915SDavid Greenman int oldmask, first; 5660b87c915SDavid Greenman u_long interesting_off; 5679b50d902SRodney W. Grimes 5680e27dc05SGarrett Wollman if (kread(off, (char *)&ifnethead, sizeof ifnethead)) 5699b50d902SRodney W. Grimes return; 5704d51ef63SPoul-Henning Kamp firstifnet = (u_long)TAILQ_FIRST(&ifnethead); 5710e27dc05SGarrett Wollman 572591c194aSGuido van Rooij if ((iftot = malloc(sizeof(struct iftot))) == NULL) { 573591c194aSGuido van Rooij printf("malloc failed\n"); 574591c194aSGuido van Rooij exit(1); 575591c194aSGuido van Rooij } 576591c194aSGuido van Rooij memset(iftot, 0, sizeof(struct iftot)); 577591c194aSGuido van Rooij 5780b87c915SDavid Greenman interesting = NULL; 5790b87c915SDavid Greenman interesting_off = 0; 5809b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off;) { 5819bf40edeSBrooks Davis char name[IFNAMSIZ]; 5829b50d902SRodney W. Grimes 5839b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) 5849b50d902SRodney W. Grimes break; 5859bf40edeSBrooks Davis strlcpy(name, ifnet.if_xname, sizeof(name)); 5860b87c915SDavid Greenman if (interface && strcmp(name, interface) == 0) { 5879b50d902SRodney W. Grimes interesting = ip; 5880b87c915SDavid Greenman interesting_off = off; 5890b87c915SDavid Greenman } 590ec3b72e9SRobert Drehmel snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);; 591591c194aSGuido van Rooij if ((ipn = malloc(sizeof(struct iftot))) == NULL) { 592591c194aSGuido van Rooij printf("malloc failed\n"); 593591c194aSGuido van Rooij exit(1); 594591c194aSGuido van Rooij } 595591c194aSGuido van Rooij memset(ipn, 0, sizeof(struct iftot)); 5964d51ef63SPoul-Henning Kamp SLIST_NEXT(ip, chain) = ipn; 597591c194aSGuido van Rooij ip = ipn; 5984d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 5999b50d902SRodney W. Grimes } 600591c194aSGuido van Rooij if ((total = malloc(sizeof(struct iftot))) == NULL) { 601591c194aSGuido van Rooij printf("malloc failed\n"); 602591c194aSGuido van Rooij exit(1); 603591c194aSGuido van Rooij } 604591c194aSGuido van Rooij memset(total, 0, sizeof(struct iftot)); 605591c194aSGuido van Rooij if ((sum = malloc(sizeof(struct iftot))) == NULL) { 606591c194aSGuido van Rooij printf("malloc failed\n"); 607591c194aSGuido van Rooij exit(1); 608591c194aSGuido van Rooij } 609591c194aSGuido van Rooij memset(sum, 0, sizeof(struct iftot)); 610591c194aSGuido van Rooij 6119b50d902SRodney W. Grimes (void)signal(SIGALRM, catchalarm); 6129b50d902SRodney W. Grimes signalled = NO; 613a01e3379SDavid Malone (void)alarm(interval1); 6140b87c915SDavid Greenman first = 1; 6150b87c915SDavid Greenman banner: 6160b87c915SDavid Greenman printf("%17s %14s %16s", "input", 6170b87c915SDavid Greenman interesting ? interesting->ift_name : "(Total)", "output"); 6189b50d902SRodney W. Grimes putchar('\n'); 6190b87c915SDavid Greenman printf("%10s %5s %10s %10s %5s %10s %5s", 6200b87c915SDavid Greenman "packets", "errs", "bytes", "packets", "errs", "bytes", "colls"); 6219b50d902SRodney W. Grimes if (dflag) 6229b50d902SRodney W. Grimes printf(" %5.5s", "drops"); 6239b50d902SRodney W. Grimes putchar('\n'); 6249b50d902SRodney W. Grimes fflush(stdout); 6259b50d902SRodney W. Grimes line = 0; 6269b50d902SRodney W. Grimes loop: 6270b87c915SDavid Greenman if (interesting != NULL) { 6280b87c915SDavid Greenman ip = interesting; 6290b87c915SDavid Greenman if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) { 6300b87c915SDavid Greenman printf("???\n"); 6310b87c915SDavid Greenman exit(1); 6320b87c915SDavid Greenman }; 6330b87c915SDavid Greenman if (!first) { 6347d56c0eeSAlexander Langer printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu", 6350b87c915SDavid Greenman ifnet.if_ipackets - ip->ift_ip, 6360b87c915SDavid Greenman ifnet.if_ierrors - ip->ift_ie, 6370b87c915SDavid Greenman ifnet.if_ibytes - ip->ift_ib, 6380b87c915SDavid Greenman ifnet.if_opackets - ip->ift_op, 6390b87c915SDavid Greenman ifnet.if_oerrors - ip->ift_oe, 6400b87c915SDavid Greenman ifnet.if_obytes - ip->ift_ob, 6410b87c915SDavid Greenman ifnet.if_collisions - ip->ift_co); 6420b87c915SDavid Greenman if (dflag) 6430b87c915SDavid Greenman printf(" %5u", ifnet.if_snd.ifq_drops - ip->ift_dr); 6440b87c915SDavid Greenman } 6450b87c915SDavid Greenman ip->ift_ip = ifnet.if_ipackets; 6460b87c915SDavid Greenman ip->ift_ie = ifnet.if_ierrors; 6470b87c915SDavid Greenman ip->ift_ib = ifnet.if_ibytes; 6480b87c915SDavid Greenman ip->ift_op = ifnet.if_opackets; 6490b87c915SDavid Greenman ip->ift_oe = ifnet.if_oerrors; 6500b87c915SDavid Greenman ip->ift_ob = ifnet.if_obytes; 6510b87c915SDavid Greenman ip->ift_co = ifnet.if_collisions; 6520b87c915SDavid Greenman ip->ift_dr = ifnet.if_snd.ifq_drops; 6530b87c915SDavid Greenman } else { 6549b50d902SRodney W. Grimes sum->ift_ip = 0; 6559b50d902SRodney W. Grimes sum->ift_ie = 0; 6560b87c915SDavid Greenman sum->ift_ib = 0; 6579b50d902SRodney W. Grimes sum->ift_op = 0; 6589b50d902SRodney W. Grimes sum->ift_oe = 0; 6590b87c915SDavid Greenman sum->ift_ob = 0; 6609b50d902SRodney W. Grimes sum->ift_co = 0; 6619b50d902SRodney W. Grimes sum->ift_dr = 0; 6624d51ef63SPoul-Henning Kamp for (off = firstifnet, ip = iftot; 6634d51ef63SPoul-Henning Kamp off && SLIST_NEXT(ip, chain) != NULL; 6644d51ef63SPoul-Henning Kamp ip = SLIST_NEXT(ip, chain)) { 6659b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) { 6669b50d902SRodney W. Grimes off = 0; 6679b50d902SRodney W. Grimes continue; 6689b50d902SRodney W. Grimes } 6690b87c915SDavid Greenman sum->ift_ip += ifnet.if_ipackets; 6700b87c915SDavid Greenman sum->ift_ie += ifnet.if_ierrors; 6710b87c915SDavid Greenman sum->ift_ib += ifnet.if_ibytes; 6720b87c915SDavid Greenman sum->ift_op += ifnet.if_opackets; 6730b87c915SDavid Greenman sum->ift_oe += ifnet.if_oerrors; 6740b87c915SDavid Greenman sum->ift_ob += ifnet.if_obytes; 6750b87c915SDavid Greenman sum->ift_co += ifnet.if_collisions; 6760b87c915SDavid Greenman sum->ift_dr += ifnet.if_snd.ifq_drops; 6774d51ef63SPoul-Henning Kamp off = (u_long)TAILQ_NEXT(&ifnet, if_link); 6789b50d902SRodney W. Grimes } 6790b87c915SDavid Greenman if (!first) { 680890bc2a5SDoug Rabson printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu", 6819b50d902SRodney W. Grimes sum->ift_ip - total->ift_ip, 6820b87c915SDavid Greenman sum->ift_ie - total->ift_ie, 6830b87c915SDavid Greenman sum->ift_ib - total->ift_ib, 6849b50d902SRodney W. Grimes sum->ift_op - total->ift_op, 6850b87c915SDavid Greenman sum->ift_oe - total->ift_oe, 6860b87c915SDavid Greenman sum->ift_ob - total->ift_ob, 6870b87c915SDavid Greenman sum->ift_co - total->ift_co); 6889b50d902SRodney W. Grimes if (dflag) 6893aa80b1dSDavid Greenman printf(" %5u", sum->ift_dr - total->ift_dr); 6909b50d902SRodney W. Grimes } 6919b50d902SRodney W. Grimes *total = *sum; 6920b87c915SDavid Greenman } 6930b87c915SDavid Greenman if (!first) 6949b50d902SRodney W. Grimes putchar('\n'); 6959b50d902SRodney W. Grimes fflush(stdout); 6969b50d902SRodney W. Grimes oldmask = sigblock(sigmask(SIGALRM)); 6979b50d902SRodney W. Grimes if (! signalled) { 6989b50d902SRodney W. Grimes sigpause(0); 6999b50d902SRodney W. Grimes } 7009b50d902SRodney W. Grimes sigsetmask(oldmask); 7019b50d902SRodney W. Grimes signalled = NO; 702a01e3379SDavid Malone (void)alarm(interval1); 7030b87c915SDavid Greenman line++; 7040b87c915SDavid Greenman first = 0; 7059b50d902SRodney W. Grimes if (line == 21) 7069b50d902SRodney W. Grimes goto banner; 7070b87c915SDavid Greenman else 7089b50d902SRodney W. Grimes goto loop; 7099b50d902SRodney W. Grimes /*NOTREACHED*/ 7109b50d902SRodney W. Grimes } 7119b50d902SRodney W. Grimes 7129b50d902SRodney W. Grimes /* 7139b50d902SRodney W. Grimes * Called if an interval expires before sidewaysintpr has completed a loop. 7149b50d902SRodney W. Grimes * Sets a flag to not wait for the alarm. 7159b50d902SRodney W. Grimes */ 7169b50d902SRodney W. Grimes static void 717f964d60dSAssar Westerlund catchalarm(int signo __unused) 7189b50d902SRodney W. Grimes { 7199b50d902SRodney W. Grimes signalled = YES; 7209b50d902SRodney W. Grimes } 721