aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-11-05 14:18:34 +0100
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-11-12 00:16:27 +0100
commit955e71001bd6d360805d2b33a9e6b9d6fd17397f (patch)
treed9feee8a560033d25b8f939dd1d9690ea87d504e /lib
parentf4f2f44072344bbf6083840f4df0dfaea5247c50 (diff)
[HICN-376] Add manual connection/route setting to face manager
Change-Id: I5c24f687e8e815d0e2f437ff8ce7fbb2c76e0579 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
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 */