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.
This commit is contained in:
Thomas Haller 2020-07-22 11:56:00 +02:00
parent 56a0aa06ac
commit 7ae8100d7a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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__ */