glib-aux: add _nm_utils_ip4_netmask_to_prefix() helper
nm_utils_ip4_netmask_to_prefix() and nm_utils_ip4_prefix_to_netmask() are public API in libnm. We thus already have an internal implementation _nm_utils_ip4_prefix_to_netmask(), for non-libnm users. Internally, we should never use the libnm variant. For consistency and so that we have the helper available in libnm-glib-aux, add _nm_utils_ip4_netmask_to_prefix().
This commit is contained in:
@@ -1571,12 +1571,7 @@ nm_utils_ip4_routes_from_variant(GVariant *value)
|
||||
guint32
|
||||
nm_utils_ip4_netmask_to_prefix(guint32 netmask)
|
||||
{
|
||||
G_STATIC_ASSERT_EXPR(__SIZEOF_INT__ == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(int) == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(guint) == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(netmask) == 4);
|
||||
|
||||
return ((netmask != 0u) ? (guint32) (32 - __builtin_ctz(ntohl(netmask))) : 0u);
|
||||
return _nm_utils_ip4_netmask_to_prefix(netmask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -389,6 +389,17 @@ gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint32
|
||||
_nm_utils_ip4_netmask_to_prefix(in_addr_t subnetmask)
|
||||
{
|
||||
G_STATIC_ASSERT_EXPR(__SIZEOF_INT__ == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(int) == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(guint) == 4);
|
||||
G_STATIC_ASSERT_EXPR(sizeof(subnetmask) == 4);
|
||||
|
||||
return ((subnetmask != 0u) ? (guint32) (32 - __builtin_ctz(ntohl(subnetmask))) : 0u);
|
||||
}
|
||||
|
||||
/**
|
||||
* _nm_utils_ip4_prefix_to_netmask:
|
||||
* @prefix: a CIDR prefix
|
||||
|
Reference in New Issue
Block a user