diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/in-addr-util.c | 13 | ||||
-rw-r--r-- | src/shared/in-addr-util.h | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/shared/in-addr-util.c b/src/shared/in-addr-util.c index e9a99177fc..459f846173 100644 --- a/src/shared/in-addr-util.c +++ b/src/shared/in-addr-util.c @@ -23,7 +23,7 @@ #include "in-addr-util.h" -int in_addr_null(int family, const union in_addr_union *u) { +int in_addr_is_null(int family, const union in_addr_union *u) { assert(u); if (family == AF_INET) @@ -39,6 +39,17 @@ int in_addr_null(int family, const union in_addr_union *u) { return -EAFNOSUPPORT; } +int in_addr_is_link_local(int family, const union in_addr_union *u) { + assert(u); + + if (family == AF_INET) + return (be32toh(u->in.s_addr) & 0xFFFF0000) == (169U << 24 | 254U << 16); + + if (family == AF_INET6) + return IN6_IS_ADDR_LINKLOCAL(&u->in6); + + return -EAFNOSUPPORT; +} int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) { assert(a); diff --git a/src/shared/in-addr-util.h b/src/shared/in-addr-util.h index cff2c321ed..7d1d6baa27 100644 --- a/src/shared/in-addr-util.h +++ b/src/shared/in-addr-util.h @@ -31,7 +31,8 @@ union in_addr_union { struct in6_addr in6; }; -int in_addr_null(int family, const union in_addr_union *u); +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_equal(int family, const union in_addr_union *a, const union in_addr_union *b); int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen); int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen); |