diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-08-08 18:09:36 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-08-09 22:09:34 +0200 |
commit | 365f8fa4628b371551d6f5b20651ac06239f905d (patch) | |
tree | d9682184d250bfaf884b7793426992ec54ec82fe /lib/in46_addr.c | |
parent | d1bf1e11ba72a5e46c0d85b845110bd56d8d6e20 (diff) |
in46_addr: Add new function in46a_prefix_equal()
This function is used to compare an IPv6 address against another,
using the smaller of the two prefix lengths.
Change-Id: Ic993d8abdc90897cb55276f01ae3b8a5eadf5a0d
Diffstat (limited to 'lib/in46_addr.c')
-rw-r--r-- | lib/in46_addr.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/in46_addr.c b/lib/in46_addr.c index 844e318..a220583 100644 --- a/lib/in46_addr.c +++ b/lib/in46_addr.c @@ -74,6 +74,23 @@ int in46a_equal(const struct in46_addr *a, const struct in46_addr *b) return 0; } +/*! Determine if two in46_addr prefix are equal or not + * The prefix length is determined by the shortest of the prefixes of a and b + * \returns 1 in case the common prefix are equal; 0 otherwise */ +int in46a_prefix_equal(const struct in46_addr *a, const struct in46_addr *b) +{ + unsigned int len; + if (a->len > b->len) + len = b->len; + else + len = a->len; + + if (!memcmp(&a->v6, &b->v6, len)) + return 1; + else + return 0; +} + /*! Match if IPv6 addr1 + addr2 are within same \a mask */ static int ipv6_within_mask(const struct in6_addr *addr1, const struct in6_addr *addr2, const struct in6_addr *mask) |