2011-12-06 18:15:09 +00:00
|
|
|
diff -up net-tools-1.60/lib/interface.c.cycle net-tools-1.60/lib/interface.c
|
2011-12-07 16:43:22 +00:00
|
|
|
--- net-tools-1.60/lib/interface.c.cycle 2011-11-21 02:31:57.000000000 +0100
|
|
|
|
+++ net-tools-1.60/lib/interface.c 2011-12-07 16:11:38.249768234 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -93,6 +93,7 @@ int if_list_all = 0; /* do we have reque
|
2004-09-09 09:10:03 +00:00
|
|
|
static struct interface *int_list, *int_last;
|
|
|
|
|
|
|
|
static int if_readlist_proc(char *);
|
|
|
|
+static int if_readlist_rep(char *, struct interface *);
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
static struct interface *if_cache_add(char *name)
|
2004-09-09 09:10:03 +00:00
|
|
|
{
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -138,11 +139,14 @@ struct interface *lookup_interface(char
|
2004-09-09 09:10:03 +00:00
|
|
|
int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
|
|
|
|
{
|
|
|
|
struct interface *ife;
|
|
|
|
+ int err;
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
if (!if_list_all && (if_readlist() < 0))
|
2004-09-09 09:10:03 +00:00
|
|
|
return -1;
|
|
|
|
for (ife = int_list; ife; ife = ife->next) {
|
|
|
|
- int err = doit(ife, cookie);
|
2011-12-06 18:15:09 +00:00
|
|
|
+ if_readlist_rep(ife->name, ife);
|
2004-09-09 09:10:03 +00:00
|
|
|
+ err = doit(ife, cookie);
|
2011-12-06 18:15:09 +00:00
|
|
|
+
|
2004-09-09 09:10:03 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -376,6 +380,41 @@ static int if_readlist_proc(char *target
|
|
|
|
fclose(fh);
|
2004-09-09 09:10:03 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+static int if_readlist_rep(char *target, struct interface *ife)
|
|
|
|
+{
|
|
|
|
+ FILE *fh;
|
|
|
|
+ char buf[512];
|
|
|
|
+ int err;
|
|
|
|
+
|
|
|
|
+ fh = fopen(_PATH_PROCNET_DEV, "r");
|
|
|
|
+ if (!fh) {
|
|
|
|
+ fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
|
|
|
|
+ _PATH_PROCNET_DEV, strerror(errno));
|
|
|
|
+ return if_readconf();
|
|
|
|
+ }
|
|
|
|
+ fgets(buf, sizeof buf, fh); /* eat line */
|
|
|
|
+ fgets(buf, sizeof buf, fh);
|
|
|
|
+
|
|
|
|
+ procnetdev_vsn = procnetdev_version(buf);
|
|
|
|
+
|
|
|
|
+ err = 0;
|
|
|
|
+ while (fgets(buf, sizeof buf, fh)) {
|
|
|
|
+ char *s, name[IFNAMSIZ];
|
|
|
|
+ s = get_name(name, buf);
|
|
|
|
+ get_dev_fields(s, ife);
|
|
|
|
+ ife->statistics_valid = 1;
|
|
|
|
+ if (target && !strcmp(target,name))
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (ferror(fh)) {
|
|
|
|
+ perror(_PATH_PROCNET_DEV);
|
|
|
|
+ err = -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fclose(fh);
|
|
|
|
+ return err;
|
|
|
|
+}
|
2011-12-06 18:15:09 +00:00
|
|
|
|
2004-09-09 09:10:03 +00:00
|
|
|
int if_readlist(void)
|
|
|
|
{
|
2011-12-06 18:15:09 +00:00
|
|
|
diff -up net-tools-1.60/man/en_US/netstat.8.cycle net-tools-1.60/man/en_US/netstat.8
|
|
|
|
--- net-tools-1.60/man/en_US/netstat.8.cycle 2011-11-21 02:31:57.000000000 +0100
|
2011-12-07 16:43:22 +00:00
|
|
|
+++ net-tools-1.60/man/en_US/netstat.8 2011-12-07 16:11:38.249768234 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -33,6 +33,7 @@ netstat \- Print network connections, ro
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-verbose | \-v ]
|
|
|
|
.RB [ \-\-continuous | \-c]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-wide | \-W]
|
2004-09-09 09:10:03 +00:00
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-route | \-r }
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -42,6 +43,7 @@ netstat \- Print network connections, ro
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-numeric | \-n ]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-continuous | \-c]
|
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-interfaces | \-i }
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -52,12 +54,14 @@ netstat \- Print network connections, ro
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-numeric | \-n ]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ]
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-continuous | \-c]
|
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-groups | \-g }
|
|
|
|
.RB [ \-\-numeric | \-n ]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-continuous | \-c]
|
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-masquerade | \-M }
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -65,6 +69,7 @@ netstat \- Print network connections, ro
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-numeric | \-n ]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-continuous | \-c]
|
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-statistics | -s }
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -72,6 +77,7 @@ netstat \- Print network connections, ro
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-udp | \-u ]
|
2011-12-06 18:15:09 +00:00
|
|
|
.RB [ \-\-udplite | \-U ]
|
2004-09-09 09:10:03 +00:00
|
|
|
.RB [ \-\-raw | \-w ]
|
|
|
|
+.RB [delay]
|
|
|
|
.P
|
|
|
|
.B netstat
|
|
|
|
.RB { \-\-version | \-V }
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -188,6 +194,10 @@ option, show interfaces that are not up
|
2004-09-09 09:10:03 +00:00
|
|
|
Print routing information from the FIB. (This is the default.)
|
|
|
|
.SS "\-C"
|
|
|
|
Print routing information from the route cache.
|
|
|
|
+.SS delay
|
|
|
|
+Netstat will cycle printing through statistics every
|
|
|
|
+.B delay
|
|
|
|
+seconds.
|
|
|
|
.P
|
|
|
|
.SH OUTPUT
|
2011-12-06 18:15:09 +00:00
|
|
|
.P
|
|
|
|
diff -up net-tools-1.60/netstat.c.cycle net-tools-1.60/netstat.c
|
2011-12-07 16:43:22 +00:00
|
|
|
--- net-tools-1.60/netstat.c.cycle 2011-11-21 02:31:57.000000000 +0100
|
|
|
|
+++ net-tools-1.60/netstat.c 2011-12-07 16:13:19.911497288 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -106,9 +106,9 @@
|
2004-09-09 09:10:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* prototypes for statistics.c */
|
|
|
|
-void parsesnmp(int, int, int);
|
|
|
|
+int parsesnmp(int, int, int);
|
|
|
|
void inittab(void);
|
2011-12-06 18:15:09 +00:00
|
|
|
-void parsesnmp6(int, int, int);
|
|
|
|
+int parsesnmp6(int, int, int);
|
|
|
|
void inittab6(void);
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -302,10 +302,10 @@ static void prg_cache_clear(void)
|
|
|
|
prg_cache_loaded=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void wait_continous(void)
|
|
|
|
+static void wait_continous(int reptimer)
|
|
|
|
{
|
|
|
|
fflush(stdout);
|
|
|
|
- sleep(1);
|
|
|
|
+ sleep(reptimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extract_type_1_socket_inode(const char lname[], unsigned long * inode_p) {
|
|
|
|
@@ -1610,6 +1610,8 @@ static int ipx_info(void)
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
static int iface_info(void)
|
|
|
|
{
|
|
|
|
+ static int count=0;
|
|
|
|
+
|
|
|
|
if (skfd < 0) {
|
|
|
|
if ((skfd = sockets_open(0)) < 0) {
|
|
|
|
perror("socket");
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1619,20 +1621,21 @@ static int iface_info(void)
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
if (flag_exp < 2) {
|
|
|
|
ife_short = 1;
|
2011-12-07 16:43:22 +00:00
|
|
|
- printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
2004-09-09 09:10:03 +00:00
|
|
|
+ if(!(count % 8))
|
2011-12-07 16:43:22 +00:00
|
|
|
+ printf(_("Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (for_all_interfaces(do_if_print, &flag_all) < 0) {
|
|
|
|
perror(_("missing interface information"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
- if (flag_cnt)
|
|
|
|
+ if (!flag_cnt) {
|
2011-12-06 18:15:09 +00:00
|
|
|
if_cache_free();
|
2004-09-09 09:10:03 +00:00
|
|
|
- else {
|
|
|
|
close(skfd);
|
|
|
|
skfd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ count++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1648,7 +1651,7 @@ static void usage(void)
|
2004-09-09 09:10:03 +00:00
|
|
|
{
|
2011-12-06 18:15:09 +00:00
|
|
|
fprintf(stderr, _("usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}\n"));
|
|
|
|
fprintf(stderr, _(" netstat [-vWnNcaeol] [<Socket> ...]\n"));
|
|
|
|
- fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n"));
|
|
|
|
+ fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n"));
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
fprintf(stderr, _(" -r, --route display routing table\n"));
|
|
|
|
fprintf(stderr, _(" -i, --interfaces display interface table\n"));
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1685,6 +1688,7 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
(int argc, char *argv[]) {
|
|
|
|
int i;
|
|
|
|
int lop;
|
|
|
|
+ int reptimer = 1;
|
2011-12-06 18:15:09 +00:00
|
|
|
static struct option longopts[] =
|
2004-09-09 09:10:03 +00:00
|
|
|
{
|
|
|
|
AFTRANS_OPTS,
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1844,6 +1848,12 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
flag_sta++;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if(argc == optind + 1) {
|
|
|
|
+ if((reptimer = atoi(argv[optind])) <= 0)
|
|
|
|
+ usage();
|
|
|
|
+ flag_cnt++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (flag_int + flag_rou + flag_mas + flag_sta > 1)
|
|
|
|
usage();
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1869,7 +1879,7 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
flag_not & FLAG_NUM_PORT, flag_exp);
|
|
|
|
if (i || !flag_cnt)
|
|
|
|
break;
|
2011-12-06 18:15:09 +00:00
|
|
|
- wait_continous();
|
|
|
|
+ wait_continous(reptimer);
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
#else
|
2011-12-06 18:15:09 +00:00
|
|
|
ENOSUPP("netstat", "FW_MASQUERADE");
|
|
|
|
@@ -1881,18 +1891,18 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
if (flag_sta) {
|
2011-12-06 18:15:09 +00:00
|
|
|
if (!afname[0])
|
|
|
|
strcpy(afname, DFLT_AF);
|
|
|
|
-
|
|
|
|
+ for (;;) {
|
|
|
|
if (!strcmp(afname, "inet")) {
|
|
|
|
#if HAVE_AFINET
|
|
|
|
inittab();
|
|
|
|
- parsesnmp(flag_raw, flag_tcp, flag_udp);
|
|
|
|
+ i = parsesnmp(flag_raw, flag_tcp, flag_udp);
|
|
|
|
#else
|
|
|
|
ENOSUPP("netstat", "AF INET");
|
|
|
|
#endif
|
|
|
|
} else if(!strcmp(afname, "inet6")) {
|
|
|
|
#if HAVE_AFINET6
|
|
|
|
inittab6();
|
|
|
|
- parsesnmp6(flag_raw, flag_tcp, flag_udp);
|
|
|
|
+ i = parsesnmp6(flag_raw, flag_tcp, flag_udp);
|
|
|
|
#else
|
|
|
|
ENOSUPP("netstat", "AF INET6");
|
|
|
|
#endif
|
|
|
|
@@ -1900,7 +1910,11 @@ int main
|
|
|
|
printf(_("netstat: No statistics support for specified address family: %s\n"), afname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
- exit(0);
|
2004-09-09 09:10:03 +00:00
|
|
|
+ if(i || !flag_cnt)
|
|
|
|
+ break;
|
|
|
|
+ sleep(reptimer);
|
2011-12-06 18:15:09 +00:00
|
|
|
+ }
|
|
|
|
+ return (i);
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flag_rou) {
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1922,7 +1936,7 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
i = route_info(afname, options);
|
|
|
|
if (i || !flag_cnt)
|
|
|
|
break;
|
2011-12-06 18:15:09 +00:00
|
|
|
- wait_continous();
|
|
|
|
+ wait_continous(reptimer);
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -1931,7 +1945,7 @@ int main
|
2004-09-09 09:10:03 +00:00
|
|
|
i = iface_info();
|
|
|
|
if (!flag_cnt || i)
|
|
|
|
break;
|
2011-12-06 18:15:09 +00:00
|
|
|
- wait_continous();
|
|
|
|
+ wait_continous(reptimer);
|
2004-09-09 09:10:03 +00:00
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -2084,7 +2098,7 @@ int main
|
|
|
|
|
2004-09-09 09:10:03 +00:00
|
|
|
if (!flag_cnt || i)
|
|
|
|
break;
|
2011-12-06 18:15:09 +00:00
|
|
|
- wait_continous();
|
|
|
|
+ wait_continous(reptimer);
|
2004-09-09 09:10:03 +00:00
|
|
|
prg_cache_clear();
|
|
|
|
}
|
|
|
|
return (i);
|
2011-12-06 18:15:09 +00:00
|
|
|
diff -up net-tools-1.60/statistics.c.cycle net-tools-1.60/statistics.c
|
|
|
|
--- net-tools-1.60/statistics.c.cycle 2011-11-21 02:31:57.000000000 +0100
|
2011-12-07 16:43:22 +00:00
|
|
|
+++ net-tools-1.60/statistics.c 2011-12-07 16:11:38.352766947 +0100
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -502,7 +502,7 @@ void process6_fd(FILE *f)
|
2004-09-09 09:10:03 +00:00
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
}
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
-void parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
|
+int parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -511,14 +511,17 @@ void parsesnmp(int flag_raw, int flag_tc
|
|
|
|
f = proc_fopen("/proc/net/snmp");
|
2004-09-09 09:10:03 +00:00
|
|
|
if (!f) {
|
|
|
|
perror(_("cannot open /proc/net/snmp"));
|
|
|
|
- return;
|
|
|
|
+ return(1);
|
|
|
|
}
|
2011-12-06 18:15:09 +00:00
|
|
|
|
|
|
|
if (process_fd(f, 1, NULL) < 0)
|
|
|
|
fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
- if (ferror(f))
|
|
|
|
+ if (ferror(f)) {
|
|
|
|
perror("/proc/net/snmp");
|
2011-04-28 14:54:48 +00:00
|
|
|
+ fclose(f);
|
2004-09-09 09:10:03 +00:00
|
|
|
+ return(1);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
@@ -528,15 +531,18 @@ void parsesnmp(int flag_raw, int flag_tc
|
|
|
|
if (process_fd(f, 1, NULL) <0)
|
|
|
|
fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
- if (ferror(f))
|
|
|
|
- perror("/proc/net/netstat");
|
|
|
|
+ if (ferror(f)) {
|
|
|
|
+ perror("/proc/net/netstat");
|
2011-04-28 14:54:48 +00:00
|
|
|
+ fclose(f);
|
2004-09-09 09:10:03 +00:00
|
|
|
+ return(1);
|
2011-12-06 18:15:09 +00:00
|
|
|
+ }
|
2004-09-09 09:10:03 +00:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
-void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
|
+int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
@@ -545,7 +551,7 @@ void parsesnmp6(int flag_raw, int flag_t
|
|
|
|
f = fopen("/proc/net/snmp6", "r");
|
|
|
|
if (!f) {
|
|
|
|
perror(_("cannot open /proc/net/snmp6"));
|
|
|
|
- return;
|
|
|
|
+ return(1);
|
|
|
|
}
|
|
|
|
process6_fd(f);
|
|
|
|
if (ferror(f))
|
|
|
|
@@ -555,13 +561,16 @@ void parsesnmp6(int flag_raw, int flag_t
|
|
|
|
f = fopen("/proc/net/snmp", "r");
|
|
|
|
if (!f) {
|
|
|
|
perror(_("cannot open /proc/net/snmp"));
|
|
|
|
- return;
|
|
|
|
+ return(1);
|
|
|
|
}
|
|
|
|
process_fd(f, 0, "Tcp");
|
|
|
|
- if (ferror(f))
|
|
|
|
+ if (ferror(f)) {
|
|
|
|
perror("/proc/net/snmp");
|
|
|
|
+ return(1);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
+ return(0);
|
|
|
|
}
|
2004-09-09 09:10:03 +00:00
|
|
|
|
2011-12-06 18:15:09 +00:00
|
|
|
void inittab(void)
|