Commit b434d7d4 authored by Thomas Haller's avatar Thomas Haller

shared: add nm_utils_ip_is_site_local()

parent 69ccbb75
......@@ -146,6 +146,27 @@ _nm_utils_ip4_get_default_prefix (guint32 ip)
return 24; /* Class C - 255.255.255.0 */
}
gboolean
nm_utils_ip_is_site_local (int addr_family,
const void *address)
{
in_addr_t addr4;
switch (addr_family) {
case AF_INET:
/* RFC1918 private addresses
* 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 */
addr4 = ntohl (*((const in_addr_t *) address));
return (addr4 & 0xff000000) == 0x0a000000
|| (addr4 & 0xfff00000) == 0xac100000
|| (addr4 & 0xffff0000) == 0xc0a80000;
case AF_INET6:
return IN6_IS_ADDR_SITELOCAL (address);
default:
g_return_val_if_reached (FALSE);
}
}
/*****************************************************************************/
/* _nm_utils_ascii_str_to_int64:
......
......@@ -146,6 +146,9 @@ char **_nm_utils_strv_cleanup (char **strv,
guint32 _nm_utils_ip4_prefix_to_netmask (guint32 prefix);
guint32 _nm_utils_ip4_get_default_prefix (guint32 ip);
gboolean nm_utils_ip_is_site_local (int addr_family,
const void *address);
/*****************************************************************************/
gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment