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 <subramanian.vijay@gmail.com>
This commit is contained in:
parent
d68e00f704
commit
d471791427
18
misc/nstat.c
18
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)
|
static void load_ugly_table(FILE *fp)
|
||||||
{
|
{
|
||||||
|
|
@ -167,10 +176,12 @@ static void load_ugly_table(FILE *fp)
|
||||||
char idbuf[sizeof(buf)];
|
char idbuf[sizeof(buf)];
|
||||||
int off;
|
int off;
|
||||||
char *p;
|
char *p;
|
||||||
|
int count1, count2, skip = 0;
|
||||||
|
|
||||||
p = strchr(buf, ':');
|
p = strchr(buf, ':');
|
||||||
if (!p)
|
if (!p)
|
||||||
abort();
|
abort();
|
||||||
|
count1 = count_spaces(buf);
|
||||||
*p = 0;
|
*p = 0;
|
||||||
idbuf[0] = 0;
|
idbuf[0] = 0;
|
||||||
strncat(idbuf, buf, sizeof(idbuf) - 1);
|
strncat(idbuf, buf, sizeof(idbuf) - 1);
|
||||||
|
|
@ -199,6 +210,9 @@ static void load_ugly_table(FILE *fp)
|
||||||
n = db;
|
n = db;
|
||||||
if (fgets(buf, sizeof(buf), fp) == NULL)
|
if (fgets(buf, sizeof(buf), fp) == NULL)
|
||||||
abort();
|
abort();
|
||||||
|
count2 = count_spaces(buf);
|
||||||
|
if (count2 > count1)
|
||||||
|
skip = count2 - count1;
|
||||||
do {
|
do {
|
||||||
p = strrchr(buf, ' ');
|
p = strrchr(buf, ' ');
|
||||||
if (!p)
|
if (!p)
|
||||||
|
|
@ -207,8 +221,8 @@ static void load_ugly_table(FILE *fp)
|
||||||
if (sscanf(p+1, "%llu", &n->val) != 1)
|
if (sscanf(p+1, "%llu", &n->val) != 1)
|
||||||
abort();
|
abort();
|
||||||
/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
|
/* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
|
||||||
if (strcmp(idbuf, "IcmpOutAddrMaskReps") == 0)
|
if (skip)
|
||||||
idbuf[5] = 0;
|
skip--;
|
||||||
else
|
else
|
||||||
n = n->next;
|
n = n->next;
|
||||||
} while (p > buf + off + 2);
|
} while (p > buf + off + 2);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue