From f9fa3fbf9fdeeb0e453b23525ae3af4ad490ed29 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 5 Aug 2021 13:19:24 +0200 Subject: [PATCH] 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. --- src/libnm-std-aux/nm-std-aux.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 62400ad86b..2747338576 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -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) {