From 4f838de4201322e6a74e1a0bb0639f22f27d4772 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 1 Feb 2019 21:23:02 +0000 Subject: [PATCH] lib: add sizing macro to ipaddr.h Useful for getting the size of the relevant data in the `ip` field of struct ipaddr. Signed-off-by: Quentin Young --- lib/ipaddr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ipaddr.h b/lib/ipaddr.h index f4ddadc66e..503431a7c0 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -56,6 +56,9 @@ struct ipaddr { #define SET_IPADDR_V4(p) (p)->ipa_type = IPADDR_V4 #define SET_IPADDR_V6(p) (p)->ipa_type = IPADDR_V6 +#define IPADDRSZ(p) \ + IS_IPADDR_V4((p)) ? sizeof(struct in_addr) : sizeof(struct in6_addr) + static inline int str2ipaddr(const char *str, struct ipaddr *ip) { int ret;