Skip to content

Commit

Permalink
Check /proc/net/snmp format for ICMP statistics
Browse files Browse the repository at this point in the history
"InCsumErrors" field was added following "InErrors" in the ICMP line of
statistics. So we may have two different formats to deal with: The old
one, where "InCsumErrors" doesn't exist, and the new one including
"InCsumErrors" field.
This patch adds a check to know which format it is and read the various
statistics at their right position.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
  • Loading branch information
sysstat committed Aug 15, 2015
1 parent 6993ba8 commit 789cd86
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions rd_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ void read_net_icmp(struct stats_net_icmp *st_net_icmp)
{
FILE *fp;
char line[1024];
static char format[256] = "";
int sw = FALSE;

if ((fp = fopen(NET_SNMP, "r")) == NULL)
Expand All @@ -1240,9 +1241,7 @@ void read_net_icmp(struct stats_net_icmp *st_net_icmp)

if (!strncmp(line, "Icmp:", 5)) {
if (sw) {
sscanf(line + 5, "%lu %*u %*u %*u %*u %*u %*u %*u " // 1 - 8, capture 1
"%lu %lu %lu %lu %lu %lu %lu %*u %*u %*u %*u " // 9 - 19, capture 9,10,11,12,13,14,15
"%*u %*u %lu %lu %lu %lu %lu %lu", // 20 - 27, capture 22,23,24,25,26,27
sscanf(line + 5, format,
&st_net_icmp->InMsgs,
&st_net_icmp->InEchos,
&st_net_icmp->InEchoReps,
Expand All @@ -1261,6 +1260,26 @@ void read_net_icmp(struct stats_net_icmp *st_net_icmp)
break;
}
else {
if (!strlen(format)) {
if (strstr(line, "InCsumErrors")) {
/*
* New format: InCsumErrors field exists at position #3.
* Capture: 1,9,10,11,12,13,14,15,22,23,24,25,26,27.
*/
strcpy(format, "%lu %*u %*u %*u %*u %*u %*u %*u "
"%lu %lu %lu %lu %lu %lu %lu %*u %*u %*u %*u "
"%*u %*u %lu %lu %lu %lu %lu %lu");
}
else {
/*
* Old format: InCsumErrors field doesn't exist.
* Capture: 1,8,9,10,11,12,13,14,21,22,23,24,25,26.
*/
strcpy(format, "%lu %*u %*u %*u %*u %*u %*u "
"%lu %lu %lu %lu %lu %lu %lu %*u %*u %*u %*u "
"%*u %*u %lu %lu %lu %lu %lu %lu");
}
}
sw = TRUE;
}
}
Expand Down

0 comments on commit 789cd86

Please sign in to comment.