From 7ae8100d7a6674c01414e50dbe27d1fb62b96d87 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 22 Jul 2020 11:56:00 +0200 Subject: [PATCH] shared: add NM_IS_IPv4() macro This is of course trivial. However, we use this macro at several places as and index into an array of length 2, to lookup either the IPv4 or IPv6 element. As such, this MUST return 0 or 1. This promise is what the macro should convey. --- shared/nm-std-aux/nm-std-aux.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h index ea43c96965..91cd6c37fa 100644 --- a/shared/nm-std-aux/nm-std-aux.h +++ b/shared/nm-std-aux/nm-std-aux.h @@ -667,4 +667,13 @@ nm_utils_addr_family_from_size (size_t len) #define nm_assert_addr_family(addr_family) \ nm_assert (NM_IN_SET ((addr_family), NM_AF_INET, NM_AF_INET6)) +#define NM_IS_IPv4(addr_family) \ + ({ \ + const int _addr_family = (addr_family); \ + \ + nm_assert_addr_family (_addr_family); \ + \ + (_addr_family == NM_AF_INET); \ + }) + #endif /* __NM_STD_AUX_H__ */