95ca85a
diff -up net-tools-2.0/lib/interface.c.cycle net-tools-2.0/lib/interface.c
5b0aab4
--- net-tools-2.0/lib/interface.c.cycle	2016-02-15 16:54:18.000000000 +0100
5b0aab4
+++ net-tools-2.0/lib/interface.c	2016-03-30 09:58:18.247891588 +0200
626e1f7
@@ -93,6 +93,7 @@ int if_list_all = 0;	/* do we have reque
cvsdist 5f913e2
 static struct interface *int_list, *int_last;
cvsdist 5f913e2
 
fbff637
 static int if_readlist_proc(const char *);
fbff637
+static int if_readlist_rep(const char *, struct interface *);
cvsdist 5f913e2
 
fbff637
 static struct interface *if_cache_add(const char *name)
cvsdist 5f913e2
 {
fbff637
@@ -138,11 +139,14 @@ struct interface *lookup_interface(const
cvsdist 5f913e2
 int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
cvsdist 5f913e2
 {
cvsdist 5f913e2
     struct interface *ife;
cvsdist 5f913e2
+    int err;
cvsdist 5f913e2
 
626e1f7
     if (!if_list_all && (if_readlist() < 0))
cvsdist 5f913e2
 	return -1;
cvsdist 5f913e2
     for (ife = int_list; ife; ife = ife->next) {
cvsdist 5f913e2
-	int err = doit(ife, cookie);
626e1f7
+	if_readlist_rep(ife->name, ife);
cvsdist 5f913e2
+	err = doit(ife, cookie);
626e1f7
+
cvsdist 5f913e2
 	if (err)
cvsdist 5f913e2
 	    return err;
cvsdist 5f913e2
     }
5b0aab4
@@ -210,16 +214,24 @@ out:
cvsdist 5f913e2
     return err;
cvsdist 5f913e2
 }
5b0aab4
 
5b0aab4
-static const char *get_name(char *name, const char *p)
5b0aab4
+static const char *get_name(char **namep, const char *p)
5b0aab4
 {
5b0aab4
+    int count = 0;
5b0aab4
     while (isspace(*p))
5b0aab4
 	p++;
5b0aab4
+    char *name = *namep = p;
5b0aab4
     while (*p) {
5b0aab4
 	if (isspace(*p))
5b0aab4
 	    break;
5b0aab4
 	if (*p == ':') {	/* could be an alias */
5b0aab4
 		const char *dot = p++;
5b0aab4
- 		while (*p && isdigit(*p)) p++;
5b0aab4
+		count++;
5b0aab4
+		while (*p && isdigit(*p)) {
5b0aab4
+		    p++;
5b0aab4
+		    count++;
5b0aab4
+		    if (count == (IFNAMSIZ-1))
5b0aab4
+			break;
5b0aab4
+		}
5b0aab4
 		if (*p == ':') {
5b0aab4
 			/* Yes it is, backup and copy it. */
5b0aab4
 			p = dot;
5b0aab4
@@ -235,6 +247,9 @@ static const char *get_name(char *name,
5b0aab4
 	    break;
5b0aab4
 	}
5b0aab4
 	*name++ = *p++;
5b0aab4
+	count++;
5b0aab4
+	if (count == (IFNAMSIZ-1))
5b0aab4
+    	      break;
5b0aab4
     }
5b0aab4
     *name++ = '\0';
5b0aab4
     return p;
5b0aab4
@@ -316,9 +331,10 @@ static int get_dev_fields(const char *bp
5b0aab4
 static int if_readlist_proc(const char *target)
5b0aab4
 {
5b0aab4
     FILE *fh;
5b0aab4
-    char buf[512];
5b0aab4
     struct interface *ife;
5b0aab4
     int err;
5b0aab4
+    char *line = NULL;
5b0aab4
+    size_t linelen = 0;  
5b0aab4
 
5b0aab4
     fh = fopen(_PATH_PROCNET_DEV, "r");
5b0aab4
     if (!fh) {
5b0aab4
@@ -326,10 +342,11 @@ static int if_readlist_proc(const char *
5b0aab4
 			_PATH_PROCNET_DEV, strerror(errno));
5b0aab4
 		return -2;
5b0aab4
 	}
5b0aab4
-    if (fgets(buf, sizeof buf, fh))
5b0aab4
-		/* eat line */;
5b0aab4
-    if (fgets(buf, sizeof buf, fh))
5b0aab4
-		/* eat line */;
5b0aab4
+    if (getline(&line, &linelen, fh) == -1 /* eat line */
5b0aab4
+	|| getline(&line, &linelen, fh) == -1) { /* eat line */
5b0aab4
+		err = -1;
5b0aab4
+		goto out;
5b0aab4
+	}
5b0aab4
 
5b0aab4
 #if 0				/* pretty, but can't cope with missing fields */
5b0aab4
     fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
5b0aab4
@@ -354,14 +371,14 @@ static int if_readlist_proc(const char *
5b0aab4
     if (!fmt)
5b0aab4
 	return -1;
5b0aab4
 #else
5b0aab4
-    procnetdev_vsn = procnetdev_version(buf);
5b0aab4
+    procnetdev_vsn = procnetdev_version(line);
5b0aab4
 #endif
5b0aab4
 
5b0aab4
     err = 0;
5b0aab4
-    while (fgets(buf, sizeof buf, fh)) {
5b0aab4
+    while (getline(&line, &linelen, fh) != -1) {
5b0aab4
 	const char *s;
5b0aab4
-	char name[IFNAMSIZ];
5b0aab4
-	s = get_name(name, buf);
5b0aab4
+	char *name;
5b0aab4
+	s = get_name(&name, line);    
5b0aab4
 	ife = if_cache_add(name);
5b0aab4
 	get_dev_fields(s, ife);
5b0aab4
 	ife->statistics_valid = 1;
5b0aab4
@@ -376,6 +393,51 @@ static int if_readlist_proc(const char *
5b0aab4
 #if 0
5b0aab4
     free(fmt);
5b0aab4
 #endif
5b0aab4
+  out:
5b0aab4
+    free(line);
5b0aab4
+    fclose(fh);
5b0aab4
+    return err;
5b0aab4
+}
cvsdist 5f913e2
+
fbff637
+static int if_readlist_rep(const char *target, struct interface *ife)
cvsdist 5f913e2
+{
cvsdist 5f913e2
+    FILE *fh;
cvsdist 5f913e2
+    int err;
5b0aab4
+    char *line = NULL;
5b0aab4
+    size_t linelen = 0;
cvsdist 5f913e2
+
cvsdist 5f913e2
+    fh = fopen(_PATH_PROCNET_DEV, "r");
cvsdist 5f913e2
+    if (!fh) {
cvsdist 5f913e2
+		fprintf(stderr, _("Warning: cannot open %s (%s). Limited output.\n"),
cvsdist 5f913e2
+			_PATH_PROCNET_DEV, strerror(errno)); 
cvsdist 5f913e2
+		return if_readconf();
5b0aab4
+	}
5b0aab4
+    if (getline(&line, &linelen, fh) == -1 /* eat line */
5b0aab4
+	|| getline(&line, &linelen, fh) == -1) { /* eat line */
5b0aab4
+		err = -1;
5b0aab4
+		goto out;
5b0aab4
+	}
cvsdist 5f913e2
+
5b0aab4
+    procnetdev_vsn = procnetdev_version(line);
cvsdist 5f913e2
+
cvsdist 5f913e2
+    err = 0;
5b0aab4
+    while (getline(&line, &linelen, fh) != -1) {
5b0aab4
+	char *s, *name;
5b0aab4
+	s = get_name(&name, line);    
cvsdist 5f913e2
+	get_dev_fields(s, ife);
cvsdist 5f913e2
+	if (target && !strcmp(target,name))
5b0aab4
+	{
5b0aab4
+		ife->statistics_valid = 1;
cvsdist 5f913e2
+		break;
5b0aab4
+	}
cvsdist 5f913e2
+    }
cvsdist 5f913e2
+    if (ferror(fh)) {
cvsdist 5f913e2
+	perror(_PATH_PROCNET_DEV);
cvsdist 5f913e2
+	err = -1;
cvsdist 5f913e2
+    }
cvsdist 5f913e2
+
5b0aab4
+  out:
5b0aab4
+    free(line);
5b0aab4
     fclose(fh);
5b0aab4
     return err;
5b0aab4
 }
95ca85a
diff -up net-tools-2.0/man/en_US/netstat.8.cycle net-tools-2.0/man/en_US/netstat.8
5b0aab4
--- net-tools-2.0/man/en_US/netstat.8.cycle	2016-02-15 16:54:18.000000000 +0100
5b0aab4
+++ net-tools-2.0/man/en_US/netstat.8	2016-03-30 09:58:18.241891637 +0200
fbff637
@@ -36,6 +36,7 @@ netstat \- Print network connections, ro
cvsdist 5f913e2
 .RB [ \-\-verbose | \-v ]
cvsdist 5f913e2
 .RB [ \-\-continuous | \-c]
fbff637
 .RB [ \-\-wide | \-W ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat 
cvsdist 5f913e2
 .RB { \-\-route | \-r }
5b0aab4
@@ -45,22 +46,25 @@ netstat \- Print network connections, ro
cvsdist 5f913e2
 .RB [ \-\-numeric | \-n ]
626e1f7
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
fbff637
 .RB [ \-\-continuous | \-c ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat
5b0aab4
-.RB { \-\-interfaces | \-i }
5b0aab4
+.RB { \-\-interfaces | \-I | \-i }
5b0aab4
 .RB [ \-\-all | \-a ]
5b0aab4
-.RB [ \-\-extend | \-e  [ \-\-extend | \-e] ]
5b0aab4
+.RB [ \-\-extend | \-e  ]
5b0aab4
 .RB [ \-\-verbose | \-v ]
5b0aab4
 .RB [ \-\-program | \-p ]
cvsdist 5f913e2
 .RB [ \-\-numeric | \-n ]
626e1f7
 .RB [ \-\-numeric-hosts "] [" \-\-numeric-ports "] [" \-\-numeric-users ]
fbff637
 .RB [ \-\-continuous | \-c ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat
cvsdist 5f913e2
 .RB { \-\-groups | \-g }
cvsdist 5f913e2
 .RB [ \-\-numeric | \-n ]
626e1f7
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
fbff637
 .RB [ \-\-continuous | \-c ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat
cvsdist 5f913e2
 .RB { \-\-masquerade | \-M }
fbff637
@@ -68,6 +72,7 @@ netstat \- Print network connections, ro
cvsdist 5f913e2
 .RB [ \-\-numeric | \-n ]
626e1f7
 .RB [ \-\-numeric\-hosts "] [" \-\-numeric\-ports "] [" \-\-numeric\-users ]
fbff637
 .RB [ \-\-continuous | \-c ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat
cvsdist 5f913e2
 .RB { \-\-statistics | -s }
fbff637
@@ -76,6 +81,7 @@ netstat \- Print network connections, ro
626e1f7
 .RB [ \-\-udplite | \-U ]
ec3d3bc
 .RB [ \-\-sctp | \-S ]
cvsdist 5f913e2
 .RB [ \-\-raw | \-w ]
cvsdist 5f913e2
+.RB [delay]
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .B netstat 
cvsdist 5f913e2
 .RB { \-\-version | \-V }
5b0aab4
@@ -128,8 +134,8 @@ and
5b0aab4
 produce the same output.
5b0aab4
 .SS "\-\-groups, \-g"
5b0aab4
 Display multicast group membership information for IPv4 and IPv6.
5b0aab4
-.SS "\-\-interfaces, \-i"
5b0aab4
-Display a table of all network interfaces.
5b0aab4
+.SS "\-\-interfaces=\fIiface \fR, \fB\-I=\fIiface \fR, \fB\-i"
5b0aab4
+Display a table of all network interfaces, or the specified \fIiface\fR.
5b0aab4
 .SS "\-\-masquerade, \-M"
5b0aab4
 Display a list of masqueraded connections.
5b0aab4
 .SS "\-\-statistics, \-s"
5b0aab4
@@ -201,13 +207,18 @@ Show the PID and name of the program to
5b0aab4
 .SS "\-l, \-\-listening"
5b0aab4
 Show only listening sockets.  (These are omitted by default.)
5b0aab4
 .SS "\-a, \-\-all"
5b0aab4
-Show both listening and non-listening sockets.  With the
5b0aab4
+Show both listening and non-listening (for TCP this means established
5b0aab4
+connections) sockets.  With the
5b0aab4
 .B \-\-interfaces
5b0aab4
 option, show interfaces that are not up
5b0aab4
 .SS "\-F"
cvsdist 5f913e2
 Print routing information from the FIB.  (This is the default.)
cvsdist 5f913e2
 .SS "\-C"
cvsdist 5f913e2
 Print routing information from the route cache.
cvsdist 5f913e2
+.SS delay
cvsdist 5f913e2
+Netstat will cycle printing through statistics every 
cvsdist 5f913e2
+.B delay 
cvsdist 5f913e2
+seconds.
cvsdist 5f913e2
 .P
cvsdist 5f913e2
 .SH OUTPUT
626e1f7
 .P
95ca85a
diff -up net-tools-2.0/netstat.c.cycle net-tools-2.0/netstat.c
5b0aab4
--- net-tools-2.0/netstat.c.cycle	2016-02-15 16:54:18.000000000 +0100
5b0aab4
+++ net-tools-2.0/netstat.c	2016-03-30 10:04:07.617171984 +0200
906023f
@@ -115,8 +115,8 @@
cvsdist 5f913e2
 #endif
cvsdist 5f913e2
 
cvsdist 5f913e2
 /* prototypes for statistics.c */
906023f
-void parsesnmp(int, int, int, int);
626e1f7
-void parsesnmp6(int, int, int);
906023f
+int parsesnmp(int, int, int, int);
626e1f7
+int parsesnmp6(int, int, int);
cvsdist 5f913e2
 
cvsdist 5f913e2
 typedef enum {
906023f
     SS_FREE = 0,		/* not allocated                */
5b0aab4
@@ -142,6 +142,7 @@ static char *Release = RELEASE, *Signatu
5b0aab4
 #define E_IOCTL -3
5b0aab4
 
5b0aab4
 int flag_int = 0;
5b0aab4
+char *flag_int_name = NULL;
5b0aab4
 int flag_rou = 0;
5b0aab4
 int flag_mas = 0;
5b0aab4
 int flag_sta = 0;
5b0aab4
@@ -340,10 +341,10 @@ static void prg_cache_clear(void)
2c75ca1
     prg_cache_loaded = 0;
626e1f7
 }
626e1f7
 
626e1f7
-static void wait_continous(void)
626e1f7
+static void wait_continous(int reptimer)
626e1f7
 {
626e1f7
     fflush(stdout);
626e1f7
-    sleep(1);
626e1f7
+    sleep(reptimer);
626e1f7
 }
626e1f7
 
626e1f7
 static int extract_type_1_socket_inode(const char lname[], unsigned long * inode_p) {
5b0aab4
@@ -501,6 +502,121 @@ static void prg_cache_load(void)
5b0aab4
 			 " will not be shown, you would have to be root to see it all.)\n"));
5b0aab4
 }
5b0aab4
 
5b0aab4
+#define TCP_HASH_SIZE 1009
5b0aab4
+
5b0aab4
+static struct tcp_node {
5b0aab4
+  struct tcp_node *next;
5b0aab4
+  char            *socket_pair;
5b0aab4
+} *tcp_node_hash[TCP_HASH_SIZE];
5b0aab4
+
5b0aab4
+static unsigned int tcp_node_compute_string_hash(const char *p)
5b0aab4
+{
5b0aab4
+  unsigned int h = *p;
5b0aab4
+
5b0aab4
+  if (h)
5b0aab4
+    for (p += 1; *p != '\0'; p++)
5b0aab4
+      h = (h << 5) - h + *p;
5b0aab4
+
5b0aab4
+  return h;
5b0aab4
+}
5b0aab4
+
5b0aab4
+#define TCP_NODE_HASH_STRING(x) \
5b0aab4
+  (tcp_node_compute_string_hash(x) % TCP_HASH_SIZE)
5b0aab4
+
5b0aab4
+static void tcp_node_hash_clear(void)
5b0aab4
+{
5b0aab4
+  int i;
5b0aab4
+  struct tcp_node *next_node;
5b0aab4
+  struct tcp_node *tmp_node;
5b0aab4
+  for (i=0; i < TCP_HASH_SIZE; i++) {
5b0aab4
+    if (tcp_node_hash[i]) {
5b0aab4
+      /* free the children of this hash bucket */
5b0aab4
+      next_node = tcp_node_hash[i]->next;
5b0aab4
+      while (next_node) {
5b0aab4
+	tmp_node = next_node;
5b0aab4
+	next_node = next_node->next;
5b0aab4
+	free(tmp_node->socket_pair);
5b0aab4
+	free(tmp_node);
5b0aab4
+      }
5b0aab4
+
5b0aab4
+      /* free the bucket itself */
5b0aab4
+      free(tcp_node_hash[i]->socket_pair);
5b0aab4
+      free(tcp_node_hash[i]);
5b0aab4
+      tcp_node_hash[i] = NULL;
5b0aab4
+    }
5b0aab4
+  }
5b0aab4
+}
5b0aab4
+
5b0aab4
+/* This function takes a socket pair string.  If it already exists in
5b0aab4
+   the hash it returns -1, otherwise it returns 0. */
5b0aab4
+
5b0aab4
+static int tcp_node_hash_check_and_append(const char *local_addr,
5b0aab4
+					  int local_port,
5b0aab4
+					  const char *rem_addr,
5b0aab4
+					  int rem_port)
5b0aab4
+{
5b0aab4
+  unsigned int hash_val;
5b0aab4
+  struct tcp_node *tmp_node;
5b0aab4
+  int   tmp_string_len;
5b0aab4
+  char *tmp_string;;
5b0aab4
+
5b0aab4
+  /* Size of the string is the size of the two lengths of the address
5b0aab4
+     strings plus enough sizes for the colons and the ports. */
5b0aab4
+  tmp_string_len = strlen(local_addr) + strlen(rem_addr) + 32;
5b0aab4
+  tmp_string = malloc(tmp_string_len);
5b0aab4
+  if (!tmp_string)
5b0aab4
+    return 0;
5b0aab4
+
5b0aab4
+  if (snprintf(tmp_string, tmp_string_len - 1, "%s:%d:%s:%d",
5b0aab4
+	       local_addr, local_port, rem_addr, rem_port) < 0) {
5b0aab4
+    free(tmp_string);
5b0aab4
+    return 0;
5b0aab4
+  }
5b0aab4
+
5b0aab4
+  hash_val = TCP_NODE_HASH_STRING(tmp_string);
5b0aab4
+
5b0aab4
+  /* See if we have to allocate this node */
5b0aab4
+  if (!tcp_node_hash[hash_val]) {
5b0aab4
+    tcp_node_hash[hash_val] = malloc(sizeof(struct tcp_node));
5b0aab4
+    if (!tcp_node_hash[hash_val]) {
5b0aab4
+      free(tmp_string);
5b0aab4
+      return 0;
5b0aab4
+    }
5b0aab4
+
5b0aab4
+    memset(tcp_node_hash[hash_val], 0, sizeof(struct tcp_node));
5b0aab4
+
5b0aab4
+    /* Stuff this new value into the hash bucket and return early */
5b0aab4
+    tcp_node_hash[hash_val]->socket_pair = tmp_string;
5b0aab4
+    return 0;
5b0aab4
+  }
5b0aab4
+
5b0aab4
+  /* Try to find the value in the hash bucket. */
5b0aab4
+  tmp_node = tcp_node_hash[hash_val];
5b0aab4
+  while (tmp_node) {
5b0aab4
+    if (!strcmp(tmp_node->socket_pair, tmp_string)) {
5b0aab4
+      free(tmp_string);
5b0aab4
+      return -1;
5b0aab4
+    }
5b0aab4
+    tmp_node = tmp_node->next;
5b0aab4
+  }
5b0aab4
+
5b0aab4
+  /* If we got this far it means that it isn't in the hash bucket.
5b0aab4
+     Add it to the front since it's faster that way. */
5b0aab4
+  tmp_node = tcp_node_hash[hash_val];
5b0aab4
+
5b0aab4
+  tcp_node_hash[hash_val] = malloc(sizeof(struct tcp_node));
5b0aab4
+  if (!tcp_node_hash[hash_val]) {
5b0aab4
+    free(tmp_string);
5b0aab4
+    tcp_node_hash[hash_val] = tmp_node;
5b0aab4
+    return 0;
5b0aab4
+  }
5b0aab4
+
5b0aab4
+  tcp_node_hash[hash_val]->socket_pair = tmp_string;
5b0aab4
+  tcp_node_hash[hash_val]->next = tmp_node;
5b0aab4
+
5b0aab4
+  return 0;
5b0aab4
+}
5b0aab4
+
5b0aab4
 #if HAVE_AFNETROM
5b0aab4
 static const char *netrom_state[] =
5b0aab4
 {
5b0aab4
@@ -1109,6 +1225,12 @@ static void tcp_do_one(int lnr, const ch
5b0aab4
 	return;
5b0aab4
     }
5b0aab4
 
5b0aab4
+    /* make sure that we haven't seen this socket pair before */
5b0aab4
+    if (tcp_node_hash_check_and_append(local_addr, local_port, rem_addr, rem_port) < 0) {
5b0aab4
+    	/*  fprintf(stderr, _("warning, got duplicate tcp line.\n")); */
5b0aab4
+    	return;
5b0aab4
+    }
5b0aab4
+
5b0aab4
 	addr_do_one(local_addr, sizeof(local_addr), 22, ap, &localsas, local_port, "tcp");
5b0aab4
 	addr_do_one(rem_addr, sizeof(rem_addr), 22, ap, &remsas, rem_port, "tcp");
5b0aab4
 
5b0aab4
@@ -1877,6 +1999,9 @@ static int rfcomm_info(void)
cvsdist 5f913e2
 
cvsdist 5f913e2
 static int iface_info(void)
cvsdist 5f913e2
 {
cvsdist 5f913e2
+    static int count=0;
5b0aab4
+    struct interface *ife = NULL;
cvsdist 5f913e2
+
cvsdist 5f913e2
     if (skfd < 0) {
cvsdist 5f913e2
 	if ((skfd = sockets_open(0)) < 0) {
cvsdist 5f913e2
 	    perror("socket");
5b0aab4
@@ -1886,20 +2011,25 @@ static int iface_info(void)
cvsdist 5f913e2
     }
cvsdist 5f913e2
     if (flag_exp < 2) {
cvsdist 5f913e2
 	ife_short = 1;
9dd4855
-	printf(_("Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
cvsdist 5f913e2
+	if(!(count % 8))
9dd4855
+	    printf(_("Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg\n"));
cvsdist 5f913e2
     }
cvsdist 5f913e2
 
5b0aab4
-    if (for_all_interfaces(do_if_print, &flag_all) < 0) {
5b0aab4
+    if (flag_int_name) {
5b0aab4
+        ife = lookup_interface(flag_int_name);
5b0aab4
+        do_if_print(ife, &flag_all);
5b0aab4
+    }
5b0aab4
+    else if (for_all_interfaces(do_if_print, &flag_all) < 0) {
cvsdist 5f913e2
 	perror(_("missing interface information"));
cvsdist 5f913e2
 	exit(1);
cvsdist 5f913e2
     }
cvsdist 5f913e2
-    if (flag_cnt)
cvsdist 5f913e2
+    if (!flag_cnt) {
626e1f7
 	if_cache_free();
cvsdist 5f913e2
-    else {
cvsdist 5f913e2
 	close(skfd);
cvsdist 5f913e2
 	skfd = -1;
cvsdist 5f913e2
     }
cvsdist 5f913e2
 
cvsdist 5f913e2
+    count++;
cvsdist 5f913e2
     return 0;
cvsdist 5f913e2
 }
cvsdist 5f913e2
 
5b0aab4
@@ -1915,9 +2045,10 @@ static void usage(int rc)
cvsdist 5f913e2
 {
626e1f7
     fprintf(stderr, _("usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}\n"));
626e1f7
     fprintf(stderr, _("       netstat [-vWnNcaeol] [<Socket> ...]\n"));
626e1f7
-    fprintf(stderr, _("       netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }\n\n"));
5b0aab4
+    fprintf(stderr, _("       netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]\n\n"));
cvsdist 5f913e2
 
cvsdist 5f913e2
     fprintf(stderr, _("        -r, --route              display routing table\n"));
5b0aab4
+    fprintf(stderr, _("        -I, --interfaces=<Iface> display interface table for <Iface>\n"));
cvsdist 5f913e2
     fprintf(stderr, _("        -i, --interfaces         display interface table\n"));
5b0aab4
     fprintf(stderr, _("        -g, --groups             display multicast group memberships\n"));
5b0aab4
     fprintf(stderr, _("        -s, --statistics         display networking statistics (like SNMP)\n"));
5b0aab4
@@ -1957,11 +2088,12 @@ int main
cvsdist 5f913e2
  (int argc, char *argv[]) {
cvsdist 5f913e2
     int i;
cvsdist 5f913e2
     int lop;
cvsdist 5f913e2
+    int reptimer = 1;
626e1f7
     static struct option longopts[] =
cvsdist 5f913e2
     {
cvsdist 5f913e2
 	AFTRANS_OPTS,
5b0aab4
 	{"version", 0, 0, 'V'},
5b0aab4
-	{"interfaces", 0, 0, 'i'},
5b0aab4
+	{"interfaces", 2, 0, 'I'},
5b0aab4
 	{"help", 0, 0, 'h'},
5b0aab4
 	{"route", 0, 0, 'r'},
5b0aab4
 #if HAVE_FW_MASQUERADE
5b0aab4
@@ -2005,7 +2137,7 @@ int main
5b0aab4
     getroute_init();		/* Set up AF routing support */
5b0aab4
 
5b0aab4
     afname[0] = '\0';
5b0aab4
-    while ((i = getopt_long(argc, argv, "A:CFMacdeghilnNoprsStuUvVWw2fx64?Z", longopts, &lop)) != EOF)
5b0aab4
+    while ((i = getopt_long(argc, argv, "A:CFMacdeghiI::lnNoprsStuUvVWw2fx64?Z", longopts, &lop)) != EOF)
5b0aab4
 	switch (i) {
5b0aab4
 	case -1:
5b0aab4
 	    break;
5b0aab4
@@ -2046,6 +2178,13 @@ int main
5b0aab4
 	case 'p':
5b0aab4
 	    flag_prg++;
5b0aab4
 	    break;
5b0aab4
+	case 'I':
5b0aab4
+	    if (optarg && strcmp(optarg, "(null)"))
5b0aab4
+		if (optarg[0] == '=') optarg++;
5b0aab4
+	    if (optarg && strcmp(optarg, "(null)"))
5b0aab4
+		flag_int_name = strdup(optarg);
5b0aab4
+	    flag_int++;
5b0aab4
+	    break;
5b0aab4
 	case 'i':
5b0aab4
 	    flag_int++;
5b0aab4
 	    break;
5b0aab4
@@ -2140,6 +2279,12 @@ int main
cvsdist 5f913e2
 	    flag_sta++;
cvsdist 5f913e2
 	}
cvsdist 5f913e2
 
cvsdist 5f913e2
+    if(argc == optind + 1) {
5b0aab4
+    	if((reptimer = atoi(argv[optind])) <= 0)
5b0aab4
+    		usage(E_USAGE);
5b0aab4
+        flag_cnt++;
cvsdist 5f913e2
+    }
5b0aab4
+
cvsdist 5f913e2
     if (flag_int + flag_rou + flag_mas + flag_sta > 1)
5b0aab4
 	usage(E_OPTERR);
cvsdist 5f913e2
 
5b0aab4
@@ -2169,7 +2314,7 @@ int main
cvsdist 5f913e2
 			     flag_not & FLAG_NUM_PORT, flag_exp);
cvsdist 5f913e2
 	    if (i || !flag_cnt)
cvsdist 5f913e2
 		break;
626e1f7
-	    wait_continous();
626e1f7
+	    wait_continous(reptimer);
cvsdist 5f913e2
 	}
cvsdist 5f913e2
 #else
626e1f7
 	ENOSUPP("netstat", "FW_MASQUERADE");
5b0aab4
@@ -2182,15 +2327,16 @@ int main
626e1f7
         if (!afname[0])
b381fc1
             safe_strncpy(afname, DFLT_AF, sizeof(afname));
c90847a
 
626e1f7
+        for (;;) {
626e1f7
         if (!strcmp(afname, "inet")) {
626e1f7
 #if HAVE_AFINET
906023f
-            parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp);
906023f
+            i = parsesnmp(flag_raw, flag_tcp, flag_udp, flag_sctp);
626e1f7
 #else
626e1f7
             ENOSUPP("netstat", "AF INET");
626e1f7
 #endif
626e1f7
         } else if(!strcmp(afname, "inet6")) {
626e1f7
 #if HAVE_AFINET6
626e1f7
-            parsesnmp6(flag_raw, flag_tcp, flag_udp);
626e1f7
+            i = parsesnmp6(flag_raw, flag_tcp, flag_udp);
626e1f7
 #else
626e1f7
             ENOSUPP("netstat", "AF INET6");
626e1f7
 #endif
5b0aab4
@@ -2198,7 +2344,11 @@ int main
626e1f7
           printf(_("netstat: No statistics support for specified address family: %s\n"), afname);
626e1f7
           exit(1);
626e1f7
         }
626e1f7
-        exit(0);
cvsdist 5f913e2
+	if(i || !flag_cnt)
cvsdist 5f913e2
+	  break;
cvsdist 5f913e2
+	sleep(reptimer);
626e1f7
+        }
626e1f7
+        return (i);
cvsdist 5f913e2
     }
c90847a
 
cvsdist 5f913e2
     if (flag_rou) {
5b0aab4
@@ -2220,7 +2370,7 @@ int main
cvsdist 5f913e2
 	    i = route_info(afname, options);
cvsdist 5f913e2
 	    if (i || !flag_cnt)
cvsdist 5f913e2
 		break;
626e1f7
-            wait_continous();
626e1f7
+            wait_continous(reptimer);
cvsdist 5f913e2
 	}
cvsdist 5f913e2
 	return (i);
cvsdist 5f913e2
     }
5b0aab4
@@ -2229,7 +2379,7 @@ int main
cvsdist 5f913e2
 	    i = iface_info();
cvsdist 5f913e2
 	    if (!flag_cnt || i)
cvsdist 5f913e2
 		break;
626e1f7
-            wait_continous();
626e1f7
+            wait_continous(reptimer);
cvsdist 5f913e2
 	}
cvsdist 5f913e2
 	return (i);
cvsdist 5f913e2
     }
5b0aab4
@@ -2416,8 +2566,9 @@ int main
3f72065
 
cvsdist 5f913e2
 	if (!flag_cnt || i)
cvsdist 5f913e2
 	    break;
626e1f7
-        wait_continous();
626e1f7
+        wait_continous(reptimer);
cvsdist 5f913e2
 	prg_cache_clear();
5b0aab4
+	tcp_node_hash_clear();
cvsdist 5f913e2
     }
cvsdist 5f913e2
     return (i);
5b0aab4
 }
95ca85a
diff -up net-tools-2.0/statistics.c.cycle net-tools-2.0/statistics.c
5b0aab4
--- net-tools-2.0/statistics.c.cycle	2016-02-15 16:54:18.000000000 +0100
5b0aab4
+++ net-tools-2.0/statistics.c	2016-03-30 09:58:18.238891661 +0200
906023f
@@ -527,7 +527,7 @@ static void process_fd2(FILE *f, const c
906023f
     }
626e1f7
 }
cvsdist 5f913e2
 
906023f
-void parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp)
906023f
+int parsesnmp(int flag_raw, int flag_tcp, int flag_udp, int flag_sctp)
cvsdist 5f913e2
 {
cvsdist 5f913e2
     FILE *f;
cvsdist 5f913e2
 
906023f
@@ -536,14 +536,17 @@ void parsesnmp(int flag_raw, int flag_tc
626e1f7
     f = proc_fopen("/proc/net/snmp");
cvsdist 5f913e2
     if (!f) {
cvsdist 5f913e2
 	perror(_("cannot open /proc/net/snmp"));
cvsdist 5f913e2
-	return;
cvsdist 5f913e2
+	return(1);
cvsdist 5f913e2
     }
626e1f7
 
626e1f7
     if (process_fd(f, 1, NULL) < 0)
626e1f7
       fprintf(stderr, _("Problem while parsing /proc/net/snmp\n"));
cvsdist 5f913e2
 
cvsdist 5f913e2
-    if (ferror(f))
cvsdist 5f913e2
+    if (ferror(f)) {
cvsdist 5f913e2
 	perror("/proc/net/snmp");
579c9b0
+	fclose(f);
cvsdist 5f913e2
+	return(1);
cvsdist 5f913e2
+    }
cvsdist 5f913e2
 
cvsdist 5f913e2
     fclose(f);
cvsdist 5f913e2
 
906023f
@@ -553,8 +556,11 @@ void parsesnmp(int flag_raw, int flag_tc
626e1f7
     	if (process_fd(f, 1, NULL) <0)
626e1f7
           fprintf(stderr, _("Problem while parsing /proc/net/netstat\n"));
cvsdist 5f913e2
 
cvsdist 5f913e2
-        if (ferror(f))
cvsdist 5f913e2
-	    perror("/proc/net/netstat");
cvsdist 5f913e2
+        if (ferror(f)) {
cvsdist 5f913e2
+	  perror("/proc/net/netstat");
579c9b0
+	  fclose(f);
cvsdist 5f913e2
+	  return(1);
626e1f7
+        }
c90847a
 
cvsdist 5f913e2
         fclose(f);
cvsdist 5f913e2
     }
906023f
@@ -567,9 +573,10 @@ void parsesnmp(int flag_raw, int flag_tc
906023f
 	    fclose(f);
906023f
 	}
906023f
     }
cvsdist 5f913e2
+    return(0);
cvsdist 5f913e2
 }
c90847a
 
626e1f7
-void parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
626e1f7
+int parsesnmp6(int flag_raw, int flag_tcp, int flag_udp)
626e1f7
 {
626e1f7
     FILE *f;
626e1f7
 
906023f
@@ -578,7 +585,7 @@ void parsesnmp6(int flag_raw, int flag_t
626e1f7
     f = fopen("/proc/net/snmp6", "r");
626e1f7
     if (!f) {
626e1f7
         perror(_("cannot open /proc/net/snmp6"));
626e1f7
-        return;
626e1f7
+        return(1);
626e1f7
     }
626e1f7
     process6_fd(f);
626e1f7
     if (ferror(f))
906023f
@@ -588,11 +595,14 @@ void parsesnmp6(int flag_raw, int flag_t
626e1f7
     f = fopen("/proc/net/snmp", "r");
626e1f7
     if (!f) {
626e1f7
         perror(_("cannot open /proc/net/snmp"));
626e1f7
-        return;
626e1f7
+        return(1);
626e1f7
     }
626e1f7
     process_fd(f, 0, "Tcp");
626e1f7
-    if (ferror(f))
626e1f7
+    if (ferror(f)) {
626e1f7
         perror("/proc/net/snmp");
626e1f7
+        return(1);
626e1f7
+    }
626e1f7
 
626e1f7
     fclose(f);
626e1f7
+    return(0);
626e1f7
 }