]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/lnstat.c
ss: sctp: fix typo for nodelay
[mirror_iproute2.git] / misc / lnstat.c
index 1e547d063eeb568bdf5fb232906401f6a2d5e103..e3c8421194e9f5c91758a73c7eaae55b262b153d 100644 (file)
@@ -55,27 +55,31 @@ static struct option opts[] = {
 
 static int usage(char *name, int exit_code)
 {
-       fprintf(stderr, "%s Version %s\n", name, LNSTAT_VERSION);
-       fprintf(stderr, "Copyright (C) 2004 by Harald Welte "
-                       "<laforge@gnumonks.org>\n");
-       fprintf(stderr, "This program is free software licensed under GNU GPLv2"
-                       "\nwith ABSOLUTELY NO WARRANTY.\n\n");
-       fprintf(stderr, "Parameters:\n");
-       fprintf(stderr, "\t-V --version\t\tPrint Version of Program\n");
-       fprintf(stderr, "\t-c --count <count>\t"
-                       "Print <count> number of intervals\n");
-       fprintf(stderr, "\t-d --dump\t\t"
-                       "Dump list of available files/keys\n");
-       fprintf(stderr, "\t-j --json\t\t"
-                       "Display in JSON format\n");
-       fprintf(stderr, "\t-f --file <file>\tStatistics file to use\n");
-       fprintf(stderr, "\t-h --help\t\tThis help message\n");
-       fprintf(stderr, "\t-i --interval <intv>\t"
-                       "Set interval to 'intv' seconds\n");
-       fprintf(stderr, "\t-k --keys k,k,k,...\tDisplay only keys specified\n");
-       fprintf(stderr, "\t-s --subject [0-2]\t?\n");
-       fprintf(stderr, "\t-w --width n,n,n,...\tWidth for each field\n");
-       fprintf(stderr, "\n");
+       fprintf(stderr,
+               "%s Version %s\n"
+               "Copyright (C) 2004 by Harald Welte <laforge@gnumonks.org>\n"
+               "This program is free software licensed under GNU GPLv2\nwith ABSOLUTELY NO WARRANTY.\n"
+               "\n"
+               "Parameters:\n"
+               "       -V --version            Print Version of Program\n"
+               "       -c --count <count>      "
+               "Print <count> number of intervals\n"
+               "       -d --dump               "
+               "Dump list of available files/keys\n"
+               "       -j --json               "
+               "Display in JSON format\n"
+               "       -f --file <file>        Statistics file to use\n"
+               "       -h --help               This help message\n"
+               "       -i --interval <intv>    "
+               "Set interval to 'intv' seconds\n"
+               "       -k --keys k,k,k,...     Display only keys specified\n"
+               "       -s --subject [0-2]      Control header printing:\n"
+               "                               0 = never\n"
+               "                               1 = once\n"
+               "                               2 = every 20 lines (default))\n"
+               "       -w --width n,n,n,...    Width for each field\n"
+               "\n",
+               name, LNSTAT_VERSION);
 
        exit(exit_code);
 }
@@ -142,14 +146,13 @@ static int map_field_params(struct lnstat_file *lnstat_files,
 
                                if (++j >= MAX_FIELDS - 1) {
                                        fprintf(stderr,
-                                               "WARN: MAX_FIELDS (%d) reached,"
-                                               " truncating number of keys\n",
+                                               "WARN: MAX_FIELDS (%d) reached, truncating number of keys\n",
                                                MAX_FIELDS);
                                        goto full;
                                }
                        }
                }
-       full:
+full:
                fps->num = j;
                return 1;
        }
@@ -178,14 +181,12 @@ static struct table_hdr *build_hdr_string(struct lnstat_file *lnstat_files,
                                          struct field_params *fps,
                                          int linewidth)
 {
-       int h,i;
+       int h, i;
        static struct table_hdr th;
        int ofs = 0;
 
-       for (i = 0; i < HDR_LINES; i++) {
-               th.hdr[i] = malloc(HDR_LINE_LENGTH);
-               memset(th.hdr[i], 0, HDR_LINE_LENGTH);
-       }
+       for (i = 0; i < HDR_LINES; i++)
+               th.hdr[i] = calloc(1, HDR_LINE_LENGTH);
 
        for (i = 0; i < fps->num; i++) {
                char *cname, *fname = fps->params[i].lf->name;
@@ -266,7 +267,7 @@ int main(int argc, char **argv)
                num_req_files = 1;
        }
 
-       while ((c = getopt_long(argc, argv,"Vc:djpf:h?i:k:s:w:",
+       while ((c = getopt_long(argc, argv, "Vc:djpf:h?i:k:s:w:",
                                opts, NULL)) != -1) {
                int len = 0;
                char *tmp, *tok;
@@ -300,8 +301,7 @@ int main(int argc, char **argv)
                             tok = strtok(NULL, ",")) {
                                if (fp.num >= MAX_FIELDS) {
                                        fprintf(stderr,
-                                               "WARN: too many keys"
-                                               " requested: (%d max)\n",
+                                               "WARN: too many keys requested: (%d max)\n",
                                                MAX_FIELDS);
                                        break;
                                }
@@ -353,24 +353,22 @@ int main(int argc, char **argv)
                if (!header)
                        exit(1);
 
-               if (interval < 1 )
+               if (interval < 1)
                        interval = 1;
 
-               for (i = 0; i < count || !count; ) {
+               for (i = 0; i < count || !count; i++) {
                        lnstat_update(lnstat_files);
                        if (mode == MODE_JSON)
                                print_json(stdout, lnstat_files, &fp);
                        else {
-                               if  ((hdr > 1 &&
-                                     (! (i % 20))) || (hdr == 1 && i == 0))
+                               if  ((hdr > 1 && !(i % 20)) ||
+                                    (hdr == 1 && i == 0))
                                        print_hdr(stdout, header);
                                print_line(stdout, lnstat_files, &fp);
                        }
                        fflush(stdout);
                        if (i < count - 1 || !count)
                                sleep(interval);
-                       if (count)
-                               ++i;
                }
                break;
        }