std-aux: add nm_utils_addr_family_to_str() helper

Like nm_utils_addr_family_to_char(), but gives a different treatment to
AF_UNSPEC to return "" instead of 'X'. As such, it also needs to
return a string and not a char.
This commit is contained in:
Thomas Haller 2021-08-05 13:19:24 +02:00
parent 7459a8c67a
commit f9fa3fbf9f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1134,6 +1134,21 @@ nm_ptr_to_uintptr(const void *p)
#define NM_AF_INET_SIZE 4 /* sizeof (in_addr_t) */
#define NM_AF_INET6_SIZE 16 /* sizeof (stuct in6_addr) */
static inline const char *
nm_utils_addr_family_to_str(int addr_family)
{
switch (addr_family) {
case NM_AF_UNSPEC:
return "";
case NM_AF_INET:
return "4";
case NM_AF_INET6:
return "6";
}
nm_assert_not_reached();
return "?";
}
static inline char
nm_utils_addr_family_to_char(int addr_family)
{