aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/includes/hicn/util/ip_address.h2
-rw-r--r--lib/src/util/ip_address.c29
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h
index 33c0d9ab5..d9dea8faa 100644
--- a/lib/includes/hicn/util/ip_address.h
+++ b/lib/includes/hicn/util/ip_address.h
@@ -148,7 +148,7 @@ int ip_prefix_ntop (const ip_prefix_t * ip_prefix, char *dst, size_t size);
int ip_prefix_len (const ip_prefix_t * prefix);
bool ip_prefix_empty (const ip_prefix_t * prefix);
int ip_prefix_to_sockaddr(const ip_prefix_t * prefix, struct sockaddr *sa);
-
+int ip_prefix_cmp(const ip_prefix_t * prefix1, const ip_prefix_t * prefix2);
/* URL */
diff --git a/lib/src/util/ip_address.c b/lib/src/util/ip_address.c
index 938c0e49d..062ff8c75 100644
--- a/lib/src/util/ip_address.c
+++ b/lib/src/util/ip_address.c
@@ -179,7 +179,16 @@ ip_address_to_sockaddr(const ip_address_t * ip_address,
int
ip_address_cmp(const ip_address_t * ip1, const ip_address_t * ip2, int family)
{
- return memcmp(ip1, ip2, ip_address_len(family));
+ switch(family) {
+ case AF_INET:
+ return memcmp(&ip1->v4, &ip2->v4, sizeof(ip1->v4));
+ break;
+ case AF_INET6:
+ return memcmp(&ip1->v6, &ip2->v6, sizeof(ip1->v6));
+ break;
+ default:
+ return memcmp(ip1, ip2, sizeof(ip_address_t));
+ }
}
int
@@ -312,13 +321,29 @@ ip_prefix_empty (const ip_prefix_t * prefix)
return prefix->len == 0;
}
-int ip_prefix_to_sockaddr(const ip_prefix_t * prefix,
+int
+ip_prefix_to_sockaddr(const ip_prefix_t * prefix,
struct sockaddr *sa)
{
// XXX assert len == ip_address_len
return ip_address_to_sockaddr(&prefix->address, sa, prefix->family);
}
+int
+ip_prefix_cmp(const ip_prefix_t * prefix1, const ip_prefix_t * prefix2)
+{
+ if (prefix1->family < prefix2->family)
+ return -1;
+ else if (prefix1->family > prefix2->family)
+ return 1;
+
+ if (prefix1->len < prefix2->len)
+ return -1;
+ else if (prefix1->len > prefix2->len)
+ return 1;
+
+ return ip_address_cmp(&prefix1->address, &prefix2->address, prefix1->family);
+}
/* URL */