summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-02 20:34:21 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-06 19:59:09 +0200
commit34380032fb8bdfd801fbd43c03acfb7ac664d2bb (patch)
treedfa2a75dee05eb9383d052eff00c14f842ed1bf0 /src
parentc917a32122ac18c9b6112d67fbb815d84a053e4a (diff)
util: make it easier to check whether in_addr or in6_addr addresses are NULL
Diffstat (limited to 'src')
-rw-r--r--src/basic/in-addr-util.c20
-rw-r--r--src/basic/in-addr-util.h3
2 files changed, 17 insertions, 6 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index 245107ebb8..1447fa84aa 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -28,18 +28,26 @@
#include "macro.h"
#include "util.h"
+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) {
+ return
+ a->s6_addr32[0] == 0 &&
+ a->s6_addr32[1] == 0 &&
+ a->s6_addr32[2] == 0 &&
+ a->s6_addr32[3] == 0;
+}
+
int in_addr_is_null(int family, const union in_addr_union *u) {
assert(u);
if (family == AF_INET)
- return u->in.s_addr == 0;
+ return in4_addr_is_null(&u->in);
if (family == AF_INET6)
- return
- u->in6.s6_addr32[0] == 0 &&
- u->in6.s6_addr32[1] == 0 &&
- u->in6.s6_addr32[2] == 0 &&
- u->in6.s6_addr32[3] == 0;
+ 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 17798ce816..62cc1e1aa4 100644
--- a/src/basic/in-addr-util.h
+++ b/src/basic/in-addr-util.h
@@ -36,6 +36,9 @@ struct in_addr_data {
union in_addr_union address;
};
+bool in4_addr_is_null(const struct in_addr *a);
+bool in6_addr_is_null(const struct in6_addr *a);
+
int in_addr_is_null(int family, const union in_addr_union *u);
int in_addr_is_link_local(int family, const union in_addr_union *u);
int in_addr_is_localhost(int family, const union in_addr_union *u);