]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
iproute2/nstat: Bug in displaying icmp stats
authorEric Dumazet <eric.dumazet@gmail.com>
Sat, 6 Dec 2014 02:10:08 +0000 (18:10 -0800)
committerStephen Hemminger <shemming@brocade.com>
Wed, 10 Dec 2014 04:33:32 +0000 (20:33 -0800)
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 <subramanian.vijay@gmail.com>
misc/nstat.c

index e54b3ae7c28b1025171f398390a98cffea150fa7..c2cb056466505ccc09540c8cc08a07097dd47eff 100644 (file)
@@ -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);