diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-09 11:17:15 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-01-28 11:17:41 +0100 |
commit | c0bd6752b977603331e5f8ea056f0f15d436d622 (patch) | |
tree | 2f0b8d404b1293128f0e12b72e849a8e59af10f2 | |
parent | 06d6de95d6613d9d9d176a999d870922102ce8ce (diff) | |
download | NetworkManager-c0bd6752b977603331e5f8ea056f0f15d436d622.tar.gz |
shared: move nm_utils_inet* helpers from libnm-core to shared
-rw-r--r-- | libnm-core/nm-core-internal.h | 28 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 23 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 58 |
3 files changed, 60 insertions, 49 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index bd65432eee..2bc7a53aae 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -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); /*****************************************************************************/ diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index b6d085d961..a86fde1877 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -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); } /** diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index e7934cf163..abe263c6bd 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -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); \ |