]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/nstat.c
ss: do not emit warn while dumping MPTCP on old kernels
[mirror_iproute2.git] / misc / nstat.c
index 23113b223b22d5db1c82bf28c26105936ee6776b..ecdd4ce8266db0aa3825f2bd39986bc186ff846e 100644 (file)
@@ -29,7 +29,7 @@
 #include <getopt.h>
 
 #include <json_writer.h>
-#include <SNAPSHOT.h>
+#include "version.h"
 #include "utils.h"
 
 int dump_zeros;
@@ -114,7 +114,7 @@ static int match(const char *id)
                return 1;
 
        for (i = 0; i < npatterns; i++) {
-               if (!fnmatch(patterns[i], id, 0))
+               if (!fnmatch(patterns[i], id, FNM_CASEFOLD))
                        return 1;
        }
        return 0;
@@ -136,20 +136,24 @@ static void load_good_table(FILE *fp)
                        buf[strlen(buf)-1] = 0;
                        if (info_source[0] && strcmp(info_source, buf+1))
                                source_mismatch = 1;
-                       info_source[0] = 0;
-                       strncat(info_source, buf+1, sizeof(info_source)-1);
+                       strlcpy(info_source, buf + 1, sizeof(info_source));
                        continue;
                }
                /* idbuf is as big as buf, so this is safe */
                nr = sscanf(buf, "%s%llu%lg", idbuf, &val, &rate);
-               if (nr < 2)
-                       abort();
+               if (nr < 2) {
+                       fprintf(stderr, "%s:%d: error parsing history file\n",
+                               __FILE__, __LINE__);
+                       exit(-2);
+               }
                if (nr < 3)
                        rate = 0;
                if (useless_number(idbuf))
                        continue;
-               if ((n = malloc(sizeof(*n))) == NULL)
-                       abort();
+               if ((n = malloc(sizeof(*n))) == NULL) {
+                       perror("nstat: malloc");
+                       exit(-1);
+               }
                n->id = strdup(idbuf);
                n->val = val;
                n->rate = rate;
@@ -190,8 +194,11 @@ static void load_ugly_table(FILE *fp)
                int count1, count2, skip = 0;
 
                p = strchr(buf, ':');
-               if (!p)
-                       abort();
+               if (!p) {
+                       fprintf(stderr, "%s:%d: error parsing history file\n",
+                               __FILE__, __LINE__);
+                       exit(-2);
+               }
                count1 = count_spaces(buf);
                *p = 0;
                idbuf[0] = 0;
@@ -211,8 +218,10 @@ static void load_ugly_table(FILE *fp)
                                strncat(idbuf, p, sizeof(idbuf) - off - 1);
                        }
                        n = malloc(sizeof(*n));
-                       if (!n)
-                               abort();
+                       if (!n) {
+                               perror("nstat: malloc");
+                               exit(-1);
+                       }
                        n->id = strdup(idbuf);
                        n->rate = 0;
                        n->next = db;
@@ -221,18 +230,27 @@ static void load_ugly_table(FILE *fp)
                }
                n = db;
                nread = getline(&buf, &buflen, fp);
-               if (nread == -1)
-                       abort();
+               if (nread == -1) {
+                       fprintf(stderr, "%s:%d: error parsing history file\n",
+                               __FILE__, __LINE__);
+                       exit(-2);
+               }
                count2 = count_spaces(buf);
                if (count2 > count1)
                        skip = count2 - count1;
                do {
                        p = strrchr(buf, ' ');
-                       if (!p)
-                               abort();
+                       if (!p) {
+                               fprintf(stderr, "%s:%d: error parsing history file\n",
+                                       __FILE__, __LINE__);
+                               exit(-2);
+                       }
                        *p = 0;
-                       if (sscanf(p+1, "%llu", &n->val) != 1)
-                               abort();
+                       if (sscanf(p+1, "%llu", &n->val) != 1) {
+                               fprintf(stderr, "%s:%d: error parsing history file\n",
+                                       __FILE__, __LINE__);
+                               exit(-2);
+                       }
                        /* Trick to skip "dummy" trailing ICMP MIB in 2.4 */
                        if (skip)
                                skip--;
@@ -602,7 +620,7 @@ int main(int argc, char *argv[])
                        break;
                case 'v':
                case 'V':
-                       printf("nstat utility, iproute2-ss%s\n", SNAPSHOT);
+                       printf("nstat utility, iproute2-%s\n", version);
                        exit(0);
                case 'h':
                case '?':