diff -up net-tools-2.0/lib/interface.c.cycle net-tools-2.0/lib/interface.c --- net-tools-2.0/lib/interface.c.cycle 2015-08-29 08:59:31.000000000 +0200 +++ net-tools-2.0/lib/interface.c 2015-09-15 18:09:54.089697132 +0200 @@ -93,6 +93,7 @@ int if_list_all = 0; /* do we have reque static struct interface *int_list, *int_last; static int if_readlist_proc(const char *); +static int if_readlist_rep(const char *, struct interface *); static struct interface *if_cache_add(const char *name) { @@ -138,11 +139,14 @@ struct interface *lookup_interface(const int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie) { struct interface *ife; + int err; if (!if_list_all && (if_readlist() < 0)) return -1; for (ife = int_list; ife; ife = ife->next) { - int err = doit(ife, cookie); + if_readlist_rep(ife->name, ife); + err = doit(ife, cookie); + if (err) return err; } @@ -379,6 +383,41 @@ static int if_readlist_proc(const char * fclose(fh); return err; } + +static int if_readlist_rep(const 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; +} int if_readlist(void) { diff -up net-tools-2.0/man/en_US/netstat.8.cycle net-tools-2.0/man/en_US/netstat.8 --- net-tools-2.0/man/en_US/netstat.8.cycle 2015-08-29 08:59:31.000000000 +0200 +++ net-tools-2.0/man/en_US/netstat.8 2015-09-15 18:09:54.090697129 +0200 @@ -36,6 +36,7 @@ netstat \- Print network connections, ro .RB [ \-\-verbose | \-v ] .RB [ \-\-continuous | \-c] .RB [ \-\-wide | \-W ] +.RB [delay] .P .B netstat .RB { \-\-route | \-r } @@ -45,6 +46,7 @@ netstat \- Print network connections, ro .RB [ \-\-numeric | \-n ] .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] .RB [ \-\-continuous | \-c ] +.RB [delay] .P .B netstat .RB { \-\-interfaces | \-i } @@ -55,12 +57,14 @@ netstat \- Print network connections, ro .RB [ \-\-numeric | \-n ] .RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ] .RB [ \-\-continuous | \-c ] +.RB [delay] .P .B netstat .RB { \-\-groups | \-g } .RB [ \-\-numeric | \-n ] .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] .RB [ \-\-continuous | \-c ] +.RB [delay] .P .B netstat .RB { \-\-masquerade | \-M } @@ -68,6 +72,7 @@ netstat \- Print network connections, ro .RB [ \-\-numeric | \-n ] .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ] .RB [ \-\-continuous | \-c ] +.RB [delay] .P .B netstat .RB { \-\-statistics | -s } @@ -76,6 +81,7 @@ netstat \- Print network connections, ro .RB [ \-\-udplite | \-U ] .RB [ \-\-sctp | \-S ] .RB [ \-\-raw | \-w ] +.RB [delay] .P .B netstat .RB { \-\-version | \-V } @@ -208,6 +214,10 @@ option, show interfaces that are not up 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 .P diff -up net-tools-2.0/netstat.c.cycle net-tools-2.0/netstat.c --- net-tools-2.0/netstat.c.cycle 2015-08-29 08:59:31.000000000 +0200 +++ net-tools-2.0/netstat.c 2015-09-15 18:09:54.090697129 +0200 @@ -115,8 +115,8 @@ #endif /* prototypes for statistics.c */ -void parsesnmp(int, int, int, int); -void parsesnmp6(int, int, int); +int parsesnmp(int, int, int, int); +int parsesnmp6(int, int, int); typedef enum { SS_FREE = 0, /* not allocated */ @@ -340,10 +340,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) { @@ -1892,6 +1892,8 @@ static int rfcomm_info(void) static int iface_info(void) { + static int count=0; + if (skfd < 0) { if ((skfd = sockets_open(0)) < 0) { perror("socket"); @@ -1901,20 +1903,21 @@ static int iface_info(void) } if (flag_exp < 2) { ife_short = 1; - printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); + if(!(count % 8)) + printf(_("Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg\n")); } if (for_all_interfaces(do_if_print, &flag_all) < 0) { perror(_("missing interface information")); exit(1); } - if (flag_cnt) + if (!flag_cnt) { if_cache_free(); - else { close(skfd); skfd = -1; } + count++; return 0; } @@ -1930,7 +1933,7 @@ static void usage(void) { fprintf(stderr, _("usage: netstat [-vWeenNcCF] [] -r netstat {-V|--version|-h|--help}\n")); fprintf(stderr, _(" netstat [-vWnNcaeol] [ ...]\n")); - fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n")); + fprintf(stderr, _(" netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n")); fprintf(stderr, _(" -r, --route display routing table\n")); fprintf(stderr, _(" -i, --interfaces display interface table\n")); @@ -1972,6 +1975,7 @@ int main (int argc, char *argv[]) { int i; int lop; + int reptimer = 1; static struct option longopts[] = { AFTRANS_OPTS, @@ -2154,6 +2158,12 @@ int main 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(); @@ -2183,7 +2193,7 @@ int main flag_not & FLAG_NUM_PORT, flag_exp); if (i || !flag_cnt) break; - wait_continous(); + wait_continous(reptimer); } #else ENOSUPP("netstat", "FW_MASQUERADE"); @@ -2196,15 +2206,16 @@ int main if (!afname[0]) safe_strncpy(afname, DFLT_AF, sizeof(afname)); + for (;;) { if (!strcmp(afname, "inet")) { #if HAVE_AFINET - parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp); + i = parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp); #else ENOSUPP("netstat", "AF INET"); #endif } else if(!strcmp(afname, "inet6")) { #if HAVE_AFINET6 - parsesnmp6(flag_raw, flag_tcp, flag_udp); + i = parsesnmp6(flag_raw, flag_tcp, flag_udp); #else ENOSUPP("netstat", "AF INET6"); #endif @@ -2212,7 +2223,11 @@ int main printf(_("netstat: No statistics support for specified address family: %s\n"), afname); exit(1); } - exit(0); + if(i || !flag_cnt) + break; + sleep(reptimer); + } + return (i); } if (flag_rou) { @@ -2234,7 +2249,7 @@ int main i = route_info(afname, options); if (i || !flag_cnt) break; - wait_continous(); + wait_continous(reptimer); } return (i); } @@ -2243,7 +2258,7 @@ int main i = iface_info(); if (!flag_cnt || i) break; - wait_continous(); + wait_continous(reptimer); } return (i); } @@ -2430,7 +2445,7 @@ int main if (!flag_cnt || i) break; - wait_continous(); + wait_continous(reptimer); prg_cache_clear(); } return (i); diff -up net-tools-2.0/statistics.c.cycle net-tools-2.0/statistics.c --- net-tools-2.0/statistics.c.cycle 2015-08-29 08:59:31.000000000 +0200 +++ net-tools-2.0/statistics.c 2015-09-15 18:10:34.608582779 +0200 @@ -527,7 +527,7 @@ static void process_fd2(FILE *f, const c } } -void parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp) +int parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp) { FILE *f; @@ -536,14 +536,17 @@ void parsesnmp(int flag_raw, int flag_tc f = proc_fopen("/proc/net/snmp"); if (!f) { perror(_("cannot open /proc/net/snmp")); - return; + return(1); } if (process_fd(f, 1, NULL) < 0) fprintf(stderr, _("Problem while parsing /proc/net/snmp\n")); - if (ferror(f)) + if (ferror(f)) { perror("/proc/net/snmp"); + fclose(f); + return(1); + } fclose(f); @@ -553,8 +556,11 @@ void parsesnmp(int flag_raw, int flag_tc if (process_fd(f, 1, NULL) <0) fprintf(stderr, _("Problem while parsing /proc/net/netstat\n")); - if (ferror(f)) - perror("/proc/net/netstat"); + if (ferror(f)) { + perror("/proc/net/netstat"); + fclose(f); + return(1); + } fclose(f); } @@ -567,9 +573,10 @@ void parsesnmp(int flag_raw, int flag_tc fclose(f); } } + return(0); } -void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp) +int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp) { FILE *f; @@ -578,7 +585,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)) @@ -588,11 +595,14 @@ 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); }