From 7653dcc3286067a25be6af47bcf84d3e8136ae39 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 18 Feb 2021 00:36:38 +0900 Subject: in-addr-util: introduce in_addr_is_set() or friends --- src/basic/in-addr-util.c | 8 +++++++- src/basic/in-addr-util.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index 641c5de7a3..6ee3a6ad63 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -24,6 +24,12 @@ bool in4_addr_is_null(const struct in_addr *a) { return a->s_addr == 0; } +bool in6_addr_is_null(const struct in6_addr *a) { + assert(a); + + return IN6_IS_ADDR_UNSPECIFIED(a); +} + int in_addr_is_null(int family, const union in_addr_union *u) { assert(u); @@ -31,7 +37,7 @@ int in_addr_is_null(int family, const union in_addr_union *u) { return in4_addr_is_null(&u->in); if (family == AF_INET6) - return IN6_IS_ADDR_UNSPECIFIED(&u->in6); + return in6_addr_is_null(&u->in6); return -EAFNOSUPPORT; } diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h index a5ce8258fd..f7cdf0d9bc 100644 --- a/src/basic/in-addr-util.h +++ b/src/basic/in-addr-util.h @@ -21,7 +21,24 @@ struct in_addr_data { }; bool in4_addr_is_null(const struct in_addr *a); +static inline bool in4_addr_is_set(const struct in_addr *a) { + return !in4_addr_is_null(a); +} +bool in6_addr_is_null(const struct in6_addr *a); +static inline bool in6_addr_is_set(const struct in6_addr *a) { + return !in6_addr_is_null(a); +} int in_addr_is_null(int family, const union in_addr_union *u); +static inline bool in_addr_is_set(int family, const union in_addr_union *u) { + return in_addr_is_null(family, u) == 0; +} +static inline int in_addr_data_is_null(const struct in_addr_data *a) { + assert(a); + return in_addr_is_null(a->family, &a->address); +} +static inline bool in_addr_data_is_set(const struct in_addr_data *a) { + return in_addr_data_is_null(a); +} int in_addr_is_multicast(int family, const union in_addr_union *u); -- cgit v1.2.3