]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Make --set-counters (-c) accept comma separated counters
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Tue, 13 May 2008 11:10:38 +0000 (13:10 +0200)
committerPatrick McHardy <kaber@trash.net>
Tue, 13 May 2008 11:10:38 +0000 (13:10 +0200)
Here is the --set-counters syntax patch requested earlier today making
--set-counters (-c) accept comma separated counts.

-c packets,bytes

I have not updated the manpage to reflect this alternate syntax for the
--set-counters (-c) option.

Henrik Nordstrom <henrik@henriknordstrom.net>

ip6tables.c
iptables.c

index d89a50f9f0e1d57cbca026a4b220926631c0fd7b..9b68fba3e27e18ed95e620d4ce3cf1c1ba59aa19 100644 (file)
@@ -1754,26 +1754,28 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
                        set_option(&options, OPT_COUNTERS, &fw.ipv6.invflags,
                                   invert);
                        pcnt = optarg;
-                       if (optind < argc && argv[optind][0] != '-'
+                       bcnt = strchr(pcnt + 1, ',');
+                       if (bcnt)
+                           bcnt++;
+                       if (!bcnt && optind < argc && argv[optind][0] != '-'
                            && argv[optind][0] != '!')
                                bcnt = argv[optind++];
-                       else
+                       if (!bcnt)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c requires packet and byte counter",
                                        opt2char(OPT_COUNTERS));
 
-                       if (sscanf(pcnt, "%llu", (unsigned long long *)&cnt) != 1)
+                       if (sscanf(pcnt, "%llu", &cnt) != 1)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c packet counter not numeric",
                                        opt2char(OPT_COUNTERS));
                        fw.counters.pcnt = cnt;
 
-                       if (sscanf(bcnt, "%llu", (unsigned long long *)&cnt) != 1)
+                       if (sscanf(bcnt, "%llu", &cnt) != 1)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c byte counter not numeric",
                                        opt2char(OPT_COUNTERS));
                        fw.counters.bcnt = cnt;
-
                        break;
 
                case 1: /* non option */
index f2a7d25e15ba78792b6206b723576cbd95850b5f..cff8cf4fcd1627fa494c8a3bfc31b48d03b29b69 100644 (file)
@@ -1794,21 +1794,24 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)
                        set_option(&options, OPT_COUNTERS, &fw.ip.invflags,
                                   invert);
                        pcnt = optarg;
-                       if (optind < argc && argv[optind][0] != '-'
+                       bcnt = strchr(pcnt + 1, ',');
+                       if (bcnt)
+                           bcnt++;
+                       if (!bcnt && optind < argc && argv[optind][0] != '-'
                            && argv[optind][0] != '!')
                                bcnt = argv[optind++];
-                       else
+                       if (!bcnt)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c requires packet and byte counter",
                                        opt2char(OPT_COUNTERS));
 
-                       if (sscanf(pcnt, "%llu", (unsigned long long *)&cnt) != 1)
+                       if (sscanf(pcnt, "%llu", &cnt) != 1)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c packet counter not numeric",
                                        opt2char(OPT_COUNTERS));
                        fw.counters.pcnt = cnt;
 
-                       if (sscanf(bcnt, "%llu", (unsigned long long *)&cnt) != 1)
+                       if (sscanf(bcnt, "%llu", &cnt) != 1)
                                exit_error(PARAMETER_PROBLEM,
                                        "-%c byte counter not numeric",
                                        opt2char(OPT_COUNTERS));