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) MFC after: 1 month
This commit is contained in:
@@ -679,6 +679,8 @@ sidewaysintpr(int interval1, u_long off)
|
|||||||
if (!first)
|
if (!first)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
if ((noutputs != 0) && (--noutputs == 0))
|
||||||
|
exit(0);
|
||||||
oldmask = sigblock(sigmask(SIGALRM));
|
oldmask = sigblock(sigmask(SIGALRM));
|
||||||
while (!signalled)
|
while (!signalled)
|
||||||
sigpause(0);
|
sigpause(0);
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ int hflag; /* show counters in human readable format */
|
|||||||
int iflag; /* show interfaces */
|
int iflag; /* show interfaces */
|
||||||
int Lflag; /* show size of listen queues */
|
int Lflag; /* show size of listen queues */
|
||||||
int mflag; /* show memory stats */
|
int mflag; /* show memory stats */
|
||||||
|
int noutputs = 0; /* how much outputs before we exit */
|
||||||
int numeric_addr; /* show addresses numerically */
|
int numeric_addr; /* show addresses numerically */
|
||||||
int numeric_port; /* show ports numerically */
|
int numeric_port; /* show ports numerically */
|
||||||
static int pflag; /* show given protocol */
|
static int pflag; /* show given protocol */
|
||||||
@@ -359,7 +360,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
af = AF_UNSPEC;
|
af = AF_UNSPEC;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSsuWw:xz")) != -1)
|
while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSsuWw:xz")) != -1)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'A':
|
case 'A':
|
||||||
Aflag = 1;
|
Aflag = 1;
|
||||||
@@ -445,6 +446,11 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
pflag = 1;
|
pflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
noutputs = atoi(optarg);
|
||||||
|
if (noutputs != 0)
|
||||||
|
noutputs++;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
rflag = 1;
|
rflag = 1;
|
||||||
break;
|
break;
|
||||||
@@ -779,7 +785,7 @@ usage(void)
|
|||||||
" [-M core] [-N system]",
|
" [-M core] [-N system]",
|
||||||
" netstat -i | -I interface [-abdhnW] [-f address_family]\n"
|
" netstat -i | -I interface [-abdhnW] [-f address_family]\n"
|
||||||
" [-M core] [-N system]",
|
" [-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"
|
" netstat -s [-s] [-z] [-f protocol_family | -p protocol]\n"
|
||||||
" [-M core] [-N system]",
|
" [-M core] [-N system]",
|
||||||
" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n"
|
" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
|
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 9, 2009
|
.Dd January 10, 2010
|
||||||
.Dt NETSTAT 1
|
.Dt NETSTAT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -133,6 +133,7 @@ is also present, print interface names using a wider field size.
|
|||||||
.Op Fl d
|
.Op Fl d
|
||||||
.Op Fl M Ar core
|
.Op Fl M Ar core
|
||||||
.Op Fl N Ar system
|
.Op Fl N Ar system
|
||||||
|
.Op Fl q Ar howmany
|
||||||
.Ek
|
.Ek
|
||||||
.Xc
|
.Xc
|
||||||
At intervals of
|
At intervals of
|
||||||
@@ -143,6 +144,11 @@ traffic on all configured network interfaces
|
|||||||
or a single
|
or a single
|
||||||
.Ar interface .
|
.Ar interface .
|
||||||
If
|
If
|
||||||
|
.Fl q
|
||||||
|
is also present, exit after
|
||||||
|
.Ar howmany
|
||||||
|
outputs.
|
||||||
|
If
|
||||||
.Fl d
|
.Fl d
|
||||||
is also present, show the number of dropped packets.
|
is also present, show the number of dropped packets.
|
||||||
.It Xo
|
.It Xo
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ extern int hflag; /* show counters in human readable format */
|
|||||||
extern int iflag; /* show interfaces */
|
extern int iflag; /* show interfaces */
|
||||||
extern int Lflag; /* show size of listen queues */
|
extern int Lflag; /* show size of listen queues */
|
||||||
extern int mflag; /* show memory stats */
|
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_addr; /* show addresses numerically */
|
||||||
extern int numeric_port; /* show ports numerically */
|
extern int numeric_port; /* show ports numerically */
|
||||||
extern int rflag; /* show routing tables (or routing stats) */
|
extern int rflag; /* show routing tables (or routing stats) */
|
||||||
|
|||||||
Reference in New Issue
Block a user