]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/nstat.c
ss: Actually print left delimiter for columns
[mirror_iproute2.git] / misc / nstat.c
index 6143719e3a07a7d7f01f714323bdf84b513f590c..88f1c7698243235b12f58cd067afce488af1be4c 100644 (file)
@@ -37,7 +37,6 @@ int reset_history;
 int ignore_history;
 int no_output;
 int json_output;
-int pretty;
 int no_update;
 int scan_interval;
 int time_constant;
@@ -76,6 +75,11 @@ static int net_snmp6_open(void)
        return generic_proc_open("PROC_NET_SNMP6", "net/snmp6");
 }
 
+static int net_sctp_snmp_open(void)
+{
+       return generic_proc_open("PROC_NET_SCTP_SNMP", "net/sctp/snmp");
+}
+
 struct nstat_ent {
        struct nstat_ent *next;
        char             *id;
@@ -173,12 +177,12 @@ static int count_spaces(const char *line)
 
 static void load_ugly_table(FILE *fp)
 {
-       char buf[4096];
+       char buf[2048];
        struct nstat_ent *db = NULL;
        struct nstat_ent *n;
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
-               char idbuf[sizeof(buf)];
+               char idbuf[4096];
                int  off;
                char *p;
                int count1, count2, skip = 0;
@@ -247,6 +251,16 @@ static void load_ugly_table(FILE *fp)
        }
 }
 
+static void load_sctp_snmp(void)
+{
+       FILE *fp = fdopen(net_sctp_snmp_open(), "r");
+
+       if (fp) {
+               load_good_table(fp);
+               fclose(fp);
+       }
+}
+
 static void load_snmp(void)
 {
        FILE *fp = fdopen(net_snmp_open(), "r");
@@ -391,6 +405,7 @@ static void update_db(int interval)
        load_netstat();
        load_snmp6();
        load_snmp();
+       load_sctp_snmp();
 
        h = kern_db;
        kern_db = n;
@@ -450,6 +465,7 @@ static void server_loop(int fd)
        load_netstat();
        load_snmp6();
        load_snmp();
+       load_sctp_snmp();
 
        for (;;) {
                int status;
@@ -509,17 +525,17 @@ static void usage(void)
 {
        fprintf(stderr,
 "Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
-"   -h, --help         this message\n"
-"   -a, --ignore       ignore history\n"
-"   -d, --scan=SECS    sample every statistics every SECS\n"
-"   -j, --json          format output in JSON\n"
-"   -n, --nooutput     do history only\n"
-"   -p, --pretty        pretty print\n"
-"   -r, --reset                reset history\n"
-"   -s, --noupdate     don\'t update history\n"
-"   -t, --interval=SECS        report average over the last SECS\n"
-"   -V, --version      output version information\n"
-"   -z, --zeros                show entries with zero activity\n");
+"   -h, --help           this message\n"
+"   -a, --ignore         ignore history\n"
+"   -d, --scan=SECS      sample every statistics every SECS\n"
+"   -j, --json           format output in JSON\n"
+"   -n, --nooutput       do history only\n"
+"   -p, --pretty         pretty print\n"
+"   -r, --reset          reset history\n"
+"   -s, --noupdate       don't update history\n"
+"   -t, --interval=SECS  report average over the last SECS\n"
+"   -V, --version        output version information\n"
+"   -z, --zeros          show entries with zero activity\n");
        exit(-1);
 }
 
@@ -689,12 +705,18 @@ int main(int argc, char *argv[])
            && verify_forging(fd) == 0) {
                FILE *sfp = fdopen(fd, "r");
 
-               load_good_table(sfp);
-               if (hist_db && source_mismatch) {
-                       fprintf(stderr, "nstat: history is stale, ignoring it.\n");
-                       hist_db = NULL;
+               if (!sfp) {
+                       fprintf(stderr, "nstat: fdopen failed: %s\n",
+                               strerror(errno));
+                       close(fd);
+               } else {
+                       load_good_table(sfp);
+                       if (hist_db && source_mismatch) {
+                               fprintf(stderr, "nstat: history is stale, ignoring it.\n");
+                               hist_db = NULL;
+                       }
+                       fclose(sfp);
                }
-               fclose(sfp);
        } else {
                if (fd >= 0)
                        close(fd);
@@ -706,6 +728,7 @@ int main(int argc, char *argv[])
                load_netstat();
                load_snmp6();
                load_snmp();
+               load_sctp_snmp();
                if (info_source[0] == 0)
                        strcpy(info_source, "kernel");
        }