diff options
author | Thomas Haller <thaller@redhat.com> | 2017-09-11 21:34:35 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-09-13 08:17:31 +0200 |
commit | 944006d485c861d1f49ac6a8d9ae2027d7bf8bad (patch) | |
tree | 0ea39f25a8f8648f92595ca66ff501278ecc0acf | |
parent | 846b02880d05376e1f6e16721fcbd79095a76570 (diff) | |
download | NetworkManager-944006d485c861d1f49ac6a8d9ae2027d7bf8bad.tar.gz |
core: add nm_utils_ip4_address_same_prefix() function
-rw-r--r-- | src/nm-core-utils.h | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index aca69fce6a..9956d96ac3 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -116,27 +116,35 @@ gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len); gconstpointer nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen); in_addr_t nm_utils_ip4_address_clear_host_address (in_addr_t addr, guint8 plen); const struct in6_addr *nm_utils_ip6_address_clear_host_address (struct in6_addr *dst, const struct in6_addr *src, guint8 plen); + +static inline int +nm_utils_ip4_address_same_prefix_cmp (in_addr_t addr_a, in_addr_t addr_b, guint8 plen) +{ + NM_CMP_DIRECT (htonl (nm_utils_ip4_address_clear_host_address (addr_a, plen)), + htonl (nm_utils_ip4_address_clear_host_address (addr_b, plen))); + return 0; +} + int nm_utils_ip6_address_same_prefix_cmp (const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen); static inline gboolean +nm_utils_ip4_address_same_prefix (in_addr_t addr_a, in_addr_t addr_b, guint8 plen) +{ + return nm_utils_ip4_address_same_prefix_cmp (addr_a, addr_b, plen) == 0; +} + +static inline gboolean nm_utils_ip6_address_same_prefix (const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen) { return nm_utils_ip6_address_same_prefix_cmp (addr_a, addr_b, plen) == 0; } +#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN (nm_utils_ip4_address_same_prefix_cmp ((a), (b), (plen))) + #define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ NM_CMP_RETURN (nm_utils_ip6_address_same_prefix_cmp ((a), (b), (plen))) -#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ - G_STMT_START { \ - const guint8 _plen = (plen); \ - const in_addr_t _aa = (a); \ - const in_addr_t _ab = (b); \ - \ - NM_CMP_DIRECT (htonl (nm_utils_ip4_address_clear_host_address (_aa, _plen)), \ - htonl (nm_utils_ip4_address_clear_host_address (_ab, _plen))); \ - } G_STMT_END - static inline guint NM_HASH_COMBINE_IN6ADDR (guint h, const struct in6_addr *addr) { |