diff options
author | Michele Papalini <micpapal@cisco.com> | 2019-11-12 13:19:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2019-11-12 13:19:55 +0000 |
commit | 4f57ca72e8131e5cfb023b26417b924e774d5e73 (patch) | |
tree | a4ece77466921823c69dbfed4933d4659437f8b8 /lib/src | |
parent | 48fe930311724be0c0bc3bcc498d911a05e01134 (diff) | |
parent | 955e71001bd6d360805d2b33a9e6b9d6fd17397f (diff) |
Merge "[HICN-376] Add manual connection/route setting to face manager"
Diffstat (limited to 'lib/src')
-rw-r--r-- | lib/src/util/ip_address.c | 29 |
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 */ |