summaryrefslogtreecommitdiffstats
path: root/lib/src/util/ip_address.c
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/src/util/ip_address.c
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/src/util/ip_address.c')
-rw-r--r--lib/src/util/ip_address.c29
1 files changed, 27 insertions, 2 deletions
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 */