libnm: discourage static buffer in nm_utils_inet*_ntop() API

nm_utils_inet[46]_ntop() are public API of libnm, so we cannot change
it. However, discourage the use of the static buffer.
This commit is contained in:
Thomas Haller
2018-11-26 17:14:19 +01:00
parent a51c09dc12
commit b9ebaf3a2b

View File

@@ -4500,10 +4500,11 @@ nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
nm_assert_addr_family (addr_family); nm_assert_addr_family (addr_family);
nm_assert (addr); nm_assert (addr);
nm_assert (dst);
s = inet_ntop (addr_family, s = inet_ntop (addr_family,
addr, addr,
dst ?: _nm_utils_inet_ntop_buffer, dst,
addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN); addr_family == AF_INET6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN);
nm_assert (s); nm_assert (s);
return s; return s;
@@ -4529,6 +4530,11 @@ nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst)
const char * const char *
nm_utils_inet4_ntop (in_addr_t inaddr, char *dst) nm_utils_inet4_ntop (in_addr_t inaddr, char *dst)
{ {
/* relying on the static buffer (by leaving @dst as %NULL) is discouraged.
* Don't do that!
*
* 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, return inet_ntop (AF_INET, &inaddr, dst ?: _nm_utils_inet_ntop_buffer,
INET_ADDRSTRLEN); INET_ADDRSTRLEN);
} }
@@ -4554,6 +4560,11 @@ nm_utils_inet4_ntop (in_addr_t inaddr, char *dst)
const char * const char *
nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst) nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst)
{ {
/* relying on the static buffer (by leaving @dst as %NULL) is discouraged.
* Don't do that!
*
* However, still support it to be lenient against mistakes and because
* this is public API of libnm. */
g_return_val_if_fail (in6addr, NULL); g_return_val_if_fail (in6addr, NULL);
return inet_ntop (AF_INET6, in6addr, dst ?: _nm_utils_inet_ntop_buffer, return inet_ntop (AF_INET6, in6addr, dst ?: _nm_utils_inet_ntop_buffer,
INET6_ADDRSTRLEN); INET6_ADDRSTRLEN);