]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Consolidate parse_counters()
authorPhil Sutter <phil@nwl.cc>
Thu, 2 Aug 2018 15:05:16 +0000 (17:05 +0200)
committerFlorian Westphal <fw@strlen.de>
Sat, 4 Aug 2018 12:26:46 +0000 (14:26 +0200)
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 <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/ip6tables-restore.c
iptables/iptables-restore.c
iptables/iptables-xml.c
iptables/xshared.c
iptables/xshared.h
iptables/xtables-restore.c

index 3065768ed8e6bccc04da1f18bdbed60d18f0609e..f2bd93d732d3c1dbfc994f7d7b9e65176bdf5d60 100644 (file)
@@ -79,17 +79,6 @@ static struct xtc_handle *create_handle(const char *tablename)
        return handle;
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-       unsigned long long pcnt, bcnt;
-       int ret;
-
-       ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-       ctr->pcnt = pcnt;
-       ctr->bcnt = bcnt;
-       return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;
index e52e8e47dda7485c8b84ebaab50147f24fad32cc..a1ae0311f508bc970c32cd709c75ab7ccc2bc766 100644 (file)
@@ -76,17 +76,6 @@ static struct xtc_handle *create_handle(const char *tablename)
        return handle;
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-       unsigned long long pcnt, bcnt;
-       int ret;
-
-       ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-       ctr->pcnt = pcnt;
-       ctr->bcnt = bcnt;
-       return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;
index a1b09f3ad745c45cacfea0cdb3c99e91ddbe4b9a..8ba45d55c079c442d2dff16d5418c9f88bba4e90 100644 (file)
@@ -50,22 +50,6 @@ print_usage(const char *name, const char *version)
        exit(1);
 }
 
-static int
-parse_counters(char *string, struct xt_counters *ctr)
-{
-       __u64 *pcnt, *bcnt;
-
-       if (string != NULL) {
-               pcnt = &ctr->pcnt;
-               bcnt = &ctr->bcnt;
-               return (sscanf
-                       (string, "[%llu:%llu]",
-                        (unsigned long long *)pcnt,
-                        (unsigned long long *)bcnt) == 2);
-       } else
-               return (0 == 2);
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static unsigned int newargc;
index 06db72d427e21581be9327c6a4e65570ecaf8845..ec5c49556b38d21d3765dbf768746a8ed4079da9 100644 (file)
@@ -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 &&
index 363549db78894008289ceee2e21745a81f9b43b4..55249341a19ba81151a59679eeba563e7daacf8d 100644 (file)
@@ -150,6 +150,7 @@ extern int xtables_lock_or_exit(int wait, struct timeval *tv);
 
 int parse_wait_time(int argc, char *argv[]);
 void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval);
+int parse_counters(const char *string, struct xt_counters *ctr);
 bool xs_has_arg(int argc, char *argv[]);
 
 extern const struct xtables_afinfo *afinfo;
index 0a3d1a311678239da382d295ec8f0ba1454c04b4..018d3fd3c80b097e80ba8bf2ef6bc11fc925e8c5 100644 (file)
@@ -56,17 +56,6 @@ static void print_usage(const char *name, const char *version)
                        "          [ --ipv6 ]\n", name);
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-       unsigned long long pcnt, bcnt;
-       int ret;
-
-       ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-       ctr->pcnt = pcnt;
-       ctr->bcnt = bcnt;
-       return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;