summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authordg <dg@FreeBSD.org>1994-10-12 02:37:35 +0000
committerdg <dg@FreeBSD.org>1994-10-12 02:37:35 +0000
commitec62e724b8eecbb45b5b63e1fa140326e65d35c3 (patch)
treee94d6d5f55ebb3a4e703c96fd221078d5730be6e /usr.bin/netstat
parentbdd76ad243b9f88ad1b56b11f205255f509573f6 (diff)
downloadFreeBSD-src-ec62e724b8eecbb45b5b63e1fa140326e65d35c3.zip
FreeBSD-src-ec62e724b8eecbb45b5b63e1fa140326e65d35c3.tar.gz
Added '-b' option to display the number of in and out bytes on a given
interface (used with -i and -I flag).
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/if.c102
-rw-r--r--usr.bin/netstat/main.c9
-rw-r--r--usr.bin/netstat/netstat.19
-rw-r--r--usr.bin/netstat/netstat.h1
4 files changed, 86 insertions, 35 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index f99e84a..b656681 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -91,9 +91,13 @@ intpr(interval, ifnetaddr)
}
if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr))
return;
- printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
- "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
- "Opkts", "Oerrs");
+ printf("%-5.5s %-5.5s %-11.11s %-15.15s %8.8s %5.5s",
+ "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+ if (bflag)
+ printf(" %10.10s","Ibytes");
+ printf(" %8.8s %5.5s", "Opkts", "Oerrs");
+ if (bflag)
+ printf(" %10.10s","Obytes");
printf(" %5s", "Coll");
if (tflag)
printf(" %s", "Time");
@@ -198,10 +202,15 @@ intpr(interval, ifnetaddr)
}
ifaddraddr = (u_long)ifaddr.ifa.ifa_next;
}
- printf("%8d %5d %8d %5d %5d",
- ifnet.if_ipackets, ifnet.if_ierrors,
- ifnet.if_opackets, ifnet.if_oerrors,
- ifnet.if_collisions);
+ printf("%8d %5d ",
+ ifnet.if_ipackets, ifnet.if_ierrors);
+ if (bflag)
+ printf("%10d ", ifnet.if_ibytes);
+ printf("%8d %5d ",
+ ifnet.if_opackets, ifnet.if_oerrors);
+ if (bflag)
+ printf("%10d ", ifnet.if_obytes);
+ printf("%5d", ifnet.if_collisions);
if (tflag)
printf(" %3d", ifnet.if_timer);
if (dflag)
@@ -213,12 +222,14 @@ intpr(interval, ifnetaddr)
#define MAXIF 10
struct iftot {
char ift_name[16]; /* interface name */
- int ift_ip; /* input packets */
- int ift_ie; /* input errors */
- int ift_op; /* output packets */
- int ift_oe; /* output errors */
- int ift_co; /* collisions */
- int ift_dr; /* drops */
+ u_int ift_ip; /* input packets */
+ u_int ift_ie; /* input errors */
+ u_int ift_op; /* output packets */
+ u_int ift_oe; /* output errors */
+ u_int ift_co; /* collisions */
+ u_int ift_dr; /* drops */
+ u_int ift_ib; /* input bytes */
+ u_int ift_ob; /* output bytes */
} iftot[MAXIF];
u_char signalled; /* set if alarm goes off "early" */
@@ -272,11 +283,13 @@ sidewaysintpr(interval, off)
signalled = NO;
(void)alarm(interval);
banner:
- printf(" input %-6.6s output ", interesting->ift_name);
+ printf(" input %s%-6.6s %soutput ", bflag ? " " : "",
+ interesting->ift_name, bflag ? " " : "");
if (lastif - iftot > 0) {
if (dflag)
printf(" ");
- printf(" input (Total) output");
+ printf(" input %s(Total) %soutput", bflag ? " " : "",
+ bflag ? " " : "");
}
for (ip = iftot; ip < iftot + MAXIF; ip++) {
ip->ift_ip = 0;
@@ -285,17 +298,30 @@ banner:
ip->ift_oe = 0;
ip->ift_co = 0;
ip->ift_dr = 0;
+ ip->ift_ib = 0;
+ ip->ift_ob = 0;
}
putchar('\n');
- printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
- "packets", "errs", "packets", "errs", "colls");
+ printf("%8.8s %5.5s ", "packets", "errs");
+ if (bflag)
+ printf("%10.10s ","bytes");
+ printf("%8.8s %5.5s ", "packets", "errs");
+ if (bflag)
+ printf("%10.10s ","bytes");
+ printf("%5.5s ", "colls");
if (dflag)
printf("%5.5s ", "drops");
- if (lastif - iftot > 0)
- printf(" %8.8s %5.5s %8.8s %5.5s %5.5s",
- "packets", "errs", "packets", "errs", "colls");
- if (dflag)
- printf(" %5.5s", "drops");
+ if (lastif - iftot > 0) {
+ printf(" %8.8s %5.5s", "packets", "errs");
+ if (bflag)
+ printf(" %10.10s", "bytes");
+ printf(" %8.8s %5.5s", "packets", "errs");
+ if (bflag)
+ printf(" %10.10s", "bytes");
+ printf(" %5.5s", "colls");
+ if (dflag)
+ printf(" %5.5s", "drops");
+ }
putchar('\n');
fflush(stdout);
line = 0;
@@ -306,18 +332,25 @@ loop:
sum->ift_oe = 0;
sum->ift_co = 0;
sum->ift_dr = 0;
+ sum->ift_ib = 0;
+ sum->ift_ob = 0;
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
if (kread(off, (char *)&ifnet, sizeof ifnet)) {
off = 0;
continue;
}
if (ip == interesting) {
- printf("%8d %5d %8d %5d %5d",
+ printf("%8d %5d ",
ifnet.if_ipackets - ip->ift_ip,
- ifnet.if_ierrors - ip->ift_ie,
+ ifnet.if_ierrors - ip->ift_ie);
+ if (bflag)
+ printf("%10d ", ifnet.if_ibytes - ip->ift_ib);
+ printf("%8d %5d ",
ifnet.if_opackets - ip->ift_op,
- ifnet.if_oerrors - ip->ift_oe,
- ifnet.if_collisions - ip->ift_co);
+ ifnet.if_oerrors - ip->ift_oe);
+ if (bflag)
+ printf("%10d ", ifnet.if_obytes - ip->ift_ob);
+ printf("%5d", ifnet.if_collisions - ip->ift_co);
if (dflag)
printf(" %5d",
ifnet.if_snd.ifq_drops - ip->ift_dr);
@@ -328,21 +361,30 @@ loop:
ip->ift_oe = ifnet.if_oerrors;
ip->ift_co = ifnet.if_collisions;
ip->ift_dr = ifnet.if_snd.ifq_drops;
+ ip->ift_ib = ifnet.if_ibytes;
+ ip->ift_ob = ifnet.if_obytes;
sum->ift_ip += ip->ift_ip;
sum->ift_ie += ip->ift_ie;
sum->ift_op += ip->ift_op;
sum->ift_oe += ip->ift_oe;
sum->ift_co += ip->ift_co;
sum->ift_dr += ip->ift_dr;
+ sum->ift_ib += ip->ift_ib;
+ sum->ift_ob += ip->ift_ob;
off = (u_long) ifnet.if_next;
}
if (lastif - iftot > 0) {
- printf(" %8d %5d %8d %5d %5d",
+ printf(" %8d %5d",
sum->ift_ip - total->ift_ip,
- sum->ift_ie - total->ift_ie,
+ sum->ift_ie - total->ift_ie);
+ if (bflag)
+ printf(" %10d", sum->ift_ib - total->ift_ib);
+ printf(" %8d %5d",
sum->ift_op - total->ift_op,
- sum->ift_oe - total->ift_oe,
- sum->ift_co - total->ift_co);
+ sum->ift_oe - total->ift_oe);
+ if (bflag)
+ printf(" %10d", sum->ift_ob - total->ift_ob);
+ printf(" %5d", sum->ift_co - total->ift_co);
if (dflag)
printf(" %5d", sum->ift_dr - total->ift_dr);
}
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 6d30186..deed78b 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -202,7 +202,7 @@ main(argc, argv)
prog = argv[0];
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aadf:ghI:iM:mN:np:rstuw:")) != EOF)
+ while ((ch = getopt(argc, argv, "Aabdf:ghI:iM:mN:np:rstuw:")) != EOF)
switch(ch) {
case 'A':
Aflag = 1;
@@ -210,6 +210,9 @@ main(argc, argv)
case 'a':
aflag = 1;
break;
+ case 'b':
+ bflag = 1;
+ break;
case 'd':
dflag = 1;
break;
@@ -499,9 +502,9 @@ usage()
(void)fprintf(stderr,
"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog);
(void)fprintf(stderr,
-" %s [-ghimnrs] [-f address_family] [-M core] [-N system]\n", prog);
+" %s [-bdghimnrs] [-f address_family] [-M core] [-N system]\n", prog);
(void)fprintf(stderr,
-" %s [-n] [-I interface] [-M core] [-N system] [-w wait]\n", prog);
+" %s [-bdn] [-I interface] [-M core] [-N system] [-w wait]\n", prog);
(void)fprintf(stderr,
" %s [-M core] [-N system] [-p protocol]\n", prog);
exit(1);
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index bf9d60e..9d58382 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -44,12 +44,12 @@
.Op Fl M Ar core
.Op Fl N Ar system
.Nm netstat
-.Op Fl dghimnrs
+.Op Fl bdghimnrs
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
.Nm netstat
-.Op Fl dn
+.Op Fl bdn
.Op Fl I Ar interface
.Op Fl M Ar core
.Op Fl N Ar system
@@ -87,6 +87,11 @@ for debugging.
With the default display,
show the state of all sockets; normally sockets used by
server processes are not shown.
+.It Fl b
+With either interface display (option
+.Fl i
+or an interval, as described below),
+show the number of bytes in and out.
.It Fl d
With either interface display (option
.Fl i
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 8f2aa1f..aa93f19 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -37,6 +37,7 @@
int Aflag; /* show addresses of protocol control block */
int aflag; /* show all sockets (including servers) */
+int bflag; /* show i/f total bytes in/out */
int dflag; /* show i/f dropped packets */
int gflag; /* show group (multicast) routing or stats */
int iflag; /* show interfaces */
OpenPOWER on IntegriCloud