From: Eric Dumazet Date: Sat, 6 Dec 2014 02:10:08 +0000 (-0800) Subject: iproute2/nstat: Bug in displaying icmp stats X-Git-Tag: v3.18.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d47179142725b67e1c3cf03bf37062e9ebc4cbd2;p=thirdparty%2Fiproute2.git iproute2/nstat: Bug in displaying icmp stats 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(-) Tested-by: Vijay Subramanian --- diff --git a/misc/nstat.c b/misc/nstat.c index e54b3ae7c..c2cb05646 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);