libnm: add internal API nm_utils_inet*_ntop_dup()

In quite some cases we need the string representation on the heap.

While nm_utils_inet*_ntop() accepts NULL as output buffer to fallback
to a static buffer, such usage of a static buffer is discouraged.
So, we actually should always allocate a temporaray buffer on the
stack. But that is cumbersome to write.

Add simple wrappers that makes calling this more convenient.
This commit is contained in:
Thomas Haller 2018-11-27 10:24:03 +01:00
parent 1e4c0dd680
commit 898f7a5665

View file

@ -496,6 +496,30 @@ NMSettingBluetooth *_nm_connection_get_setting_bluetooth_for_nap (NMConnection *
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, const struct in6_addr *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);
/*****************************************************************************/