Blame SOURCES/net-tools-cycle.patch

612949
diff -up net-tools-2.0/lib/interface.c.cycle net-tools-2.0/lib/interface.c
612949
--- net-tools-2.0/lib/interface.c.cycle	2013-08-30 14:30:25.000000000 +0200
612949
+++ net-tools-2.0/lib/interface.c	2013-09-10 12:31:03.930309225 +0200
612949
@@ -93,6 +93,7 @@ int if_list_all = 0;	/* do we have reque
612949
 static struct interface *int_list, *int_last;
612949
 
612949
 static int if_readlist_proc(char *);
612949
+static int if_readlist_rep(char *, struct interface *);
612949
 
612949
 static struct interface *if_cache_add(char *name)
612949
 {
612949
@@ -138,11 +139,14 @@ struct interface *lookup_interface(char
612949
 int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
612949
 {
612949
     struct interface *ife;
612949
+    int err;
612949
 
612949
     if (!if_list_all && (if_readlist() < 0))
612949
 	return -1;
612949
     for (ife = int_list; ife; ife = ife->next) {
612949
-	int err = doit(ife, cookie);
612949
+	if_readlist_rep(ife->name, ife);
612949
+	err = doit(ife, cookie);
612949
+
612949
 	if (err)
612949
 	    return err;
612949
     }
612949
@@ -378,6 +382,41 @@ static int if_readlist_proc(char *target
612949
     fclose(fh);
612949
     return err;
612949
 }
612949
+
612949
+static int if_readlist_rep(char *target, struct interface *ife)
612949
+{
612949
+    FILE *fh;
612949
+    char buf[512];
612949
+    int err;
612949
+
612949
+    fh = fopen(_PATH_PROCNET_DEV, "r");
612949
+    if (!fh) {
612949
+		fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
612949
+			_PATH_PROCNET_DEV, strerror(errno)); 
612949
+		return if_readconf();
612949
+	}	
612949
+    fgets(buf, sizeof buf, fh);	/* eat line */
612949
+    fgets(buf, sizeof buf, fh);
612949
+
612949
+    procnetdev_vsn = procnetdev_version(buf);
612949
+
612949
+    err = 0;
612949
+    while (fgets(buf, sizeof buf, fh)) {
612949
+	char *s, name[IFNAMSIZ];
612949
+	s = get_name(name, buf);    
612949
+	get_dev_fields(s, ife);
612949
+	ife->statistics_valid = 1;
612949
+	if (target && !strcmp(target,name))
612949
+		break;
612949
+    }
612949
+    if (ferror(fh)) {
612949
+	perror(_PATH_PROCNET_DEV);
612949
+	err = -1;
612949
+    }
612949
+
612949
+    fclose(fh);
612949
+    return err;
612949
+}
612949
 
612949
 int if_readlist(void)
612949
 {
612949
diff -up net-tools-2.0/man/en_US/netstat.8.cycle net-tools-2.0/man/en_US/netstat.8
612949
--- net-tools-2.0/man/en_US/netstat.8.cycle	2013-08-30 14:30:25.000000000 +0200
612949
+++ net-tools-2.0/man/en_US/netstat.8	2013-09-10 12:31:03.930309225 +0200
612949
@@ -33,6 +33,7 @@ netstat \- Print network connections, ro
612949
 .RB [ \-\-verbose | \-v ]
612949
 .RB [ \-\-continuous | \-c]
612949
 .RB [ \-\-wide | \-W]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat 
612949
 .RB { \-\-route | \-r }
612949
@@ -42,6 +43,7 @@ netstat \- Print network connections, ro
612949
 .RB [ \-\-numeric | \-n ]
612949
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
612949
 .RB [ \-\-continuous | \-c]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat
612949
 .RB { \-\-interfaces | \-i }
612949
@@ -52,12 +54,14 @@ netstat \- Print network connections, ro
612949
 .RB [ \-\-numeric | \-n ]
612949
 .RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ]
612949
 .RB [ \-\-continuous | \-c]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat
612949
 .RB { \-\-groups | \-g }
612949
 .RB [ \-\-numeric | \-n ]
612949
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
612949
 .RB [ \-\-continuous | \-c]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat
612949
 .RB { \-\-masquerade | \-M }
612949
@@ -65,6 +69,7 @@ netstat \- Print network connections, ro
612949
 .RB [ \-\-numeric | \-n ]
612949
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
612949
 .RB [ \-\-continuous | \-c]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat
612949
 .RB { \-\-statistics | -s }
612949
@@ -72,6 +77,7 @@ netstat \- Print network connections, ro
612949
 .RB [ \-\-udp | \-u ]
612949
 .RB [ \-\-udplite | \-U ]
612949
 .RB [ \-\-raw | \-w ]
612949
+.RB [delay]
612949
 .P
612949
 .B netstat 
612949
 .RB { \-\-version | \-V }
612949
@@ -197,6 +203,10 @@ option, show interfaces that are not up
612949
 Print routing information from the FIB.  (This is the default.)
612949
 .SS "\-C"
612949
 Print routing information from the route cache.
612949
+.SS delay
612949
+Netstat will cycle printing through statistics every 
612949
+.B delay 
612949
+seconds.
612949
 .P
612949
 .SH OUTPUT
612949
 .P
612949
diff -up net-tools-2.0/netstat.c.cycle net-tools-2.0/netstat.c
612949
--- net-tools-2.0/netstat.c.cycle	2013-08-30 14:30:25.000000000 +0200
612949
+++ net-tools-2.0/netstat.c	2013-09-10 12:32:32.460124531 +0200
612949
@@ -115,9 +115,9 @@
612949
 #endif
612949
 
612949
 /* prototypes for statistics.c */
612949
-void parsesnmp(int, int, int);
612949
+int parsesnmp(int, int, int);
612949
 void inittab(void);
612949
-void parsesnmp6(int, int, int);
612949
+int parsesnmp6(int, int, int);
612949
 void inittab6(void);
612949
 
612949
 typedef enum {
612949
@@ -341,10 +341,10 @@ static void prg_cache_clear(void)
612949
     prg_cache_loaded = 0;
612949
 }
612949
 
612949
-static void wait_continous(void)
612949
+static void wait_continous(int reptimer)
612949
 {
612949
     fflush(stdout);
612949
-    sleep(1);
612949
+    sleep(reptimer);
612949
 }
612949
 
612949
 static int extract_type_1_socket_inode(const char lname[], unsigned long * inode_p) {
612949
@@ -1781,6 +1781,8 @@ static int rfcomm_info(void)
612949
 
612949
 static int iface_info(void)
612949
 {
612949
+    static int count=0;
612949
+
612949
     if (skfd < 0) {
612949
 	if ((skfd = sockets_open(0)) < 0) {
612949
 	    perror("socket");
612949
@@ -1790,20 +1792,21 @@ static int iface_info(void)
612949
     }
612949
     if (flag_exp < 2) {
612949
 	ife_short = 1;
612949
-	printf(_("Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
612949
+	if(!(count % 8))
612949
+	    printf(_("Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
612949
     }
612949
 
612949
     if (for_all_interfaces(do_if_print, &flag_all) < 0) {
612949
 	perror(_("missing interface information"));
612949
 	exit(1);
612949
     }
612949
-    if (flag_cnt)
612949
+    if (!flag_cnt) {
612949
 	if_cache_free();
612949
-    else {
612949
 	close(skfd);
612949
 	skfd = -1;
612949
     }
612949
 
612949
+    count++;
612949
     return 0;
612949
 }
612949
 
612949
@@ -1819,7 +1822,7 @@ static void usage(void)
612949
 {
612949
     fprintf(stderr, _("usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}\n"));
612949
     fprintf(stderr, _("       netstat [-vWnNcaeol] [<Socket> ...]\n"));
612949
-    fprintf(stderr, _("       netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n"));
612949
+    fprintf(stderr, _("       netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n"));
612949
 
612949
     fprintf(stderr, _("        -r, --route              display routing table\n"));
612949
     fprintf(stderr, _("        -i, --interfaces         display interface table\n"));
612949
@@ -1861,6 +1864,7 @@ int main
612949
  (int argc, char *argv[]) {
612949
     int i;
612949
     int lop;
612949
+    int reptimer = 1;
612949
     static struct option longopts[] =
612949
     {
612949
 	AFTRANS_OPTS,
612949
@@ -2043,6 +2047,12 @@ int main
612949
 	    flag_sta++;
612949
 	}
612949
 
612949
+    if(argc == optind + 1) {
612949
+      if((reptimer = atoi(argv[optind])) <= 0)
612949
+	usage();
612949
+      flag_cnt++;
612949
+    }
612949
+    
612949
     if (flag_int + flag_rou + flag_mas + flag_sta > 1)
612949
 	usage();
612949
 
612949
@@ -2072,7 +2082,7 @@ int main
612949
 			     flag_not & FLAG_NUM_PORT, flag_exp);
612949
 	    if (i || !flag_cnt)
612949
 		break;
612949
-	    wait_continous();
612949
+	    wait_continous(reptimer);
612949
 	}
612949
 #else
612949
 	ENOSUPP("netstat", "FW_MASQUERADE");
612949
@@ -2085,17 +2095,18 @@ int main
612949
         if (!afname[0])
612949
             safe_strncpy(afname, DFLT_AF, sizeof(afname));
612949
 
612949
+        for (;;) {
612949
         if (!strcmp(afname, "inet")) {
612949
 #if HAVE_AFINET
612949
             inittab();
612949
-            parsesnmp(flag_raw, flag_tcp, flag_udp);
612949
+            i = parsesnmp(flag_raw, flag_tcp, flag_udp);
612949
 #else
612949
             ENOSUPP("netstat", "AF INET");
612949
 #endif
612949
         } else if(!strcmp(afname, "inet6")) {
612949
 #if HAVE_AFINET6
612949
             inittab6();
612949
-            parsesnmp6(flag_raw, flag_tcp, flag_udp);
612949
+            i = parsesnmp6(flag_raw, flag_tcp, flag_udp);
612949
 #else
612949
             ENOSUPP("netstat", "AF INET6");
612949
 #endif
612949
@@ -2103,7 +2114,11 @@ int main
612949
           printf(_("netstat: No statistics support for specified address family: %s\n"), afname);
612949
           exit(1);
612949
         }
612949
-        exit(0);
612949
+	if(i || !flag_cnt)
612949
+	  break;
612949
+	sleep(reptimer);
612949
+        }
612949
+        return (i);
612949
     }
612949
 
612949
     if (flag_rou) {
612949
@@ -2125,7 +2140,7 @@ int main
612949
 	    i = route_info(afname, options);
612949
 	    if (i || !flag_cnt)
612949
 		break;
612949
-            wait_continous();
612949
+            wait_continous(reptimer);
612949
 	}
612949
 	return (i);
612949
     }
612949
@@ -2134,7 +2149,7 @@ int main
612949
 	    i = iface_info();
612949
 	    if (!flag_cnt || i)
612949
 		break;
612949
-            wait_continous();
612949
+            wait_continous(reptimer);
612949
 	}
612949
 	return (i);
612949
     }
612949
@@ -2321,7 +2336,7 @@ int main
612949
 
612949
 	if (!flag_cnt || i)
612949
 	    break;
612949
-        wait_continous();
612949
+        wait_continous(reptimer);
612949
 	prg_cache_clear();
612949
     }
612949
     return (i);
612949
diff -up net-tools-2.0/statistics.c.cycle net-tools-2.0/statistics.c
612949
--- net-tools-2.0/statistics.c.cycle	2013-08-30 14:30:25.000000000 +0200
612949
+++ net-tools-2.0/statistics.c	2013-09-10 12:31:03.932309198 +0200
612949
@@ -502,7 +502,7 @@ void process6_fd(FILE *f)
612949
 
612949
 }
612949
 
612949
-void parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
612949
+int parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
612949
 {
612949
     FILE *f;
612949
 
612949
@@ -511,14 +511,17 @@ void parsesnmp(int flag_raw, int flag_tc
612949
     f = proc_fopen("/proc/net/snmp");
612949
     if (!f) {
612949
 	perror(_("cannot open /proc/net/snmp"));
612949
-	return;
612949
+	return(1);
612949
     }
612949
 
612949
     if (process_fd(f, 1, NULL) < 0)
612949
       fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
612949
 
612949
-    if (ferror(f))
612949
+    if (ferror(f)) {
612949
 	perror("/proc/net/snmp");
612949
+	fclose(f);
612949
+	return(1);
612949
+    }
612949
 
612949
     fclose(f);
612949
 
612949
@@ -528,15 +531,18 @@ void parsesnmp(int flag_raw, int flag_tc
612949
     	if (process_fd(f, 1, NULL) <0)
612949
           fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
612949
 
612949
-        if (ferror(f))
612949
-	    perror("/proc/net/netstat");
612949
+        if (ferror(f)) {
612949
+	  perror("/proc/net/netstat");
612949
+	  fclose(f);
612949
+	  return(1);
612949
+        }
612949
 
612949
         fclose(f);
612949
     }
612949
-    return;
612949
+    return(0);
612949
 }
612949
 
612949
-void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
612949
+int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
612949
 {
612949
     FILE *f;
612949
 
612949
@@ -545,7 +551,7 @@ void parsesnmp6(int flag_raw, int flag_t
612949
     f = fopen("/proc/net/snmp6", "r");
612949
     if (!f) {
612949
         perror(_("cannot open /proc/net/snmp6"));
612949
-        return;
612949
+        return(1);
612949
     }
612949
     process6_fd(f);
612949
     if (ferror(f))
612949
@@ -555,13 +561,16 @@ void parsesnmp6(int flag_raw, int flag_t
612949
     f = fopen("/proc/net/snmp", "r");
612949
     if (!f) {
612949
         perror(_("cannot open /proc/net/snmp"));
612949
-        return;
612949
+        return(1);
612949
     }
612949
     process_fd(f, 0, "Tcp");
612949
-    if (ferror(f))
612949
+    if (ferror(f)) {
612949
         perror("/proc/net/snmp");
612949
+        return(1);
612949
+    }
612949
 
612949
     fclose(f);
612949
+    return(0);
612949
 }
612949
 
612949
 void inittab(void)