diff options
author | delphij <delphij@FreeBSD.org> | 2010-02-10 00:34:13 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2010-02-10 00:34:13 +0000 |
commit | 56c6dfba43330adcd014d353900bc76289b651d9 (patch) | |
tree | 7bf04e0b348da197a4f59f9c383c1bdf8de02f29 /usr.bin | |
parent | 09b661ed8df65a1c5e108bbf6919342962658eb5 (diff) | |
download | FreeBSD-src-56c6dfba43330adcd014d353900bc76289b651d9.zip FreeBSD-src-56c6dfba43330adcd014d353900bc76289b651d9.tar.gz |
MFC r202060:
Add a new option, -q howmany, which when used in conjuction with -w,
exits netstat after _howmany_ outputs.
Requested by: thomasa
Reviewed by: freebsd-net (bms, old version in early 2007)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/if.c | 2 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 10 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 8 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 1 |
4 files changed, 18 insertions, 3 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index e9e77b9..99a820a 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -685,6 +685,8 @@ loop: if (!first) putchar('\n'); fflush(stdout); + if ((noutputs != 0) && (--noutputs == 0)) + exit(0); oldmask = sigblock(sigmask(SIGALRM)); while (!signalled) sigpause(0); diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index ebbe1d2..7a6dc73 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -332,6 +332,7 @@ int hflag; /* show counters in human readable format */ int iflag; /* show interfaces */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ +int noutputs = 0; /* how much outputs before we exit */ int numeric_addr; /* show addresses numerically */ int numeric_port; /* show ports numerically */ static int pflag; /* show given protocol */ @@ -358,7 +359,7 @@ main(int argc, char *argv[]) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:xz")) != -1) + while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSstuWw:xz")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -444,6 +445,11 @@ main(int argc, char *argv[]) } pflag = 1; break; + case 'q': + noutputs = atoi(optarg); + if (noutputs != 0) + noutputs++; + break; case 'r': rflag = 1; break; @@ -780,7 +786,7 @@ usage(void) " [-M core] [-N system]", " netstat -i | -I interface [-abdhntW] [-f address_family]\n" " [-M core] [-N system]", -" netstat -w wait [-I interface] [-d] [-M core] [-N system]", +" netstat -w wait [-I interface] [-d] [-M core] [-N system] [-q howmany]", " netstat -s [-s] [-z] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -i | -I interface -s [-f protocol_family | -p protocol]\n" diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 41e15c1..872ff95 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -32,7 +32,7 @@ .\" @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd July 9, 2009 +.Dd January 10, 2010 .Dt NETSTAT 1 .Os .Sh NAME @@ -136,6 +136,7 @@ is also present, print interface names using a wider field size. .Op Fl d .Op Fl M Ar core .Op Fl N Ar system +.Op Fl q Ar howmany .Ek .Xc At intervals of @@ -146,6 +147,11 @@ traffic on all configured network interfaces or a single .Ar interface . If +.Fl q +is also present, exit after +.Ar howmany +outputs. +If .Fl d is also present, show the number of dropped packets. .It Xo diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index f834495..7594464 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -45,6 +45,7 @@ extern int hflag; /* show counters in human readable format */ extern int iflag; /* show interfaces */ extern int Lflag; /* show size of listen queues */ extern int mflag; /* show memory stats */ +extern int noutputs; /* how much outputs before we exit */ extern int numeric_addr; /* show addresses numerically */ extern int numeric_port; /* show ports numerically */ extern int rflag; /* show routing tables (or routing stats) */ |