mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 04:58:01 +02:00
libnm-core: use utility function in NMIPRoute for getting size of addresses per family
This commit is contained in:
parent
0ba4322eec
commit
862be319a8
1 changed files with 16 additions and 8 deletions
|
|
@ -63,6 +63,19 @@ const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[] = {
|
||||||
{ NULL, FALSE, FALSE }
|
{ NULL, FALSE, FALSE }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
_addr_size (int family)
|
||||||
|
{
|
||||||
|
switch (family) {
|
||||||
|
case AF_INET:
|
||||||
|
return sizeof (in_addr_t);
|
||||||
|
case AF_INET6:
|
||||||
|
return sizeof (struct in6_addr);
|
||||||
|
default:
|
||||||
|
g_return_val_if_reached (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
canonicalize_ip (int family, const char *ip, gboolean null_any)
|
canonicalize_ip (int family, const char *ip, gboolean null_any)
|
||||||
{
|
{
|
||||||
|
|
@ -77,9 +90,7 @@ canonicalize_ip (int family, const char *ip, gboolean null_any)
|
||||||
g_return_val_if_fail (ret == 1, NULL);
|
g_return_val_if_fail (ret == 1, NULL);
|
||||||
|
|
||||||
if (null_any) {
|
if (null_any) {
|
||||||
int addrlen = (family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
|
if (!memcmp (addr_bytes, &in6addr_any, _addr_size (family)))
|
||||||
|
|
||||||
if (!memcmp (addr_bytes, &in6addr_any, addrlen))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,9 +112,7 @@ canonicalize_ip_binary (int family, gconstpointer ip, gboolean null_any)
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
}
|
}
|
||||||
if (null_any) {
|
if (null_any) {
|
||||||
int addrlen = (family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
|
if (!memcmp (ip, &in6addr_any, _addr_size (family)))
|
||||||
|
|
||||||
if (!memcmp (ip, &in6addr_any, addrlen))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return g_strdup (inet_ntop (family, ip, string, sizeof (string)));
|
return g_strdup (inet_ntop (family, ip, string, sizeof (string)));
|
||||||
|
|
@ -956,8 +965,7 @@ nm_ip_route_get_next_hop_binary (NMIPRoute *route,
|
||||||
inet_pton (route->family, route->next_hop, next_hop);
|
inet_pton (route->family, route->next_hop, next_hop);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
memset (next_hop, 0,
|
memset (next_hop, 0, _addr_size (route->family));
|
||||||
route->family == AF_INET ? sizeof (struct in_addr) : sizeof (struct in6_addr));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue