Skip to contentSkip to conversation

Make --set-counters (-c) accept comma separated counters

PATCH In review Henrik Nordstrom 2 participants 2 messages May 12, 2008 – May 13, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make --set-counters (-c) accept comma separated counters

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.

Regards
Henrik

ip6tables.c +7 -5
Index: iptables/ip6tables.c
===================================================================
@@ -1754,26 +1754,28 @@ int do_command6(int argc, char *argv[], 
 			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 */
iptables.c +7 -4
Index: iptables/iptables.c
===================================================================
@@ -1794,21 +1794,24 @@ int do_command(int argc, char *argv[], c
 			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));
#1 lore raw
Quoted 7 lines · Henrik Nordstrom

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.

Also applied, thanks Henrik.