From b55013b1a7e7dd7e4e90455703d272b9ffc28b64 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 20 Sep 2024 14:12:44 +1000 Subject: inany: Add inany_pton() helper We already have an inany_ntop() function to format inany addresses into text. Add inany_pton() to parse them from text, and use it in conf_ports(). Signed-off-by: David Gibson --- inany.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'inany.c') diff --git a/inany.c b/inany.c index 5e391dc..f5483bf 100644 --- a/inany.c +++ b/inany.c @@ -36,3 +36,23 @@ const char *inany_ntop(const union inany_addr *src, char *dst, socklen_t size) return inet_ntop(AF_INET6, &src->a6, dst, size); } + +/** inany_pton - Parse an IPv[46] address from text format + * @src: IPv[46] address + * @dst: output buffer, filled with parsed address + * + * Return: On success, 1, if no parseable address is found, 0 + */ +int inany_pton(const char *src, union inany_addr *dst) +{ + if (inet_pton(AF_INET, src, &dst->v4mapped.a4)) { + memset(&dst->v4mapped.zero, 0, sizeof(dst->v4mapped.zero)); + memset(&dst->v4mapped.one, 0xff, sizeof(dst->v4mapped.one)); + return 1; + } + + if (inet_pton(AF_INET6, src, &dst->a6)) + return 1; + + return 0; +} -- cgit v1.2.3