[package] base-files: Add support for assigning multiple IPv6 addresses on an interface
[openwrt.git] / package / wprobe / src / user / wprobe-util.c
index d5d440a..654442f 100644 (file)
@@ -82,7 +82,7 @@ wprobe_dump_data(struct wprobe_iface *dev)
        bool first = true;
 
        if (!simple_mode)
        bool first = true;
 
        if (!simple_mode)
-               fprintf(stderr, "\n");
+               fprintf(stdout, "\n");
        wprobe_request_data(dev, NULL);
        list_for_each_entry(attr, &dev->global_attr, list) {
                if (simple_mode) {
        wprobe_request_data(dev, NULL);
        list_for_each_entry(attr, &dev->global_attr, list) {
                if (simple_mode) {
@@ -90,7 +90,7 @@ wprobe_dump_data(struct wprobe_iface *dev)
                                fprintf(stdout, "[global]\n");
                        fprintf(stdout, "%s=%s\n", attr->name, wprobe_dump_value(attr));
                } else {
                                fprintf(stdout, "[global]\n");
                        fprintf(stdout, "%s=%s\n", attr->name, wprobe_dump_value(attr));
                } else {
-                       fprintf(stderr, (first ?
+                       fprintf(stdout, (first ?
                                "Global:            %s=%s\n" :
                                "                   %s=%s\n"),
                                attr->name,
                                "Global:            %s=%s\n" :
                                "                   %s=%s\n"),
                                attr->name,
@@ -105,8 +105,8 @@ wprobe_dump_data(struct wprobe_iface *dev)
                wprobe_request_data(dev, link->addr);
                list_for_each_entry(attr, &dev->link_attr, list) {
                        if (first) {
                wprobe_request_data(dev, link->addr);
                list_for_each_entry(attr, &dev->link_attr, list) {
                        if (first) {
-                               fprintf((simple_mode ? stdout : stderr),
-                                       (simple_mode ? 
+                               fprintf(stdout,
+                                       (simple_mode ?
                                         "[%02x:%02x:%02x:%02x:%02x:%02x]\n%s=%s\n" :
                                         "%02x:%02x:%02x:%02x:%02x:%02x: %s=%s\n"),
                                        link->addr[0], link->addr[1], link->addr[2],
                                         "[%02x:%02x:%02x:%02x:%02x:%02x]\n%s=%s\n" :
                                         "%02x:%02x:%02x:%02x:%02x:%02x: %s=%s\n"),
                                        link->addr[0], link->addr[1], link->addr[2],
@@ -115,7 +115,7 @@ wprobe_dump_data(struct wprobe_iface *dev)
                                        wprobe_dump_value(attr));
                                first = false;
                        } else {
                                        wprobe_dump_value(attr));
                                first = false;
                        } else {
-                               fprintf((simple_mode ? stdout : stderr),
+                               fprintf(stdout,
                                        (simple_mode ? "%s=%s\n" :
                                         "                   %s=%s\n"),
                                        attr->name,
                                        (simple_mode ? "%s=%s\n" :
                                         "                   %s=%s\n"),
                                        attr->name,
@@ -142,22 +142,24 @@ static const char *attr_typestr[] = {
 static int usage(const char *prog)
 {
        fprintf(stderr,
 static int usage(const char *prog)
 {
        fprintf(stderr,
-#ifndef NO_LOCAL_ACCESS 
+#ifndef NO_LOCAL_ACCESS
                "Usage: %s <interface>|<host>:<device>|-P [options]\n"
 #else
                "Usage: %s <host>:<device> [options]\n"
 #endif
                "\n"
                "Options:\n"
                "Usage: %s <interface>|<host>:<device>|-P [options]\n"
 #else
                "Usage: %s <host>:<device> [options]\n"
 #endif
                "\n"
                "Options:\n"
+               "  -a:            Print attributes\n"
                "  -c:            Only apply configuration\n"
                "  -d:            Delay between measurement dumps (in milliseconds, default: 1000)\n"
                "  -c:            Only apply configuration\n"
                "  -d:            Delay between measurement dumps (in milliseconds, default: 1000)\n"
+               "                 A value of 0 (zero) prints once and exits; useful for scripts\n"
                "  -f:            Dump contents of layer 2 filter counters during measurement\n"
                "  -F <file>:     Apply layer 2 filters from <file>\n"
                "  -h:            This help text\n"
                "  -i <interval>: Set measurement interval\n"
                "  -m:            Run measurement loop\n"
                "  -p:            Set the TCP port for server/client (default: 17990)\n"
                "  -f:            Dump contents of layer 2 filter counters during measurement\n"
                "  -F <file>:     Apply layer 2 filters from <file>\n"
                "  -h:            This help text\n"
                "  -i <interval>: Set measurement interval\n"
                "  -m:            Run measurement loop\n"
                "  -p:            Set the TCP port for server/client (default: 17990)\n"
-#ifndef NO_LOCAL_ACCESS 
+#ifndef NO_LOCAL_ACCESS
                "  -P:            Run in proxy mode (listen on network)\n"
 #endif
                "\n"
                "  -P:            Run in proxy mode (listen on network)\n"
 #endif
                "\n"
@@ -171,11 +173,11 @@ static void show_attributes(struct wprobe_iface *dev)
        if (simple_mode)
                return;
        list_for_each_entry(attr, &dev->global_attr, list) {
        if (simple_mode)
                return;
        list_for_each_entry(attr, &dev->global_attr, list) {
-               fprintf(stderr, "Global attribute: '%s' (%s)\n",
+               fprintf(stdout, "Global attribute: '%s' (%s)\n",
                        attr->name, attr_typestr[attr->type]);
        }
        list_for_each_entry(attr, &dev->link_attr, list) {
                        attr->name, attr_typestr[attr->type]);
        }
        list_for_each_entry(attr, &dev->link_attr, list) {
-               fprintf(stderr, "Link attribute: '%s' (%s)\n",
+               fprintf(stdout, "Link attribute: '%s' (%s)\n",
                        attr->name, attr_typestr[attr->type]);
        }
 }
                        attr->name, attr_typestr[attr->type]);
        }
 }
@@ -196,22 +198,23 @@ static void show_filter_simple(void *arg, const char *group, struct wprobe_filte
 static void show_filter(void *arg, const char *group, struct wprobe_filter_item *items, int n_items)
 {
        int i;
 static void show_filter(void *arg, const char *group, struct wprobe_filter_item *items, int n_items)
 {
        int i;
-       fprintf(stderr, "Filter group: '%s' (tx/rx)\n", group);
+       fprintf(stdout, "Filter group: '%s' (tx/rx)\n", group);
        for (i = 0; i < n_items; i++) {
        for (i = 0; i < n_items; i++) {
-               fprintf(stderr, " - %s (%lld/%lld)\n",
+               fprintf(stdout, " - %s (%lld/%lld)\n",
                        items[i].name, items[i].tx, items[i].rx);
        }
 }
 
 static void loop_measurement(struct wprobe_iface *dev, bool print_filters, unsigned long delay)
 {
                        items[i].name, items[i].tx, items[i].rx);
        }
 }
 
 static void loop_measurement(struct wprobe_iface *dev, bool print_filters, unsigned long delay)
 {
-       while (1) {
-               usleep(delay * 1000);
+       do {
                wprobe_update_links(dev);
                wprobe_dump_data(dev);
                if (print_filters)
                        wprobe_dump_filters(dev, simple_mode ? show_filter_simple : show_filter, NULL);
                wprobe_update_links(dev);
                wprobe_dump_data(dev);
                if (print_filters)
                        wprobe_dump_filters(dev, simple_mode ? show_filter_simple : show_filter, NULL);
+               usleep(delay * 1000);
        }
        }
+       while (delay);
 }
 
 static void set_filter(struct wprobe_iface *dev, const char *filename)
 }
 
 static void set_filter(struct wprobe_iface *dev, const char *filename)
@@ -296,7 +299,7 @@ static int run_proxy(int port)
                return 1;
        }
        while(1) {
                return 1;
        }
        while(1) {
-               unsigned int addrlen;
+               unsigned int addrlen = sizeof(struct sockaddr_in);
                int ret, c;
 
                c = accept(s, (struct sockaddr *)&sa, &addrlen);
                int ret, c;
 
                c = accept(s, (struct sockaddr *)&sa, &addrlen);
@@ -342,6 +345,7 @@ int main(int argc, char **argv)
                CMD_PROXY,
        } cmd = CMD_NONE;
        const char *filter = NULL;
                CMD_PROXY,
        } cmd = CMD_NONE;
        const char *filter = NULL;
+       bool print_attributes = false;
        bool print_filters = false;
        unsigned long delay = 1000;
        int interval = -1;
        bool print_filters = false;
        unsigned long delay = 1000;
        int interval = -1;
@@ -350,7 +354,7 @@ int main(int argc, char **argv)
        if (argc < 2)
                return usage(prog);
 
        if (argc < 2)
                return usage(prog);
 
-#ifndef NO_LOCAL_ACCESS 
+#ifndef NO_LOCAL_ACCESS
        if (!strcmp(argv[1], "-P")) {
                while ((ch = getopt(argc - 1, argv + 1, "p:")) != -1) {
                        switch(ch) {
        if (!strcmp(argv[1], "-P")) {
                while ((ch = getopt(argc - 1, argv + 1, "p:")) != -1) {
                        switch(ch) {
@@ -373,8 +377,11 @@ int main(int argc, char **argv)
        argv++;
        argc--;
 
        argv++;
        argc--;
 
-       while ((ch = getopt(argc, argv, "cd:fF:hi:msp:")) != -1) {
+       while ((ch = getopt(argc, argv, "acd:fF:hi:msp:")) != -1) {
                switch(ch) {
                switch(ch) {
+               case 'a':
+                       print_attributes = true;
+                       break;
                case 'c':
                        cmd = CMD_CONFIG;
                        break;
                case 'c':
                        cmd = CMD_CONFIG;
                        break;
@@ -415,7 +422,7 @@ int main(int argc, char **argv)
        if (!dev || (list_empty(&dev->global_attr) &&
                list_empty(&dev->link_attr))) {
                if (err)
        if (!dev || (list_empty(&dev->global_attr) &&
                list_empty(&dev->link_attr))) {
                if (err)
-                       fprintf(stderr, "%s\n", err);
+                       fprintf(stdout, "%s\n", err);
                else
                        fprintf(stderr, "Interface '%s' not found\n", ifname);
                return 1;
                else
                        fprintf(stderr, "Interface '%s' not found\n", ifname);
                return 1;
@@ -430,8 +437,10 @@ int main(int argc, char **argv)
                wprobe_apply_config(dev);
        }
 
                wprobe_apply_config(dev);
        }
 
-       if (cmd != CMD_CONFIG)
-               show_attributes(dev);
+       if (cmd != CMD_CONFIG) {
+               if (print_attributes)
+                       show_attributes(dev);
+       }
        if (cmd == CMD_MEASURE)
                loop_measurement(dev, print_filters, delay);
 
        if (cmd == CMD_MEASURE)
                loop_measurement(dev, print_filters, delay);
 
This page took 0.029638 seconds and 4 git commands to generate.