Deleted Added
full compact
if.c (67963) if.c (70524)
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

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35/*
36static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
37*/
38static const char rcsid[] =
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

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35/*
36static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
37*/
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/netstat/if.c 67963 2000-10-30 11:53:19Z guido $";
39 "$FreeBSD: head/usr.bin/netstat/if.c 70524 2000-12-30 21:22:54Z phk $";
40#endif /* not lint */
41
42#include <sys/types.h>
43#include <sys/protosw.h>
44#include <sys/socket.h>
45#include <sys/sysctl.h>
46#include <sys/time.h>
47

--- 122 unchanged lines hidden (view full) ---

170 return;
171 }
172 if (interval) {
173 sidewaysintpr((unsigned)interval, ifnetaddr);
174 return;
175 }
176 if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead))
177 return;
40#endif /* not lint */
41
42#include <sys/types.h>
43#include <sys/protosw.h>
44#include <sys/socket.h>
45#include <sys/sysctl.h>
46#include <sys/time.h>
47

--- 122 unchanged lines hidden (view full) ---

170 return;
171 }
172 if (interval) {
173 sidewaysintpr((unsigned)interval, ifnetaddr);
174 return;
175 }
176 if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead))
177 return;
178 ifnetaddr = (u_long)ifnethead.tqh_first;
178 ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
179 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
180 return;
181
182 if ((!sflag || iflag) && !pflag) {
183 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
184 "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
185 if (bflag)
186 printf(" %10.10s","Ibytes");

--- 17 unchanged lines hidden (view full) ---

204 int n, m;
205
206 if (ifaddraddr == 0) {
207 ifnetfound = ifnetaddr;
208 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
209 kread((u_long)ifnet.if_name, tname, 16))
210 return;
211 tname[15] = '\0';
179 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
180 return;
181
182 if ((!sflag || iflag) && !pflag) {
183 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
184 "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
185 if (bflag)
186 printf(" %10.10s","Ibytes");

--- 17 unchanged lines hidden (view full) ---

204 int n, m;
205
206 if (ifaddraddr == 0) {
207 ifnetfound = ifnetaddr;
208 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
209 kread((u_long)ifnet.if_name, tname, 16))
210 return;
211 tname[15] = '\0';
212 ifnetaddr = (u_long)ifnet.if_link.tqe_next;
212 ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
213 snprintf(name, 32, "%s%d", tname, ifnet.if_unit);
214 if (interface != 0 && (strcmp(name, interface) != 0))
215 continue;
216 cp = index(name, '\0');
217
218 if (pfunc) {
219 (*pfunc)(name);
220 continue;
221 }
222
223 if ((ifnet.if_flags&IFF_UP) == 0)
224 *cp++ = '*';
225 *cp = '\0';
213 snprintf(name, 32, "%s%d", tname, ifnet.if_unit);
214 if (interface != 0 && (strcmp(name, interface) != 0))
215 continue;
216 cp = index(name, '\0');
217
218 if (pfunc) {
219 (*pfunc)(name);
220 continue;
221 }
222
223 if ((ifnet.if_flags&IFF_UP) == 0)
224 *cp++ = '*';
225 *cp = '\0';
226 ifaddraddr = (u_long)ifnet.if_addrhead.tqh_first;
226 ifaddraddr = (u_long)TAILQ_FIRST(&ifnet.if_addrhead);
227 }
228 printf("%-5.5s %-5lu ", name, ifnet.if_mtu);
229 ifaddrfound = ifaddraddr;
230
231 /*
232 * Get the interface stats. These may get
233 * overriden below on a per-interface basis.
234 */

--- 127 unchanged lines hidden (view full) ---

362 opackets = ifaddr.in.ia_ifa.if_opackets;
363 ipackets = ifaddr.in.ia_ifa.if_ipackets;
364 obytes = ifaddr.in.ia_ifa.if_obytes;
365 ibytes = ifaddr.in.ia_ifa.if_ibytes;
366 oerrors = ierrors = 0;
367 collisions = timer = drops = 0;
368 }
369
227 }
228 printf("%-5.5s %-5lu ", name, ifnet.if_mtu);
229 ifaddrfound = ifaddraddr;
230
231 /*
232 * Get the interface stats. These may get
233 * overriden below on a per-interface basis.
234 */

--- 127 unchanged lines hidden (view full) ---

362 opackets = ifaddr.in.ia_ifa.if_opackets;
363 ipackets = ifaddr.in.ia_ifa.if_ipackets;
364 obytes = ifaddr.in.ia_ifa.if_obytes;
365 ibytes = ifaddr.in.ia_ifa.if_ibytes;
366 oerrors = ierrors = 0;
367 collisions = timer = drops = 0;
368 }
369
370 ifaddraddr = (u_long)ifaddr.ifa.ifa_link.tqe_next;
370 ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
371 }
372
373 printf("%8lu %5lu ", ipackets, ierrors);
374 if (bflag)
375 printf("%10lu ", ibytes);
376 printf("%8lu %5lu ", opackets, oerrors);
377 if (bflag)
378 printf("%10lu ", obytes);
379 printf("%5lu", collisions);
380 if (tflag)
381 printf(" %3d", timer);
382 if (dflag)
383 printf(" %3d", drops);
384 putchar('\n');
385 if (aflag && ifaddrfound) {
386 /*
387 * Print family's multicast addresses
388 */
371 }
372
373 printf("%8lu %5lu ", ipackets, ierrors);
374 if (bflag)
375 printf("%10lu ", ibytes);
376 printf("%8lu %5lu ", opackets, oerrors);
377 if (bflag)
378 printf("%10lu ", obytes);
379 printf("%5lu", collisions);
380 if (tflag)
381 printf(" %3d", timer);
382 if (dflag)
383 printf(" %3d", drops);
384 putchar('\n');
385 if (aflag && ifaddrfound) {
386 /*
387 * Print family's multicast addresses
388 */
389 u_long multiaddr;
389 struct ifmultiaddr *multiaddr;
390 struct ifmultiaddr ifma;
391 union {
392 struct sockaddr sa;
393 struct sockaddr_in in;
394#ifdef INET6
395 struct sockaddr_in6 in6;
396#endif /* INET6 */
397 struct sockaddr_dl dl;
398 } msa;
399 const char *fmt;
400
390 struct ifmultiaddr ifma;
391 union {
392 struct sockaddr sa;
393 struct sockaddr_in in;
394#ifdef INET6
395 struct sockaddr_in6 in6;
396#endif /* INET6 */
397 struct sockaddr_dl dl;
398 } msa;
399 const char *fmt;
400
401 for(multiaddr = (u_long)ifnet.if_multiaddrs.lh_first;
402 multiaddr;
403 multiaddr = (u_long)ifma.ifma_link.le_next) {
404 if (kread(multiaddr, (char *)&ifma,
401 LIST_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
402 if (kread(*(u_long *)multiaddr, (char *)&ifma,
405 sizeof ifma))
406 break;
407 if (kread((u_long)ifma.ifma_addr, (char *)&msa,
408 sizeof msa))
409 break;
410 if (msa.sa.sa_family != sa->sa_family)
411 continue;
412

--- 25 unchanged lines hidden (view full) ---

438 if (fmt)
439 printf("%23s %s\n", "", fmt);
440 }
441 }
442 }
443}
444
445struct iftot {
403 sizeof ifma))
404 break;
405 if (kread((u_long)ifma.ifma_addr, (char *)&msa,
406 sizeof msa))
407 break;
408 if (msa.sa.sa_family != sa->sa_family)
409 continue;
410

--- 25 unchanged lines hidden (view full) ---

436 if (fmt)
437 printf("%23s %s\n", "", fmt);
438 }
439 }
440 }
441}
442
443struct iftot {
446 struct iftot *ift_next; /* next element list*/
444 SLIST_ENTRY(iftot) chain;
447 char ift_name[16]; /* interface name */
448 u_long ift_ip; /* input packets */
449 u_long ift_ie; /* input errors */
450 u_long ift_op; /* output packets */
451 u_long ift_oe; /* output errors */
452 u_long ift_co; /* collisions */
453 u_int ift_dr; /* drops */
454 u_long ift_ib; /* input bytes */

--- 19 unchanged lines hidden (view full) ---

474 struct ifnethead ifnethead;
475 struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
476 register int line;
477 int oldmask, first;
478 u_long interesting_off;
479
480 if (kread(off, (char *)&ifnethead, sizeof ifnethead))
481 return;
445 char ift_name[16]; /* interface name */
446 u_long ift_ip; /* input packets */
447 u_long ift_ie; /* input errors */
448 u_long ift_op; /* output packets */
449 u_long ift_oe; /* output errors */
450 u_long ift_co; /* collisions */
451 u_int ift_dr; /* drops */
452 u_long ift_ib; /* input bytes */

--- 19 unchanged lines hidden (view full) ---

472 struct ifnethead ifnethead;
473 struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
474 register int line;
475 int oldmask, first;
476 u_long interesting_off;
477
478 if (kread(off, (char *)&ifnethead, sizeof ifnethead))
479 return;
482 firstifnet = (u_long)ifnethead.tqh_first;
480 firstifnet = (u_long)TAILQ_FIRST(&ifnethead);
483
484 if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
485 printf("malloc failed\n");
486 exit(1);
487 }
488 memset(iftot, 0, sizeof(struct iftot));
489
490 interesting = NULL;

--- 12 unchanged lines hidden (view full) ---

503 interesting_off = off;
504 }
505 snprintf(ip->ift_name, 16, "(%s)", name);;
506 if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
507 printf("malloc failed\n");
508 exit(1);
509 }
510 memset(ipn, 0, sizeof(struct iftot));
481
482 if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
483 printf("malloc failed\n");
484 exit(1);
485 }
486 memset(iftot, 0, sizeof(struct iftot));
487
488 interesting = NULL;

--- 12 unchanged lines hidden (view full) ---

501 interesting_off = off;
502 }
503 snprintf(ip->ift_name, 16, "(%s)", name);;
504 if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
505 printf("malloc failed\n");
506 exit(1);
507 }
508 memset(ipn, 0, sizeof(struct iftot));
511 ip->ift_next = ipn;
509 SLIST_NEXT(ip, chain) = ipn;
512 ip = ipn;
510 ip = ipn;
513 off = (u_long) ifnet.if_link.tqe_next;
511 off = (u_long)TAILQ_NEXT(&ifnet, if_link);
514 }
515 if ((total = malloc(sizeof(struct iftot))) == NULL) {
516 printf("malloc failed\n");
517 exit(1);
518 }
519 memset(total, 0, sizeof(struct iftot));
520 if ((sum = malloc(sizeof(struct iftot))) == NULL) {
521 printf("malloc failed\n");

--- 48 unchanged lines hidden (view full) ---

570 sum->ift_ip = 0;
571 sum->ift_ie = 0;
572 sum->ift_ib = 0;
573 sum->ift_op = 0;
574 sum->ift_oe = 0;
575 sum->ift_ob = 0;
576 sum->ift_co = 0;
577 sum->ift_dr = 0;
512 }
513 if ((total = malloc(sizeof(struct iftot))) == NULL) {
514 printf("malloc failed\n");
515 exit(1);
516 }
517 memset(total, 0, sizeof(struct iftot));
518 if ((sum = malloc(sizeof(struct iftot))) == NULL) {
519 printf("malloc failed\n");

--- 48 unchanged lines hidden (view full) ---

568 sum->ift_ip = 0;
569 sum->ift_ie = 0;
570 sum->ift_ib = 0;
571 sum->ift_op = 0;
572 sum->ift_oe = 0;
573 sum->ift_ob = 0;
574 sum->ift_co = 0;
575 sum->ift_dr = 0;
578 for (off = firstifnet, ip = iftot; off && ip->ift_next != NULL;
579 ip = ip->ift_next) {
576 for (off = firstifnet, ip = iftot;
577 off && SLIST_NEXT(ip, chain) != NULL;
578 ip = SLIST_NEXT(ip, chain)) {
580 if (kread(off, (char *)&ifnet, sizeof ifnet)) {
581 off = 0;
582 continue;
583 }
584 sum->ift_ip += ifnet.if_ipackets;
585 sum->ift_ie += ifnet.if_ierrors;
586 sum->ift_ib += ifnet.if_ibytes;
587 sum->ift_op += ifnet.if_opackets;
588 sum->ift_oe += ifnet.if_oerrors;
589 sum->ift_ob += ifnet.if_obytes;
590 sum->ift_co += ifnet.if_collisions;
591 sum->ift_dr += ifnet.if_snd.ifq_drops;
579 if (kread(off, (char *)&ifnet, sizeof ifnet)) {
580 off = 0;
581 continue;
582 }
583 sum->ift_ip += ifnet.if_ipackets;
584 sum->ift_ie += ifnet.if_ierrors;
585 sum->ift_ib += ifnet.if_ibytes;
586 sum->ift_op += ifnet.if_opackets;
587 sum->ift_oe += ifnet.if_oerrors;
588 sum->ift_ob += ifnet.if_obytes;
589 sum->ift_co += ifnet.if_collisions;
590 sum->ift_dr += ifnet.if_snd.ifq_drops;
592 off = (u_long) ifnet.if_link.tqe_next;
591 off = (u_long)TAILQ_NEXT(&ifnet, if_link);
593 }
594 if (!first) {
595 printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
596 sum->ift_ip - total->ift_ip,
597 sum->ift_ie - total->ift_ie,
598 sum->ift_ib - total->ift_ib,
599 sum->ift_op - total->ift_op,
600 sum->ift_oe - total->ift_oe,

--- 36 unchanged lines hidden ---
592 }
593 if (!first) {
594 printf("%10lu %5lu %10lu %10lu %5lu %10lu %5lu",
595 sum->ift_ip - total->ift_ip,
596 sum->ift_ie - total->ift_ie,
597 sum->ift_ib - total->ift_ib,
598 sum->ift_op - total->ift_op,
599 sum->ift_oe - total->ift_oe,

--- 36 unchanged lines hidden ---