From: Lennart Poettering Date: Mon, 10 May 2021 15:14:13 +0000 (+0200) Subject: af-list: add helpers mapping AF_INET/AF_INET6 to "ipv4"/"ipv6" X-Git-Tag: v249-rc1~236^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=23118193d23438f9fdb4dd31c9acc5d6bfcc393c;p=thirdparty%2Fsystemd.git af-list: add helpers mapping AF_INET/AF_INET6 to "ipv4"/"ipv6" --- diff --git a/src/basic/af-list.c b/src/basic/af-list.c index 7e819d6d11e..a9ab891e20d 100644 --- a/src/basic/af-list.c +++ b/src/basic/af-list.c @@ -38,3 +38,15 @@ int af_from_name(const char *name) { int af_max(void) { return ELEMENTSOF(af_names); } + +const char *af_to_ipv4_ipv6(int id) { + /* Pretty often we want to map the address family to the typically used protocol name for IPv4 + + * IPv6. Let's add special helpers for that. */ + return id == AF_INET ? "ipv4" : + id == AF_INET6 ? "ipv6" : NULL; +} + +int af_from_ipv4_ipv6(const char *af) { + return streq_ptr(af, "ipv4") ? AF_INET : + streq_ptr(af, "ipv6") ? AF_INET6 : AF_UNSPEC; +} diff --git a/src/basic/af-list.h b/src/basic/af-list.h index 688ac63df75..9592b9ed3c9 100644 --- a/src/basic/af-list.h +++ b/src/basic/af-list.h @@ -22,4 +22,7 @@ static inline const char* af_to_name_short(int id) { return f + 3; } +const char* af_to_ipv4_ipv6(int id); +int af_from_ipv4_ipv6(const char *af); + int af_max(void);