mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-01 10:18:00 +02:00
core: add nm_utils_ip4_address_same_prefix() function
This commit is contained in:
parent
846b02880d
commit
944006d485
1 changed files with 18 additions and 10 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue