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

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

33
34#if 0
35#ifndef lint
36static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
37#endif /* not lint */
38#endif
39
40#include <sys/cdefs.h>
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

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

33
34#if 0
35#ifndef lint
36static 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: head/usr.bin/netstat/if.c 160787 2006-07-28 16:09:19Z yar $");
41__FBSDID("$FreeBSD: head/usr.bin/netstat/if.c 164095 2006-11-08 15:15:05Z bde $");
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>

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

127}
128
129/*
130 * Display a formatted value, or a '-' in the same space.
131 */
132static void
133show_stat(const char *fmt, int width, u_long value, short showvalue)
134{
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>

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

127}
128
129/*
130 * Display a formatted value, or a '-' in the same space.
131 */
132static void
133show_stat(const char *fmt, int width, u_long value, short showvalue)
134{
135 const char *lsep, *rsep;
135 char newfmt[32];
136
136 char newfmt[32];
137
138 lsep = "";
139 if (strncmp(fmt, "LS", 2) == 0) {
140 lsep = " ";
141 fmt += 2;
142 }
143 rsep = " ";
144 if (strncmp(fmt, "NRS", 3) == 0) {
145 rsep = "";
146 fmt += 3;
147 }
137 if (showvalue == 0) {
138 /* Print just dash. */
148 if (showvalue == 0) {
149 /* Print just dash. */
139 sprintf(newfmt, "%%%ds ", width);
150 sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
140 printf(newfmt, "-");
141 return;
142 }
143
144 if (hflag) {
145 char buf[5];
146
147 /* Format in human readable form. */
148 humanize_number(buf, sizeof(buf), (int64_t)value, "",
149 HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
151 printf(newfmt, "-");
152 return;
153 }
154
155 if (hflag) {
156 char buf[5];
157
158 /* Format in human readable form. */
159 humanize_number(buf, sizeof(buf), (int64_t)value, "",
160 HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
150 sprintf(newfmt, "%%%ds ", width);
161 sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
151 printf(newfmt, buf);
152 } else {
153 /* Construct the format string. */
162 printf(newfmt, buf);
163 } else {
164 /* Construct the format string. */
154 sprintf(newfmt, "%%%d%s ", width, fmt);
165 sprintf(newfmt, "%s%%%d%s%s", lsep, width, fmt, rsep);
155 printf(newfmt, value);
156 }
157}
158
159/*
160 * Print a description of the network interfaces.
161 */
162void

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

410 if (bflag)
411 show_stat("lu", 10, ibytes, link_layer|network_layer);
412
413 show_stat("lu", 8, opackets, link_layer|network_layer);
414 show_stat("lu", 5, oerrors, link_layer);
415 if (bflag)
416 show_stat("lu", 10, obytes, link_layer|network_layer);
417
166 printf(newfmt, value);
167 }
168}
169
170/*
171 * Print a description of the network interfaces.
172 */
173void

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

421 if (bflag)
422 show_stat("lu", 10, ibytes, link_layer|network_layer);
423
424 show_stat("lu", 8, opackets, link_layer|network_layer);
425 show_stat("lu", 5, oerrors, link_layer);
426 if (bflag)
427 show_stat("lu", 10, obytes, link_layer|network_layer);
428
418 show_stat("lu", 5, collisions, link_layer);
429 show_stat("NRSlu", 5, collisions, link_layer);
419 if (tflag)
430 if (tflag)
420 show_stat("d", 4, timer, link_layer);
421
431 show_stat("LSd", 4, timer, link_layer);
422 if (dflag)
432 if (dflag)
423 show_stat("d", 4, drops, link_layer);
424
433 show_stat("LSd", 4, drops, link_layer);
425 putchar('\n');
434 putchar('\n');
435
426 if (aflag && ifaddrfound) {
427 /*
428 * Print family's multicast addresses
429 */
430 struct ifmultiaddr *multiaddr;
431 struct ifmultiaddr ifma;
432 union {
433 struct sockaddr sa;

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

595 };
596 if (!first) {
597 show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1);
598 show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1);
599 show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1);
600 show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1);
601 show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1);
602 show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1);
436 if (aflag && ifaddrfound) {
437 /*
438 * Print family's multicast addresses
439 */
440 struct ifmultiaddr *multiaddr;
441 struct ifmultiaddr ifma;
442 union {
443 struct sockaddr sa;

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

605 };
606 if (!first) {
607 show_stat("lu", 10, ifnet.if_ipackets - ip->ift_ip, 1);
608 show_stat("lu", 5, ifnet.if_ierrors - ip->ift_ie, 1);
609 show_stat("lu", 10, ifnet.if_ibytes - ip->ift_ib, 1);
610 show_stat("lu", 10, ifnet.if_opackets - ip->ift_op, 1);
611 show_stat("lu", 5, ifnet.if_oerrors - ip->ift_oe, 1);
612 show_stat("lu", 10, ifnet.if_obytes - ip->ift_ob, 1);
603 show_stat("lu", 5, ifnet.if_collisions - ip->ift_co, 1);
613 show_stat("NRSlu", 5,
614 ifnet.if_collisions - ip->ift_co, 1);
604 if (dflag)
615 if (dflag)
605 show_stat("u", 5,
616 show_stat("LSu", 5,
606 ifnet.if_snd.ifq_drops - ip->ift_dr, 1);
607 }
608 ip->ift_ip = ifnet.if_ipackets;
609 ip->ift_ie = ifnet.if_ierrors;
610 ip->ift_ib = ifnet.if_ibytes;
611 ip->ift_op = ifnet.if_opackets;
612 ip->ift_oe = ifnet.if_oerrors;
613 ip->ift_ob = ifnet.if_obytes;

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

641 }
642 if (!first) {
643 show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1);
644 show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1);
645 show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1);
646 show_stat("lu", 10, sum->ift_op - total->ift_op, 1);
647 show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1);
648 show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1);
617 ifnet.if_snd.ifq_drops - ip->ift_dr, 1);
618 }
619 ip->ift_ip = ifnet.if_ipackets;
620 ip->ift_ie = ifnet.if_ierrors;
621 ip->ift_ib = ifnet.if_ibytes;
622 ip->ift_op = ifnet.if_opackets;
623 ip->ift_oe = ifnet.if_oerrors;
624 ip->ift_ob = ifnet.if_obytes;

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

652 }
653 if (!first) {
654 show_stat("lu", 10, sum->ift_ip - total->ift_ip, 1);
655 show_stat("lu", 5, sum->ift_ie - total->ift_ie, 1);
656 show_stat("lu", 10, sum->ift_ib - total->ift_ib, 1);
657 show_stat("lu", 10, sum->ift_op - total->ift_op, 1);
658 show_stat("lu", 5, sum->ift_oe - total->ift_oe, 1);
659 show_stat("lu", 10, sum->ift_ob - total->ift_ob, 1);
649 show_stat("lu", 5, sum->ift_co - total->ift_co, 1);
660 show_stat("NRSlu", 5, sum->ift_co - total->ift_co, 1);
650 if (dflag)
661 if (dflag)
651 show_stat("u", 5,
662 show_stat("LSu", 5,
652 sum->ift_dr - total->ift_dr, 1);
653 }
654 *total = *sum;
655 }
656 if (!first)
657 putchar('\n');
658 fflush(stdout);
659 oldmask = sigblock(sigmask(SIGALRM));

--- 24 unchanged lines hidden ---
663 sum->ift_dr - total->ift_dr, 1);
664 }
665 *total = *sum;
666 }
667 if (!first)
668 putchar('\n');
669 fflush(stdout);
670 oldmask = sigblock(sigmask(SIGALRM));

--- 24 unchanged lines hidden ---