From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 3/6] libxtables: Introduce xtables_strtoul_base()
Date: Wed, 22 Nov 2023 22:52:58 +0100 [thread overview]
Message-ID: <20231122215301.15725-4-phil@nwl.cc> (raw)
In-Reply-To: <20231122215301.15725-1-phil@nwl.cc>
Semantically identical to xtables_strtoul() but accepts the base as
parameter so callers may force it irrespective of number prefix. The old
xtables_strtoul() becomes a shallow wrapper.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/xtables.h | 2 ++
libxtables/xtables.c | 16 +++++++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/include/xtables.h b/include/xtables.h
index 087a1d600f9ae..1a9e08bb131ab 100644
--- a/include/xtables.h
+++ b/include/xtables.h
@@ -486,6 +486,8 @@ extern void xtables_register_matches(struct xtables_match *, unsigned int);
extern void xtables_register_target(struct xtables_target *me);
extern void xtables_register_targets(struct xtables_target *, unsigned int);
+extern bool xtables_strtoul_base(const char *, char **, uintmax_t *,
+ uintmax_t, uintmax_t, unsigned int);
extern bool xtables_strtoul(const char *, char **, uintmax_t *,
uintmax_t, uintmax_t);
extern bool xtables_strtoui(const char *, char **, unsigned int *,
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index ba9ceaeb3da41..b4339e8d31275 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -580,23 +580,23 @@ int xtables_load_ko(const char *modprobe, bool quiet)
}
/**
- * xtables_strtou{i,l} - string to number conversion
+ * xtables_strtoul_base - string to number conversion
* @s: input string
* @end: like strtoul's "end" pointer
* @value: pointer for result
* @min: minimum accepted value
* @max: maximum accepted value
+ * @base: assumed base of value
*
* If @end is NULL, we assume the caller wants a "strict strtoul", and hence
* "15a" is rejected.
* In either case, the value obtained is compared for min-max compliance.
- * Base is always 0, i.e. autodetect depending on @s.
*
* Returns true/false whether number was accepted. On failure, *value has
* undefined contents.
*/
-bool xtables_strtoul(const char *s, char **end, uintmax_t *value,
- uintmax_t min, uintmax_t max)
+bool xtables_strtoul_base(const char *s, char **end, uintmax_t *value,
+ uintmax_t min, uintmax_t max, unsigned int base)
{
uintmax_t v;
const char *p;
@@ -608,7 +608,7 @@ bool xtables_strtoul(const char *s, char **end, uintmax_t *value,
;
if (*p == '-')
return false;
- v = strtoumax(s, &my_end, 0);
+ v = strtoumax(s, &my_end, base);
if (my_end == s)
return false;
if (end != NULL)
@@ -625,6 +625,12 @@ bool xtables_strtoul(const char *s, char **end, uintmax_t *value,
return false;
}
+bool xtables_strtoul(const char *s, char **end, uintmax_t *value,
+ uintmax_t min, uintmax_t max)
+{
+ return xtables_strtoul_base(s, end, value, min, max, 0);
+}
+
bool xtables_strtoui(const char *s, char **end, unsigned int *value,
unsigned int min, unsigned int max)
{
--
2.41.0
next prev parent reply other threads:[~2023-11-22 21:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 21:52 [iptables PATCH 0/6] Extend guided option parser for use by arptables Phil Sutter
2023-11-22 21:52 ` [iptables PATCH 1/6] libxtables: Combine the two extension option mergers Phil Sutter
2023-11-22 21:52 ` [iptables PATCH 2/6] libxtables: Fix guided option parser for use with arptables Phil Sutter
2023-11-22 21:52 ` Phil Sutter [this message]
2023-11-22 21:52 ` [iptables PATCH 4/6] libxtables: Introduce struct xt_option_entry::base Phil Sutter
2023-11-22 21:53 ` [iptables PATCH 5/6] extensions: libarpt_mangle: Use guided option parser Phil Sutter
2023-11-22 21:53 ` [iptables PATCH 6/6] extensions: MARK: arptables: " Phil Sutter
2023-11-23 16:55 ` [iptables PATCH 0/6] Extend guided option parser for use by arptables Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231122215301.15725-4-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).