diff options
| author | Thomas Haller <thaller@redhat.com> | 2017-07-26 10:58:39 +0200 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2017-07-31 15:13:31 +0200 |
| commit | 54f8c2ac22b0df9d7316744808163e95f573dfbd (patch) | |
| tree | 33578b8be9f4142d3e2232283d641765b5ac291f /src/nm-core-utils.h | |
| parent | 8d03caf599e6f6737a333aeccda0ee22dc66beeb (diff) | |
| download | NetworkManager-54f8c2ac22b0df9d7316744808163e95f573dfbd.tar.gz | |
core: add nm_utils_ip6_address_same_prefix_cmp() helper
Useful for sorting/comparing.
Diffstat (limited to 'src/nm-core-utils.h')
| -rw-r--r-- | src/nm-core-utils.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 20df8d7e96..99d9e9c486 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -122,7 +122,26 @@ 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); -gboolean nm_utils_ip6_address_same_prefix (const struct in6_addr *addr_a, const struct in6_addr *addr_b, guint8 plen); +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_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_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 double nm_utils_exp10 (gint16 e); |
