diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-05-10 17:14:13 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-05-11 15:37:31 +0200 |
commit | 23118193d23438f9fdb4dd31c9acc5d6bfcc393c (patch) | |
tree | 1088c7c9804c186cc2cc1cd8004ec2e9758caa4b /src/basic/af-list.c | |
parent | f80a206aa497c1a1ce2a7bfc024ea2080f357aeb (diff) | |
download | systemd-23118193d23438f9fdb4dd31c9acc5d6bfcc393c.tar.gz |
af-list: add helpers mapping AF_INET/AF_INET6 to "ipv4"/"ipv6"
Diffstat (limited to 'src/basic/af-list.c')
-rw-r--r-- | src/basic/af-list.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/basic/af-list.c b/src/basic/af-list.c index 7e819d6d11..a9ab891e20 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; +} |