From 898f7a56655de1edf0bcb8036d3a8ca71b19c536 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 27 Nov 2018 10:24:03 +0100 Subject: [PATCH] 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. --- libnm-core/nm-core-internal.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 6c85cc6be4..ff2444673f 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -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); /*****************************************************************************/