mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-21 18:24:49 +00:00
shared: move nm_utils_inet* helpers from libnm-core to shared
This commit is contained in:
parent
06d6de95d6
commit
c0bd6752b9
|
@ -538,34 +538,6 @@ gboolean _nm_setting_bond_option_supported (const char *option, NMBondMode mode)
|
|||
|
||||
NMSettingBluetooth *_nm_connection_get_setting_bluetooth_for_nap (NMConnection *connection);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst);
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet4_ntop_dup (in_addr_t addr)
|
||||
{
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
return g_strdup (nm_utils_inet4_ntop (addr, buf));
|
||||
}
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet6_ntop_dup (const struct in6_addr *addr)
|
||||
{
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
return g_strdup (nm_utils_inet6_ntop (addr, buf));
|
||||
}
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet_ntop_dup (int addr_family, gconstpointer addr)
|
||||
{
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
return g_strdup (nm_utils_inet_ntop (addr_family, addr, buf));
|
||||
}
|
||||
|
||||
gboolean _nm_utils_inet6_is_token (const struct in6_addr *in6addr);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -4819,23 +4819,6 @@ nm_utils_is_uuid (const char *str)
|
|||
|
||||
static char _nm_utils_inet_ntop_buffer[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
const char *
|
||||
nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
nm_assert_addr_family (addr_family);
|
||||
nm_assert (addr);
|
||||
nm_assert (dst);
|
||||
|
||||
s = inet_ntop (addr_family,
|
||||
addr,
|
||||
dst,
|
||||
addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN);
|
||||
nm_assert (s);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_inet4_ntop: (skip)
|
||||
* @inaddr: the address that should be converted to string.
|
||||
|
@ -4861,8 +4844,7 @@ nm_utils_inet4_ntop (in_addr_t inaddr, char *dst)
|
|||
*
|
||||
* However, still support it to be lenient against mistakes and because
|
||||
* this is public API of libnm. */
|
||||
return inet_ntop (AF_INET, &inaddr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET_ADDRSTRLEN);
|
||||
return _nm_utils_inet4_ntop (inaddr, dst ?: _nm_utils_inet_ntop_buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4892,8 +4874,7 @@ nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
|
|||
* However, still support it to be lenient against mistakes and because
|
||||
* this is public API of libnm. */
|
||||
g_return_val_if_fail (in6addr, NULL);
|
||||
return inet_ntop (AF_INET6, in6addr, dst ?: _nm_utils_inet_ntop_buffer,
|
||||
INET6_ADDRSTRLEN);
|
||||
return _nm_utils_inet6_ntop (in6addr, dst ?: _nm_utils_inet_ntop_buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -158,6 +158,64 @@ nm_ip4_addr_is_localhost (in_addr_t addr4)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN
|
||||
|
||||
static inline const char *
|
||||
nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
const char *inet_ntop (int af,
|
||||
const void *src,
|
||||
char *dst,
|
||||
socklen_t size);
|
||||
|
||||
nm_assert_addr_family (addr_family);
|
||||
nm_assert (addr);
|
||||
nm_assert (dst);
|
||||
|
||||
s = inet_ntop (addr_family,
|
||||
addr,
|
||||
dst,
|
||||
addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN);
|
||||
nm_assert (s);
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
_nm_utils_inet4_ntop (in_addr_t addr, char *dst)
|
||||
{
|
||||
return nm_utils_inet_ntop (AF_INET, &addr, dst);
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
_nm_utils_inet6_ntop (const struct in6_addr *addr, char *dst)
|
||||
{
|
||||
return nm_utils_inet_ntop (AF_INET6, addr, dst);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet_ntop_dup (int addr_family, gconstpointer addr)
|
||||
{
|
||||
char buf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
return g_strdup (nm_utils_inet_ntop (addr_family, addr, buf));
|
||||
}
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet4_ntop_dup (in_addr_t addr)
|
||||
{
|
||||
return nm_utils_inet_ntop_dup (AF_INET, &addr);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
nm_utils_inet6_ntop_dup (const struct in6_addr *addr)
|
||||
{
|
||||
return nm_utils_inet_ntop_dup (AF_INET6, addr);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_CMP_RETURN(c) \
|
||||
G_STMT_START { \
|
||||
const int _cc = (c); \
|
||||
|
|
Loading…
Reference in a new issue