Noticed that netstat doesn't have a repeat count option like vmstat does.
Index: if.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/if.c,v
retrieving revision 1.61
diff -u -r1.61 if.c
--- if.c 4 Aug 2009 03:45:47 -0000 1.61
+++ if.c 20 Aug 2009 00:27:31 -0000
@@ -56,7 +56,7 @@
#include "netstat.h"
static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data
*);
-static void sidewaysintpr(u_int);
+static void sidewaysintpr(u_int, int);
static void catchalarm(int);
static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
static void fetchifs(void);
@@ -67,7 +67,7 @@
* which is a TAILQ_HEAD.
*/
void
-intpr(int interval)
+intpr(int interval, int repeatcount)
{
struct if_msghdr ifm;
int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
@@ -82,7 +82,7 @@
size_t len;
if (interval) {
- sidewaysintpr((unsigned)interval);
+ sidewaysintpr((unsigned)interval, repeatcount);
return;
}
@@ -350,7 +350,7 @@
* First line printed at top of screen is always cumulative.
*/
static void
-sidewaysintpr(unsigned int interval)
+sidewaysintpr(unsigned int interval, int repeatcount)
{
sigset_t emptyset;
int line;
@@ -449,6 +449,8 @@
putchar('\n');
fflush(stdout);
+ if (repeatcount && --repeatcount == 0)
+ return;
line++;
sigemptyset(&emptyset);
if (!signalled)
@@ -458,7 +460,6 @@
if (line == 21)
goto banner;
goto loop;
- /*NOTREACHED*/
}
/*
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.79
diff -u -r1.79 main.c
--- main.c 7 May 2009 15:51:53 -0000 1.79
+++ main.c 20 Aug 2009 00:27:33 -0000
@@ -155,10 +155,11 @@
gid_t gid;
u_long pcbaddr = 0;
u_int tableid = 0;
+ int repeatcount = 0;
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "AabdFf:gI:ilM:mN:np:P:qrsT:tuvW:w:"))
!= -1)
+ while ((ch = getopt(argc, argv,
"Aabc:dFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -169,6 +170,9 @@
case 'b':
bflag = 1;
break;
+ case 'c':
+ repeatcount = strtonum(optarg, 1, INT_MAX, &errstr);
+ break;
case 'd':
dflag = 1;
break;
@@ -369,7 +373,7 @@
setnetent(1);
if (iflag) {
- intpr(interval);
+ intpr(interval, repeatcount);
exit(0);
}
if (rflag) {
Index: netstat.h
===================================================================
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.50
diff -u -r1.50 netstat.h
--- netstat.h 7 May 2009 15:51:53 -0000 1.50
+++ netstat.h 20 Aug 2009 00:27:33 -0000
@@ -129,7 +129,7 @@
void nsprotopr(u_long, char *);
-void intpr(int);
+void intpr(int, int);
void unixpr(u_long);