diff mbox

iproute2/nstat: Bug in displaying icmp stats

Message ID 1417831808.15618.23.camel@edumazet-glaptop2.roam.corp.google.com
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Eric Dumazet Dec. 6, 2014, 2:10 a.m. UTC
On Fri, 2014-12-05 at 17:13 -0800, Eric Dumazet wrote:

> I guess we could count number of spaces/fields in both lines,
> and disable the iproute2 trick if counts match.

Something like that maybe ?

 misc/nstat.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Vijay Subramanian Dec. 6, 2014, 3:45 a.m. UTC | #1
> Something like that maybe ?
>
>  misc/nstat.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> diff --git a/misc/nstat.c b/misc/nstat.c

Thanks Eric!
This works on current kernel and looks good to me for 2.4 too..

Tested-by: Vijay Subramanian <subramanian.vijay@gmail.com>


Vijay
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/nstat.c b/misc/nstat.c
index e54b3ae..c2cb056 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -156,6 +156,15 @@  static void load_good_table(FILE *fp)
 	}
 }
 
+static int count_spaces(const char *line)
+{
+	int count = 0;
+	char c;
+
+	while ((c = *line++) != 0)
+		count += c == ' ' || c == '\n';
+	return count;
+}
 
 static void load_ugly_table(FILE *fp)
 {
@@ -167,10 +176,12 @@  static void load_ugly_table(FILE *fp)
 		char idbuf[sizeof(buf)];
 		int  off;
 		char *p;
+		int count1, count2, skip = 0;
 
 		p = strchr(buf, ':');
 		if (!p)
 			abort();
+		count1 = count_spaces(buf);
 		*p = 0;
 		idbuf[0] = 0;
 		strncat(idbuf, buf, sizeof(idbuf) - 1);
@@ -199,6 +210,9 @@  static void load_ugly_table(FILE *fp)
 		n = db;
 		if (fgets(buf, sizeof(buf), fp) == NULL)
 			abort();
+		count2 = count_spaces(buf);
+		if (count2 > count1)
+			skip = count2 - count1;
 		do {
 			p = strrchr(buf, ' ');
 			if (!p)
@@ -207,8 +221,8 @@  static void load_ugly_table(FILE *fp)
 			if (sscanf(p+1, "%llu", &n->val) != 1)
 				abort();
 			/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
-			if (strcmp(idbuf, "IcmpOutAddrMaskReps") == 0)
-				idbuf[5] = 0;
+			if (skip)
+				skip--;
 			else
 				n = n->next;
 		} while (p > buf + off + 2);