1 /* 2 * Copyright (c) 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #if 0 35 #ifndef lint 36 static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; 37 #endif /* not lint */ 38 #endif 39 40 #include <sys/cdefs.h> 41 __FBSDID("$FreeBSD$"); 42 43 #include <sys/types.h> 44 #include <sys/protosw.h> 45 #include <sys/socket.h> 46 #include <sys/sysctl.h> 47 #include <sys/time.h> 48 49 #include <net/if.h> 50 #include <net/if_var.h> 51 #include <net/if_dl.h> 52 #include <net/if_types.h> 53 #include <net/ethernet.h> 54 #include <net/pfvar.h> 55 #include <net/if_pfsync.h> 56 #include <netinet/in.h> 57 #include <netinet/in_var.h> 58 #include <netipx/ipx.h> 59 #include <netipx/ipx_if.h> 60 #include <arpa/inet.h> 61 62 #include <err.h> 63 #include <errno.h> 64 #include <libutil.h> 65 #include <signal.h> 66 #include <stdio.h> 67 #include <stdlib.h> 68 #include <string.h> 69 #include <unistd.h> 70 71 #include "netstat.h" 72 73 #define YES 1 74 #define NO 0 75 76 static void sidewaysintpr (u_int, u_long); 77 static void catchalarm (int); 78 79 #ifdef INET6 80 static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */ 81 #endif 82 83 /* 84 * Dump pfsync statistics structure. 85 */ 86 void 87 pfsync_stats(u_long off __unused, const char *name, int af1 __unused) 88 { 89 struct pfsyncstats pfsyncstat, zerostat; 90 size_t len = sizeof(struct pfsyncstats); 91 92 if (zflag) 93 memset(&zerostat, 0, len); 94 if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len, 95 zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 96 if (errno != ENOENT) 97 warn("sysctl: net.inet.pfsync.stats"); 98 return; 99 } 100 101 printf("%s:\n", name); 102 103 #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ 104 printf(m, (unsigned long long)pfsyncstat.f, plural(pfsyncstat.f)) 105 #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ 106 printf(m, (unsigned long long)pfsyncstat.f) 107 108 p(pfsyncs_ipackets, "\t%llu packet%s received (IPv4)\n"); 109 p(pfsyncs_ipackets6, "\t%llu packet%s received (IPv6)\n"); 110 p(pfsyncs_badif, "\t\t%llu packet%s discarded for bad interface\n"); 111 p(pfsyncs_badttl, "\t\t%llu packet%s discarded for bad ttl\n"); 112 p(pfsyncs_hdrops, "\t\t%llu packet%s shorter than header\n"); 113 p(pfsyncs_badver, "\t\t%llu packet%s discarded for bad version\n"); 114 p(pfsyncs_badauth, "\t\t%llu packet%s discarded for bad HMAC\n"); 115 p(pfsyncs_badact,"\t\t%llu packet%s discarded for bad action\n"); 116 p(pfsyncs_badlen, "\t\t%llu packet%s discarded for short packet\n"); 117 p(pfsyncs_badval, "\t\t%llu state%s discarded for bad values\n"); 118 p(pfsyncs_stale, "\t\t%llu stale state%s\n"); 119 p(pfsyncs_badstate, "\t\t%llu failed state lookup/insert%s\n"); 120 p(pfsyncs_opackets, "\t%llu packet%s sent (IPv4)\n"); 121 p(pfsyncs_opackets6, "\t%llu packet%s sent (IPv6)\n"); 122 p2(pfsyncs_onomem, "\t\t%llu send failed due to mbuf memory error\n"); 123 p2(pfsyncs_oerrors, "\t\t%llu send error\n"); 124 #undef p 125 #undef p2 126 } 127 128 /* 129 * Display a formatted value, or a '-' in the same space. 130 */ 131 static void 132 show_stat(const char *fmt, int width, u_long value, short showvalue) 133 { 134 char newfmt[32]; 135 136 if (showvalue == 0) { 137 /* Print just dash. */ 138 sprintf(newfmt, "%%%ds ", width); 139 printf(newfmt, "-"); 140 return; 141 } 142 143 if (hflag) { 144 char buf[5]; 145 146 /* Format in human readable form. */ 147 humanize_number(buf, sizeof(buf), (int64_t)value, "", 148 HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); 149 sprintf(newfmt, "%%%ds ", width); 150 printf(newfmt, buf); 151 } else { 152 /* Construct the format string. */ 153 sprintf(newfmt, "%%%d%s ", width, fmt); 154 printf(newfmt, value); 155 } 156 } 157 158 /* 159 * Print a description of the network interfaces. 160 */ 161 void 162 intpr(int _interval, u_long ifnetaddr, void (*pfunc)(char *)) 163 { 164 struct ifnet ifnet; 165 struct ifnethead ifnethead; 166 union { 167 struct ifaddr ifa; 168 struct in_ifaddr in; 169 #ifdef INET6 170 struct in6_ifaddr in6; 171 #endif 172 struct ipx_ifaddr ipx; 173 } ifaddr; 174 u_long ifaddraddr; 175 u_long ifaddrfound; 176 u_long ifnetfound; 177 u_long opackets; 178 u_long ipackets; 179 u_long obytes; 180 u_long ibytes; 181 u_long omcasts; 182 u_long imcasts; 183 u_long oerrors; 184 u_long ierrors; 185 u_long collisions; 186 short timer; 187 int drops; 188 struct sockaddr *sa = NULL; 189 char name[IFNAMSIZ]; 190 short network_layer; 191 short link_layer; 192 193 if (ifnetaddr == 0) { 194 printf("ifnet: symbol not defined\n"); 195 return; 196 } 197 if (_interval) { 198 sidewaysintpr((unsigned)_interval, ifnetaddr); 199 return; 200 } 201 if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) 202 return; 203 ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead); 204 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 205 return; 206 207 if (!pfunc) { 208 if (Wflag) 209 printf("%-7.7s", "Name"); 210 else 211 printf("%-5.5s", "Name"); 212 printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s", 213 "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 214 if (bflag) 215 printf(" %10.10s","Ibytes"); 216 printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 217 if (bflag) 218 printf(" %10.10s","Obytes"); 219 printf(" %5s", "Coll"); 220 if (tflag) 221 printf(" %s", "Time"); 222 if (dflag) 223 printf(" %s", "Drop"); 224 putchar('\n'); 225 } 226 ifaddraddr = 0; 227 while (ifnetaddr || ifaddraddr) { 228 struct sockaddr_in *sockin; 229 #ifdef INET6 230 struct sockaddr_in6 *sockin6; 231 #endif 232 char *cp; 233 int n, m; 234 235 network_layer = 0; 236 link_layer = 0; 237 238 if (ifaddraddr == 0) { 239 ifnetfound = ifnetaddr; 240 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 241 return; 242 strlcpy(name, ifnet.if_xname, sizeof(name)); 243 ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link); 244 if (interface != 0 && (strcmp(name, interface) != 0)) 245 continue; 246 cp = index(name, '\0'); 247 248 if (pfunc) { 249 (*pfunc)(name); 250 continue; 251 } 252 253 if ((ifnet.if_flags&IFF_UP) == 0) 254 *cp++ = '*'; 255 *cp = '\0'; 256 ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead); 257 } 258 ifaddrfound = ifaddraddr; 259 260 /* 261 * Get the interface stats. These may get 262 * overriden below on a per-interface basis. 263 */ 264 opackets = ifnet.if_opackets; 265 ipackets = ifnet.if_ipackets; 266 obytes = ifnet.if_obytes; 267 ibytes = ifnet.if_ibytes; 268 omcasts = ifnet.if_omcasts; 269 imcasts = ifnet.if_imcasts; 270 oerrors = ifnet.if_oerrors; 271 ierrors = ifnet.if_ierrors; 272 collisions = ifnet.if_collisions; 273 timer = ifnet.if_timer; 274 drops = ifnet.if_snd.ifq_drops; 275 276 if (ifaddraddr == 0) { 277 if (Wflag) 278 printf("%-7.7s", name); 279 else 280 printf("%-5.5s", name); 281 printf(" %5lu ", ifnet.if_mtu); 282 printf("%-13.13s ", "none"); 283 printf("%-17.17s ", "none"); 284 } else { 285 if (kread(ifaddraddr, (char *)&ifaddr, sizeof ifaddr)) { 286 ifaddraddr = 0; 287 continue; 288 } 289 #define CP(x) ((char *)(x)) 290 cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) + 291 CP(&ifaddr); 292 sa = (struct sockaddr *)cp; 293 if (af != AF_UNSPEC && sa->sa_family != af) { 294 ifaddraddr = 295 (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 296 continue; 297 } 298 if (Wflag) 299 printf("%-7.7s", name); 300 else 301 printf("%-5.5s", name); 302 printf(" %5lu ", ifnet.if_mtu); 303 switch (sa->sa_family) { 304 case AF_UNSPEC: 305 printf("%-13.13s ", "none"); 306 printf("%-15.15s ", "none"); 307 break; 308 case AF_INET: 309 sockin = (struct sockaddr_in *)sa; 310 #ifdef notdef 311 /* can't use inet_makeaddr because kernel 312 * keeps nets unshifted. 313 */ 314 in = inet_makeaddr(ifaddr.in.ia_subnet, 315 INADDR_ANY); 316 printf("%-13.13s ", netname(in.s_addr, 317 ifaddr.in.ia_subnetmask)); 318 #else 319 printf("%-13.13s ", 320 netname(htonl(ifaddr.in.ia_subnet), 321 ifaddr.in.ia_subnetmask)); 322 #endif 323 printf("%-17.17s ", 324 routename(sockin->sin_addr.s_addr)); 325 326 network_layer = 1; 327 break; 328 #ifdef INET6 329 case AF_INET6: 330 sockin6 = (struct sockaddr_in6 *)sa; 331 printf("%-13.13s ", 332 netname6(&ifaddr.in6.ia_addr, 333 &ifaddr.in6.ia_prefixmask.sin6_addr)); 334 printf("%-17.17s ", 335 inet_ntop(AF_INET6, 336 &sockin6->sin6_addr, 337 ntop_buf, sizeof(ntop_buf))); 338 339 network_layer = 1; 340 break; 341 #endif /*INET6*/ 342 case AF_IPX: 343 { 344 struct sockaddr_ipx *sipx = 345 (struct sockaddr_ipx *)sa; 346 u_long net; 347 char netnum[10]; 348 349 *(union ipx_net *) &net = sipx->sipx_addr.x_net; 350 sprintf(netnum, "%lx", (u_long)ntohl(net)); 351 printf("ipx:%-8s ", netnum); 352 /* printf("ipx:%-8s ", netname(net, 0L)); */ 353 printf("%-17s ", 354 ipx_phost((struct sockaddr *)sipx)); 355 } 356 357 network_layer = 1; 358 break; 359 360 case AF_APPLETALK: 361 printf("atalk:%-12.12s ",atalk_print(sa,0x10) ); 362 printf("%-11.11s ",atalk_print(sa,0x0b) ); 363 break; 364 case AF_LINK: 365 { 366 struct sockaddr_dl *sdl = 367 (struct sockaddr_dl *)sa; 368 char linknum[10]; 369 cp = (char *)LLADDR(sdl); 370 n = sdl->sdl_alen; 371 sprintf(linknum, "<Link#%d>", sdl->sdl_index); 372 m = printf("%-13.13s ", linknum); 373 } 374 goto hexprint; 375 default: 376 m = printf("(%d)", sa->sa_family); 377 for (cp = sa->sa_len + (char *)sa; 378 --cp > sa->sa_data && (*cp == 0);) {} 379 n = cp - sa->sa_data + 1; 380 cp = sa->sa_data; 381 hexprint: 382 while (--n >= 0) 383 m += printf("%02x%c", *cp++ & 0xff, 384 n > 0 ? ':' : ' '); 385 m = 32 - m; 386 while (m-- > 0) 387 putchar(' '); 388 389 link_layer = 1; 390 break; 391 } 392 393 /* 394 * Fixup the statistics for interfaces that 395 * update stats for their network addresses 396 */ 397 if (network_layer) { 398 opackets = ifaddr.in.ia_ifa.if_opackets; 399 ipackets = ifaddr.in.ia_ifa.if_ipackets; 400 obytes = ifaddr.in.ia_ifa.if_obytes; 401 ibytes = ifaddr.in.ia_ifa.if_ibytes; 402 } 403 404 ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link); 405 } 406 407 show_stat("lu", 8, ipackets, link_layer|network_layer); 408 show_stat("lu", 5, ierrors, link_layer); 409 if (bflag) 410 show_stat("lu", 10, ibytes, link_layer|network_layer); 411 412 show_stat("lu", 8, opackets, link_layer|network_layer); 413 show_stat("lu", 5, oerrors, link_layer); 414 if (bflag) 415 show_stat("lu", 10, obytes, link_layer|network_layer); 416 417 show_stat("lu", 5, collisions, link_layer); 418 if (tflag) 419 show_stat("d", 4, timer, link_layer); 420 421 if (dflag) 422 show_stat("d", 4, drops, link_layer); 423 424 putchar('\n'); 425 if (aflag && ifaddrfound) { 426 /* 427 * Print family's multicast addresses 428 */ 429 struct ifmultiaddr *multiaddr; 430 struct ifmultiaddr ifma; 431 union { 432 struct sockaddr sa; 433 struct sockaddr_in in; 434 #ifdef INET6 435 struct sockaddr_in6 in6; 436 #endif /* INET6 */ 437 struct sockaddr_dl dl; 438 } msa; 439 const char *fmt; 440 441 TAILQ_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) { 442 if (kread((u_long)multiaddr, (char *)&ifma, 443 sizeof ifma)) 444 break; 445 multiaddr = &ifma; 446 if (kread((u_long)ifma.ifma_addr, (char *)&msa, 447 sizeof msa)) 448 break; 449 if (msa.sa.sa_family != sa->sa_family) 450 continue; 451 452 fmt = 0; 453 switch (msa.sa.sa_family) { 454 case AF_INET: 455 fmt = routename(msa.in.sin_addr.s_addr); 456 break; 457 #ifdef INET6 458 case AF_INET6: 459 printf("%*s %-19.19s(refs: %d)\n", 460 Wflag ? 27 : 25, "", 461 inet_ntop(AF_INET6, 462 &msa.in6.sin6_addr, 463 ntop_buf, 464 sizeof(ntop_buf)), 465 ifma.ifma_refcount); 466 break; 467 #endif /* INET6 */ 468 case AF_LINK: 469 switch (msa.dl.sdl_type) { 470 case IFT_ETHER: 471 case IFT_FDDI: 472 fmt = ether_ntoa( 473 (struct ether_addr *) 474 LLADDR(&msa.dl)); 475 break; 476 } 477 break; 478 } 479 if (fmt) { 480 printf("%*s %-17.17s", 481 Wflag ? 27 : 25, "", fmt); 482 if (msa.sa.sa_family == AF_LINK) { 483 printf(" %8lu", imcasts); 484 printf("%*s", 485 bflag ? 17 : 6, ""); 486 printf(" %8lu", omcasts); 487 } 488 putchar('\n'); 489 } 490 } 491 } 492 } 493 } 494 495 struct iftot { 496 SLIST_ENTRY(iftot) chain; 497 char ift_name[IFNAMSIZ]; /* interface name */ 498 u_long ift_ip; /* input packets */ 499 u_long ift_ie; /* input errors */ 500 u_long ift_op; /* output packets */ 501 u_long ift_oe; /* output errors */ 502 u_long ift_co; /* collisions */ 503 u_int ift_dr; /* drops */ 504 u_long ift_ib; /* input bytes */ 505 u_long ift_ob; /* output bytes */ 506 }; 507 508 u_char signalled; /* set if alarm goes off "early" */ 509 510 /* 511 * Print a running summary of interface statistics. 512 * Repeat display every interval seconds, showing statistics 513 * collected over that interval. Assumes that interval is non-zero. 514 * First line printed at top of screen is always cumulative. 515 * XXX - should be rewritten to use ifmib(4). 516 */ 517 static void 518 sidewaysintpr(unsigned interval1, u_long off) 519 { 520 struct ifnet ifnet; 521 u_long firstifnet; 522 struct ifnethead ifnethead; 523 struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting; 524 int line; 525 int oldmask, first; 526 u_long interesting_off; 527 528 if (kread(off, (char *)&ifnethead, sizeof ifnethead)) 529 return; 530 firstifnet = (u_long)TAILQ_FIRST(&ifnethead); 531 532 if ((iftot = malloc(sizeof(struct iftot))) == NULL) { 533 printf("malloc failed\n"); 534 exit(1); 535 } 536 memset(iftot, 0, sizeof(struct iftot)); 537 538 interesting = NULL; 539 interesting_off = 0; 540 for (off = firstifnet, ip = iftot; off;) { 541 char name[IFNAMSIZ]; 542 543 if (kread(off, (char *)&ifnet, sizeof ifnet)) 544 break; 545 strlcpy(name, ifnet.if_xname, sizeof(name)); 546 if (interface && strcmp(name, interface) == 0) { 547 interesting = ip; 548 interesting_off = off; 549 } 550 snprintf(ip->ift_name, sizeof(ip->ift_name), "(%s)", name);; 551 if ((ipn = malloc(sizeof(struct iftot))) == NULL) { 552 printf("malloc failed\n"); 553 exit(1); 554 } 555 memset(ipn, 0, sizeof(struct iftot)); 556 SLIST_NEXT(ip, chain) = ipn; 557 ip = ipn; 558 off = (u_long)TAILQ_NEXT(&ifnet, if_link); 559 } 560 if (interface && interesting == NULL) 561 errx(1, "%s: unknown interface", interface); 562 if ((total = malloc(sizeof(struct iftot))) == NULL) { 563 printf("malloc failed\n"); 564 exit(1); 565 } 566 memset(total, 0, sizeof(struct iftot)); 567 if ((sum = malloc(sizeof(struct iftot))) == NULL) { 568 printf("malloc failed\n"); 569 exit(1); 570 } 571 memset(sum, 0, sizeof(struct iftot)); 572 573 (void)signal(SIGALRM, catchalarm); 574 signalled = NO; 575 (void)alarm(interval1); 576 first = 1; 577 banner: 578 printf("%17s %14s %16s", "input", 579 interesting ? interesting->ift_name : "(Total)", "output"); 580 putchar('\n'); 581 printf("%10s %5s %10s %10s %5s %10s %5s", 582 "packets", "errs", "bytes", "packets", "errs", "bytes", "colls"); 583 if (dflag) 584 printf(" %5.5s", "drops"); 585 putchar('\n'); 586 fflush(stdout); 587 line = 0; 588 loop: 589 if (interesting != NULL) { 590 ip = interesting; 591 if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) { 592 printf("???\n"); 593 exit(1); 594 }; 595 if (!first) { 596 show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1); 597 show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1); 598 show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1); 599 show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1); 600 show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1); 601 show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1); 602 show_stat("lu", 5, ifnet.if_collisions - ip->ift_co, 1); 603 if (dflag) 604 show_stat("u", 5, 605 ifnet.if_snd.ifq_drops - ip->ift_dr, 1); 606 } 607 ip->ift_ip = ifnet.if_ipackets; 608 ip->ift_ie = ifnet.if_ierrors; 609 ip->ift_ib = ifnet.if_ibytes; 610 ip->ift_op = ifnet.if_opackets; 611 ip->ift_oe = ifnet.if_oerrors; 612 ip->ift_ob = ifnet.if_obytes; 613 ip->ift_co = ifnet.if_collisions; 614 ip->ift_dr = ifnet.if_snd.ifq_drops; 615 } else { 616 sum->ift_ip = 0; 617 sum->ift_ie = 0; 618 sum->ift_ib = 0; 619 sum->ift_op = 0; 620 sum->ift_oe = 0; 621 sum->ift_ob = 0; 622 sum->ift_co = 0; 623 sum->ift_dr = 0; 624 for (off = firstifnet, ip = iftot; 625 off && SLIST_NEXT(ip, chain) != NULL; 626 ip = SLIST_NEXT(ip, chain)) { 627 if (kread(off, (char *)&ifnet, sizeof ifnet)) { 628 off = 0; 629 continue; 630 } 631 sum->ift_ip += ifnet.if_ipackets; 632 sum->ift_ie += ifnet.if_ierrors; 633 sum->ift_ib += ifnet.if_ibytes; 634 sum->ift_op += ifnet.if_opackets; 635 sum->ift_oe += ifnet.if_oerrors; 636 sum->ift_ob += ifnet.if_obytes; 637 sum->ift_co += ifnet.if_collisions; 638 sum->ift_dr += ifnet.if_snd.ifq_drops; 639 off = (u_long)TAILQ_NEXT(&ifnet, if_link); 640 } 641 if (!first) { 642 show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1); 643 show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1); 644 show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1); 645 show_stat("lu", 10, sum->ift_op - total->ift_op, 1); 646 show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1); 647 show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1); 648 show_stat("lu", 5, sum->ift_co - total->ift_co, 1); 649 if (dflag) 650 show_stat("u", 5, 651 sum->ift_dr - total->ift_dr, 1); 652 } 653 *total = *sum; 654 } 655 if (!first) 656 putchar('\n'); 657 fflush(stdout); 658 oldmask = sigblock(sigmask(SIGALRM)); 659 if (! signalled) { 660 sigpause(0); 661 } 662 sigsetmask(oldmask); 663 signalled = NO; 664 (void)alarm(interval1); 665 line++; 666 first = 0; 667 if (line == 21) 668 goto banner; 669 else 670 goto loop; 671 /*NOTREACHED*/ 672 } 673 674 /* 675 * Called if an interval expires before sidewaysintpr has completed a loop. 676 * Sets a flag to not wait for the alarm. 677 */ 678 static void 679 catchalarm(int signo __unused) 680 { 681 signalled = YES; 682 } 683