1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 23:21:22 +03:00

af-list: add helpers mapping AF_INET/AF_INET6 to "ipv4"/"ipv6"

This commit is contained in:
Lennart Poettering 2021-05-10 17:14:13 +02:00
parent f80a206aa4
commit 23118193d2
2 changed files with 15 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);