From 1cc09188079a64dc8b733f198c959cfb441e6e20 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 2 Aug 2018 17:05:16 +0200 Subject: xshared: Consolidate parse_counters() Move this helper function into xshared. While being at it, drop the need for temporary variables and take over null pointer tolerance from the implementation in iptables-xml.c. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- iptables/xshared.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'iptables/xshared.c') diff --git a/iptables/xshared.c b/iptables/xshared.c index 06db72d4..ec5c4955 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -359,6 +359,20 @@ void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval) xtables_error(PARAMETER_PROBLEM, "wait interval not numeric"); } +int parse_counters(const char *string, struct xt_counters *ctr) +{ + int ret; + + if (!string) + return 0; + + ret = sscanf(string, "[%llu:%llu]", + (unsigned long long *)&ctr->pcnt, + (unsigned long long *)&ctr->bcnt); + + return ret == 2; +} + inline bool xs_has_arg(int argc, char *argv[]) { return optind < argc && -- cgit v1.2.3