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 349b50d902SRodney W. Grimes #ifndef lint 359b50d902SRodney W. Grimes static char sccsid[] = "@(#)if.c 8.2 (Berkeley) 2/21/94"; 369b50d902SRodney W. Grimes #endif /* not lint */ 379b50d902SRodney W. Grimes 389b50d902SRodney W. Grimes #include <sys/types.h> 399b50d902SRodney W. Grimes #include <sys/protosw.h> 409b50d902SRodney W. Grimes #include <sys/socket.h> 419b50d902SRodney W. Grimes 429b50d902SRodney W. Grimes #include <net/if.h> 439b50d902SRodney W. Grimes #include <net/if_dl.h> 449b50d902SRodney W. Grimes #include <netinet/in.h> 459b50d902SRodney W. Grimes #include <netinet/in_var.h> 469b50d902SRodney W. Grimes #include <netns/ns.h> 479b50d902SRodney W. Grimes #include <netns/ns_if.h> 489b50d902SRodney W. Grimes #include <netiso/iso.h> 499b50d902SRodney W. Grimes #include <netiso/iso_var.h> 509b50d902SRodney W. Grimes #include <arpa/inet.h> 519b50d902SRodney W. Grimes 529b50d902SRodney W. Grimes #include <signal.h> 539b50d902SRodney W. Grimes #include <stdio.h> 549b50d902SRodney W. Grimes #include <string.h> 559b50d902SRodney W. Grimes #include <unistd.h> 569b50d902SRodney W. Grimes 579b50d902SRodney W. Grimes #include "netstat.h" 589b50d902SRodney W. Grimes 599b50d902SRodney W. Grimes #define YES 1 609b50d902SRodney W. Grimes #define NO 0 619b50d902SRodney W. Grimes 629b50d902SRodney W. Grimes static void sidewaysintpr __P((u_int, u_long)); 639b50d902SRodney W. Grimes static void catchalarm __P((int)); 649b50d902SRodney W. Grimes 659b50d902SRodney W. Grimes /* 669b50d902SRodney W. Grimes * Print a description of the network interfaces. 679b50d902SRodney W. Grimes */ 689b50d902SRodney W. Grimes void 699b50d902SRodney W. Grimes intpr(interval, ifnetaddr) 709b50d902SRodney W. Grimes int interval; 719b50d902SRodney W. Grimes u_long ifnetaddr; 729b50d902SRodney W. Grimes { 739b50d902SRodney W. Grimes struct ifnet ifnet; 749b50d902SRodney W. Grimes union { 759b50d902SRodney W. Grimes struct ifaddr ifa; 769b50d902SRodney W. Grimes struct in_ifaddr in; 779b50d902SRodney W. Grimes struct ns_ifaddr ns; 789b50d902SRodney W. Grimes struct iso_ifaddr iso; 799b50d902SRodney W. Grimes } ifaddr; 809b50d902SRodney W. Grimes u_long ifaddraddr; 819b50d902SRodney W. Grimes struct sockaddr *sa; 829b50d902SRodney W. Grimes char name[16]; 839b50d902SRodney W. Grimes 849b50d902SRodney W. Grimes if (ifnetaddr == 0) { 859b50d902SRodney W. Grimes printf("ifnet: symbol not defined\n"); 869b50d902SRodney W. Grimes return; 879b50d902SRodney W. Grimes } 889b50d902SRodney W. Grimes if (interval) { 899b50d902SRodney W. Grimes sidewaysintpr((unsigned)interval, ifnetaddr); 909b50d902SRodney W. Grimes return; 919b50d902SRodney W. Grimes } 929b50d902SRodney W. Grimes if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr)) 939b50d902SRodney W. Grimes return; 94e1e293a5SDavid Greenman printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s", 95e1e293a5SDavid Greenman "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 96e1e293a5SDavid Greenman if (bflag) 97e1e293a5SDavid Greenman printf(" %10.10s","Ibytes"); 98e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 99e1e293a5SDavid Greenman if (bflag) 100e1e293a5SDavid Greenman printf(" %10.10s","Obytes"); 1019b50d902SRodney W. Grimes printf(" %5s", "Coll"); 1029b50d902SRodney W. Grimes if (tflag) 1039b50d902SRodney W. Grimes printf(" %s", "Time"); 1049b50d902SRodney W. Grimes if (dflag) 1059b50d902SRodney W. Grimes printf(" %s", "Drop"); 1069b50d902SRodney W. Grimes putchar('\n'); 1079b50d902SRodney W. Grimes ifaddraddr = 0; 1089b50d902SRodney W. Grimes while (ifnetaddr || ifaddraddr) { 1099b50d902SRodney W. Grimes struct sockaddr_in *sin; 1109b50d902SRodney W. Grimes register char *cp; 1119b50d902SRodney W. Grimes int n, m; 1129b50d902SRodney W. Grimes 1139b50d902SRodney W. Grimes if (ifaddraddr == 0) { 1149b50d902SRodney W. Grimes if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || 1159b50d902SRodney W. Grimes kread((u_long)ifnet.if_name, name, 16)) 1169b50d902SRodney W. Grimes return; 1179b50d902SRodney W. Grimes name[15] = '\0'; 1189b50d902SRodney W. Grimes ifnetaddr = (u_long)ifnet.if_next; 1199b50d902SRodney W. Grimes if (interface != 0 && (strcmp(name, interface) != 0 || 1209b50d902SRodney W. Grimes unit != ifnet.if_unit)) 1219b50d902SRodney W. Grimes continue; 1229b50d902SRodney W. Grimes cp = index(name, '\0'); 1239b50d902SRodney W. Grimes cp += sprintf(cp, "%d", ifnet.if_unit); 1249b50d902SRodney W. Grimes if ((ifnet.if_flags&IFF_UP) == 0) 1259b50d902SRodney W. Grimes *cp++ = '*'; 1269b50d902SRodney W. Grimes *cp = '\0'; 1279b50d902SRodney W. Grimes ifaddraddr = (u_long)ifnet.if_addrlist; 1289b50d902SRodney W. Grimes } 1299b50d902SRodney W. Grimes printf("%-5.5s %-5d ", name, ifnet.if_mtu); 1309b50d902SRodney W. Grimes if (ifaddraddr == 0) { 1319b50d902SRodney W. Grimes printf("%-11.11s ", "none"); 1329b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 1339b50d902SRodney W. Grimes } else { 1349b50d902SRodney W. Grimes if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) { 1359b50d902SRodney W. Grimes ifaddraddr = 0; 1369b50d902SRodney W. Grimes continue; 1379b50d902SRodney W. Grimes } 1389b50d902SRodney W. Grimes #define CP(x) ((char *)(x)) 1399b50d902SRodney W. Grimes cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 1409b50d902SRodney W. Grimes CP(&ifaddr); sa = (struct sockaddr *)cp; 1419b50d902SRodney W. Grimes switch (sa->sa_family) { 1429b50d902SRodney W. Grimes case AF_UNSPEC: 1439b50d902SRodney W. Grimes printf("%-11.11s ", "none"); 1449b50d902SRodney W. Grimes printf("%-15.15s ", "none"); 1459b50d902SRodney W. Grimes break; 1469b50d902SRodney W. Grimes case AF_INET: 1479b50d902SRodney W. Grimes sin = (struct sockaddr_in *)sa; 1489b50d902SRodney W. Grimes #ifdef notdef 1499b50d902SRodney W. Grimes /* can't use inet_makeaddr because kernel 1509b50d902SRodney W. Grimes * keeps nets unshifted. 1519b50d902SRodney W. Grimes */ 1529b50d902SRodney W. Grimes in = inet_makeaddr(ifaddr.in.ia_subnet, 1539b50d902SRodney W. Grimes INADDR_ANY); 1549b50d902SRodney W. Grimes printf("%-11.11s ", netname(in.s_addr, 1559b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 1569b50d902SRodney W. Grimes #else 1579b50d902SRodney W. Grimes printf("%-11.11s ", 1589b50d902SRodney W. Grimes netname(htonl(ifaddr.in.ia_subnet), 1599b50d902SRodney W. Grimes ifaddr.in.ia_subnetmask)); 1609b50d902SRodney W. Grimes #endif 1619b50d902SRodney W. Grimes printf("%-15.15s ", 1629b50d902SRodney W. Grimes routename(sin->sin_addr.s_addr)); 1639b50d902SRodney W. Grimes break; 1649b50d902SRodney W. Grimes case AF_NS: 1659b50d902SRodney W. Grimes { 1669b50d902SRodney W. Grimes struct sockaddr_ns *sns = 1679b50d902SRodney W. Grimes (struct sockaddr_ns *)sa; 1689b50d902SRodney W. Grimes u_long net; 1699b50d902SRodney W. Grimes char netnum[8]; 1709b50d902SRodney W. Grimes 1719b50d902SRodney W. Grimes *(union ns_net *) &net = sns->sns_addr.x_net; 1729b50d902SRodney W. Grimes sprintf(netnum, "%lxH", ntohl(net)); 1739b50d902SRodney W. Grimes upHex(netnum); 1749b50d902SRodney W. Grimes printf("ns:%-8s ", netnum); 1759b50d902SRodney W. Grimes printf("%-15s ", 1769b50d902SRodney W. Grimes ns_phost((struct sockaddr *)sns)); 1779b50d902SRodney W. Grimes } 1789b50d902SRodney W. Grimes break; 1799b50d902SRodney W. Grimes case AF_LINK: 1809b50d902SRodney W. Grimes { 1819b50d902SRodney W. Grimes struct sockaddr_dl *sdl = 1829b50d902SRodney W. Grimes (struct sockaddr_dl *)sa; 1839b50d902SRodney W. Grimes cp = (char *)LLADDR(sdl); 1849b50d902SRodney W. Grimes n = sdl->sdl_alen; 1859b50d902SRodney W. Grimes } 1869b50d902SRodney W. Grimes m = printf("<Link>"); 1879b50d902SRodney W. Grimes goto hexprint; 1889b50d902SRodney W. Grimes default: 1899b50d902SRodney W. Grimes m = printf("(%d)", sa->sa_family); 1909b50d902SRodney W. Grimes for (cp = sa->sa_len + (char *)sa; 1919b50d902SRodney W. Grimes --cp > sa->sa_data && (*cp == 0);) {} 1929b50d902SRodney W. Grimes n = cp - sa->sa_data + 1; 1939b50d902SRodney W. Grimes cp = sa->sa_data; 1949b50d902SRodney W. Grimes hexprint: 1959b50d902SRodney W. Grimes while (--n >= 0) 196541f2562SDavid Greenman m += printf("%02x%c", *cp++ & 0xff, 1979b50d902SRodney W. Grimes n > 0 ? '.' : ' '); 1989b50d902SRodney W. Grimes m = 28 - m; 1999b50d902SRodney W. Grimes while (m-- > 0) 2009b50d902SRodney W. Grimes putchar(' '); 2019b50d902SRodney W. Grimes break; 2029b50d902SRodney W. Grimes } 2039b50d902SRodney W. Grimes ifaddraddr = (u_long)ifaddr.ifa.ifa_next; 2049b50d902SRodney W. Grimes } 205e1e293a5SDavid Greenman printf("%8d %5d ", 206e1e293a5SDavid Greenman ifnet.if_ipackets, ifnet.if_ierrors); 207e1e293a5SDavid Greenman if (bflag) 208e1e293a5SDavid Greenman printf("%10d ", ifnet.if_ibytes); 209e1e293a5SDavid Greenman printf("%8d %5d ", 210e1e293a5SDavid Greenman ifnet.if_opackets, ifnet.if_oerrors); 211e1e293a5SDavid Greenman if (bflag) 212e1e293a5SDavid Greenman printf("%10d ", ifnet.if_obytes); 213e1e293a5SDavid Greenman printf("%5d", ifnet.if_collisions); 2149b50d902SRodney W. Grimes if (tflag) 2159b50d902SRodney W. Grimes printf(" %3d", ifnet.if_timer); 2169b50d902SRodney W. Grimes if (dflag) 2179b50d902SRodney W. Grimes printf(" %3d", ifnet.if_snd.ifq_drops); 2189b50d902SRodney W. Grimes putchar('\n'); 2199b50d902SRodney W. Grimes } 2209b50d902SRodney W. Grimes } 2219b50d902SRodney W. Grimes 2229b50d902SRodney W. Grimes #define MAXIF 10 2239b50d902SRodney W. Grimes struct iftot { 2249b50d902SRodney W. Grimes char ift_name[16]; /* interface name */ 225e1e293a5SDavid Greenman u_int ift_ip; /* input packets */ 226e1e293a5SDavid Greenman u_int ift_ie; /* input errors */ 227e1e293a5SDavid Greenman u_int ift_op; /* output packets */ 228e1e293a5SDavid Greenman u_int ift_oe; /* output errors */ 229e1e293a5SDavid Greenman u_int ift_co; /* collisions */ 230e1e293a5SDavid Greenman u_int ift_dr; /* drops */ 231e1e293a5SDavid Greenman u_int ift_ib; /* input bytes */ 232e1e293a5SDavid Greenman u_int ift_ob; /* output bytes */ 2339b50d902SRodney W. Grimes } iftot[MAXIF]; 2349b50d902SRodney W. Grimes 2359b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 2369b50d902SRodney W. Grimes 2379b50d902SRodney W. Grimes /* 2389b50d902SRodney W. Grimes * Print a running summary of interface statistics. 2399b50d902SRodney W. Grimes * Repeat display every interval seconds, showing statistics 2409b50d902SRodney W. Grimes * collected over that interval. Assumes that interval is non-zero. 2419b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 2429b50d902SRodney W. Grimes */ 2439b50d902SRodney W. Grimes static void 2449b50d902SRodney W. Grimes sidewaysintpr(interval, off) 2459b50d902SRodney W. Grimes unsigned interval; 2469b50d902SRodney W. Grimes u_long off; 2479b50d902SRodney W. Grimes { 2489b50d902SRodney W. Grimes struct ifnet ifnet; 2499b50d902SRodney W. Grimes u_long firstifnet; 2509b50d902SRodney W. Grimes register struct iftot *ip, *total; 2519b50d902SRodney W. Grimes register int line; 2529b50d902SRodney W. Grimes struct iftot *lastif, *sum, *interesting; 2539b50d902SRodney W. Grimes int oldmask; 2549b50d902SRodney W. Grimes 2559b50d902SRodney W. Grimes if (kread(off, (char *)&firstifnet, sizeof (u_long))) 2569b50d902SRodney W. Grimes return; 2579b50d902SRodney W. Grimes lastif = iftot; 2589b50d902SRodney W. Grimes sum = iftot + MAXIF - 1; 2599b50d902SRodney W. Grimes total = sum - 1; 2609b50d902SRodney W. Grimes interesting = iftot; 2619b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off;) { 2629b50d902SRodney W. Grimes char *cp; 2639b50d902SRodney W. Grimes 2649b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) 2659b50d902SRodney W. Grimes break; 2669b50d902SRodney W. Grimes ip->ift_name[0] = '('; 2679b50d902SRodney W. Grimes if (kread((u_long)ifnet.if_name, ip->ift_name + 1, 15)) 2689b50d902SRodney W. Grimes break; 2699b50d902SRodney W. Grimes if (interface && strcmp(ip->ift_name + 1, interface) == 0 && 2709b50d902SRodney W. Grimes unit == ifnet.if_unit) 2719b50d902SRodney W. Grimes interesting = ip; 2729b50d902SRodney W. Grimes ip->ift_name[15] = '\0'; 2739b50d902SRodney W. Grimes cp = index(ip->ift_name, '\0'); 2749b50d902SRodney W. Grimes sprintf(cp, "%d)", ifnet.if_unit); 2759b50d902SRodney W. Grimes ip++; 2769b50d902SRodney W. Grimes if (ip >= iftot + MAXIF - 2) 2779b50d902SRodney W. Grimes break; 2789b50d902SRodney W. Grimes off = (u_long) ifnet.if_next; 2799b50d902SRodney W. Grimes } 2809b50d902SRodney W. Grimes lastif = ip; 2819b50d902SRodney W. Grimes 2829b50d902SRodney W. Grimes (void)signal(SIGALRM, catchalarm); 2839b50d902SRodney W. Grimes signalled = NO; 2849b50d902SRodney W. Grimes (void)alarm(interval); 2859b50d902SRodney W. Grimes banner: 286e1e293a5SDavid Greenman printf(" input %s%-6.6s %soutput ", bflag ? " " : "", 287e1e293a5SDavid Greenman interesting->ift_name, bflag ? " " : ""); 2889b50d902SRodney W. Grimes if (lastif - iftot > 0) { 2899b50d902SRodney W. Grimes if (dflag) 2909b50d902SRodney W. Grimes printf(" "); 291e1e293a5SDavid Greenman printf(" input %s(Total) %soutput", bflag ? " " : "", 292e1e293a5SDavid Greenman bflag ? " " : ""); 2939b50d902SRodney W. Grimes } 2949b50d902SRodney W. Grimes for (ip = iftot; ip < iftot + MAXIF; ip++) { 2959b50d902SRodney W. Grimes ip->ift_ip = 0; 2969b50d902SRodney W. Grimes ip->ift_ie = 0; 2979b50d902SRodney W. Grimes ip->ift_op = 0; 2989b50d902SRodney W. Grimes ip->ift_oe = 0; 2999b50d902SRodney W. Grimes ip->ift_co = 0; 3009b50d902SRodney W. Grimes ip->ift_dr = 0; 301e1e293a5SDavid Greenman ip->ift_ib = 0; 302e1e293a5SDavid Greenman ip->ift_ob = 0; 3039b50d902SRodney W. Grimes } 3049b50d902SRodney W. Grimes putchar('\n'); 305e1e293a5SDavid Greenman printf("%8.8s %5.5s ", "packets", "errs"); 306e1e293a5SDavid Greenman if (bflag) 307e1e293a5SDavid Greenman printf("%10.10s ","bytes"); 308e1e293a5SDavid Greenman printf("%8.8s %5.5s ", "packets", "errs"); 309e1e293a5SDavid Greenman if (bflag) 310e1e293a5SDavid Greenman printf("%10.10s ","bytes"); 311e1e293a5SDavid Greenman printf("%5.5s ", "colls"); 3129b50d902SRodney W. Grimes if (dflag) 3139b50d902SRodney W. Grimes printf("%5.5s ", "drops"); 314e1e293a5SDavid Greenman if (lastif - iftot > 0) { 315e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "packets", "errs"); 316e1e293a5SDavid Greenman if (bflag) 317e1e293a5SDavid Greenman printf(" %10.10s", "bytes"); 318e1e293a5SDavid Greenman printf(" %8.8s %5.5s", "packets", "errs"); 319e1e293a5SDavid Greenman if (bflag) 320e1e293a5SDavid Greenman printf(" %10.10s", "bytes"); 321e1e293a5SDavid Greenman printf(" %5.5s", "colls"); 3229b50d902SRodney W. Grimes if (dflag) 3239b50d902SRodney W. Grimes printf(" %5.5s", "drops"); 324e1e293a5SDavid Greenman } 3259b50d902SRodney W. Grimes putchar('\n'); 3269b50d902SRodney W. Grimes fflush(stdout); 3279b50d902SRodney W. Grimes line = 0; 3289b50d902SRodney W. Grimes loop: 3299b50d902SRodney W. Grimes sum->ift_ip = 0; 3309b50d902SRodney W. Grimes sum->ift_ie = 0; 3319b50d902SRodney W. Grimes sum->ift_op = 0; 3329b50d902SRodney W. Grimes sum->ift_oe = 0; 3339b50d902SRodney W. Grimes sum->ift_co = 0; 3349b50d902SRodney W. Grimes sum->ift_dr = 0; 335e1e293a5SDavid Greenman sum->ift_ib = 0; 336e1e293a5SDavid Greenman sum->ift_ob = 0; 3379b50d902SRodney W. Grimes for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) { 3389b50d902SRodney W. Grimes if (kread(off, (char *)&ifnet, sizeof ifnet)) { 3399b50d902SRodney W. Grimes off = 0; 3409b50d902SRodney W. Grimes continue; 3419b50d902SRodney W. Grimes } 3429b50d902SRodney W. Grimes if (ip == interesting) { 343e1e293a5SDavid Greenman printf("%8d %5d ", 3449b50d902SRodney W. Grimes ifnet.if_ipackets - ip->ift_ip, 345e1e293a5SDavid Greenman ifnet.if_ierrors - ip->ift_ie); 346e1e293a5SDavid Greenman if (bflag) 347e1e293a5SDavid Greenman printf("%10d ", ifnet.if_ibytes - ip->ift_ib); 348e1e293a5SDavid Greenman printf("%8d %5d ", 3499b50d902SRodney W. Grimes ifnet.if_opackets - ip->ift_op, 350e1e293a5SDavid Greenman ifnet.if_oerrors - ip->ift_oe); 351e1e293a5SDavid Greenman if (bflag) 352e1e293a5SDavid Greenman printf("%10d ", ifnet.if_obytes - ip->ift_ob); 353e1e293a5SDavid Greenman printf("%5d", ifnet.if_collisions - ip->ift_co); 3549b50d902SRodney W. Grimes if (dflag) 3559b50d902SRodney W. Grimes printf(" %5d", 3569b50d902SRodney W. Grimes ifnet.if_snd.ifq_drops - ip->ift_dr); 3579b50d902SRodney W. Grimes } 3589b50d902SRodney W. Grimes ip->ift_ip = ifnet.if_ipackets; 3599b50d902SRodney W. Grimes ip->ift_ie = ifnet.if_ierrors; 3609b50d902SRodney W. Grimes ip->ift_op = ifnet.if_opackets; 3619b50d902SRodney W. Grimes ip->ift_oe = ifnet.if_oerrors; 3629b50d902SRodney W. Grimes ip->ift_co = ifnet.if_collisions; 3639b50d902SRodney W. Grimes ip->ift_dr = ifnet.if_snd.ifq_drops; 364e1e293a5SDavid Greenman ip->ift_ib = ifnet.if_ibytes; 365e1e293a5SDavid Greenman ip->ift_ob = ifnet.if_obytes; 3669b50d902SRodney W. Grimes sum->ift_ip += ip->ift_ip; 3679b50d902SRodney W. Grimes sum->ift_ie += ip->ift_ie; 3689b50d902SRodney W. Grimes sum->ift_op += ip->ift_op; 3699b50d902SRodney W. Grimes sum->ift_oe += ip->ift_oe; 3709b50d902SRodney W. Grimes sum->ift_co += ip->ift_co; 3719b50d902SRodney W. Grimes sum->ift_dr += ip->ift_dr; 372e1e293a5SDavid Greenman sum->ift_ib += ip->ift_ib; 373e1e293a5SDavid Greenman sum->ift_ob += ip->ift_ob; 3749b50d902SRodney W. Grimes off = (u_long) ifnet.if_next; 3759b50d902SRodney W. Grimes } 3769b50d902SRodney W. Grimes if (lastif - iftot > 0) { 377e1e293a5SDavid Greenman printf(" %8d %5d", 3789b50d902SRodney W. Grimes sum->ift_ip - total->ift_ip, 379e1e293a5SDavid Greenman sum->ift_ie - total->ift_ie); 380e1e293a5SDavid Greenman if (bflag) 381e1e293a5SDavid Greenman printf(" %10d", sum->ift_ib - total->ift_ib); 382e1e293a5SDavid Greenman printf(" %8d %5d", 3839b50d902SRodney W. Grimes sum->ift_op - total->ift_op, 384e1e293a5SDavid Greenman sum->ift_oe - total->ift_oe); 385e1e293a5SDavid Greenman if (bflag) 386e1e293a5SDavid Greenman printf(" %10d", sum->ift_ob - total->ift_ob); 387e1e293a5SDavid Greenman printf(" %5d", sum->ift_co - total->ift_co); 3889b50d902SRodney W. Grimes if (dflag) 3899b50d902SRodney W. Grimes printf(" %5d", sum->ift_dr - total->ift_dr); 3909b50d902SRodney W. Grimes } 3919b50d902SRodney W. Grimes *total = *sum; 3929b50d902SRodney W. Grimes putchar('\n'); 3939b50d902SRodney W. Grimes fflush(stdout); 3949b50d902SRodney W. Grimes line++; 3959b50d902SRodney W. Grimes oldmask = sigblock(sigmask(SIGALRM)); 3969b50d902SRodney W. Grimes if (! signalled) { 3979b50d902SRodney W. Grimes sigpause(0); 3989b50d902SRodney W. Grimes } 3999b50d902SRodney W. Grimes sigsetmask(oldmask); 4009b50d902SRodney W. Grimes signalled = NO; 4019b50d902SRodney W. Grimes (void)alarm(interval); 4029b50d902SRodney W. Grimes if (line == 21) 4039b50d902SRodney W. Grimes goto banner; 4049b50d902SRodney W. Grimes goto loop; 4059b50d902SRodney W. Grimes /*NOTREACHED*/ 4069b50d902SRodney W. Grimes } 4079b50d902SRodney W. Grimes 4089b50d902SRodney W. Grimes /* 4099b50d902SRodney W. Grimes * Called if an interval expires before sidewaysintpr has completed a loop. 4109b50d902SRodney W. Grimes * Sets a flag to not wait for the alarm. 4119b50d902SRodney W. Grimes */ 4129b50d902SRodney W. Grimes static void 4139b50d902SRodney W. Grimes catchalarm(signo) 4149b50d902SRodney W. Grimes int signo; 4159b50d902SRodney W. Grimes { 4169b50d902SRodney W. Grimes signalled = YES; 4179b50d902SRodney W. Grimes } 418