]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: Introduce struct xt_option_entry::base
authorPhil Sutter <phil@nwl.cc>
Wed, 22 Nov 2023 19:43:40 +0000 (20:43 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 23 Nov 2023 17:01:21 +0000 (18:01 +0100)
Enable guided option parser users to parse integer values with a fixed
base.

Signed-off-by: Phil Sutter <phil@nwl.cc>
include/xtables.h
libxtables/xtoptions.c

index 1a9e08bb131abf0a4d1358881a6a4e74e312e405..b3c45c981b1c7153619e6ebf01d347404f5f140d 100644 (file)
@@ -122,6 +122,7 @@ enum xt_option_flags {
  * @size:      size of the item pointed to by @ptroff; this is a safeguard
  * @min:       lowest allowed value (for singular integral types)
  * @max:       highest allowed value (for singular integral types)
+ * @base:      assumed base of parsed value for integer types (default 0)
  */
 struct xt_option_entry {
        const char *name;
@@ -129,7 +130,7 @@ struct xt_option_entry {
        unsigned int id, excl, also, flags;
        unsigned int ptroff;
        size_t size;
-       unsigned int min, max;
+       unsigned int min, max, base;
 };
 
 /**
index 25540f8b88c6da9e3c4da9975b71454210aec542..4fd0e70e6b55588d5e7ae769b0028bf913cd9de1 100644 (file)
@@ -161,7 +161,8 @@ static void xtopt_parse_int(struct xt_option_call *cb)
        if (cb->entry->max != 0)
                lmax = cb->entry->max;
 
-       if (!xtables_strtoul(cb->arg, NULL, &value, lmin, lmax))
+       if (!xtables_strtoul_base(cb->arg, NULL, &value,
+                                 lmin, lmax, cb->entry->base))
                xt_params->exit_err(PARAMETER_PROBLEM,
                        "%s: bad value for option \"--%s\", "
                        "or out of range (%ju-%ju).\n",