]> granicus.if.org Git - sysstat/commitdiff
Check /proc/net/snmp format for ICMP statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 15 Aug 2015 12:39:21 +0000 (14:39 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 15 Aug 2015 12:39:21 +0000 (14:39 +0200)
"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>
rd_stats.c

index 153cfd9b12fd92add7c64c6dd34d3501b6780306..009b770b4c331fdc467e5b0d5dfd643d11fbcefe 100644 (file)
@@ -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)
@@ -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,
@@ -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;
                        }
                }