From: Yu Watanabe Date: Sat, 12 Oct 2024 07:40:19 +0000 (+0900) Subject: sysctl-util: introduce sysctl_read_ip_property_int() and _uint32() X-Git-Tag: v257-rc1~225^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d56d07fc1ed3ce5f5353b9d73772dcafe7d03bad;p=thirdparty%2Fsystemd.git sysctl-util: introduce sysctl_read_ip_property_int() and _uint32() Currently not used, but will be used later. --- diff --git a/src/basic/sysctl-util.c b/src/basic/sysctl-util.c index 8a73dc6b3ed..2feb4917d73 100644 --- a/src/basic/sysctl-util.c +++ b/src/basic/sysctl-util.c @@ -10,6 +10,7 @@ #include "fileio.h" #include "log.h" #include "macro.h" +#include "parse-util.h" #include "path-util.h" #include "socket-util.h" #include "string-util.h" @@ -193,3 +194,29 @@ int sysctl_read_ip_property(int af, const char *ifname, const char *property, ch return sysctl_read(p, ret); } + +int sysctl_read_ip_property_int(int af, const char *ifname, const char *property, int *ret) { + _cleanup_free_ char *s = NULL; + int r; + + assert(ret); + + r = sysctl_read_ip_property(af, ifname, property, &s); + if (r < 0) + return r; + + return safe_atoi(s, ret); +} + +int sysctl_read_ip_property_uint32(int af, const char *ifname, const char *property, uint32_t *ret) { + _cleanup_free_ char *s = NULL; + int r; + + assert(ret); + + r = sysctl_read_ip_property(af, ifname, property, &s); + if (r < 0) + return r; + + return safe_atou32(s, ret); +} diff --git a/src/basic/sysctl-util.h b/src/basic/sysctl-util.h index 041292f6933..bbfc4ce1ea5 100644 --- a/src/basic/sysctl-util.h +++ b/src/basic/sysctl-util.h @@ -17,6 +17,8 @@ static inline int sysctl_write(const char *property, const char *value) { } int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret); +int sysctl_read_ip_property_int(int af, const char *ifname, const char *property, int *ret); +int sysctl_read_ip_property_uint32(int af, const char *ifname, const char *property, uint32_t *ret); int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value, Hashmap **shadow); static inline int sysctl_write_ip_property_boolean(int af, const char *ifname, const char *property, bool value, Hashmap **shadow) { return sysctl_write_ip_property(af, ifname, property, one_zero(value), shadow);