summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-12-07 19:15:08 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-12-08 10:34:04 +0100
commit8e0bacab6eedbc790bb7ed3218da2e929ebfdab1 (patch)
tree909bb2fded58a7da67e932db7764a30e07361fbf /src/libsystemd/sd-network
parentsd-network: drop unnecessary +1 for buffer size (diff)
downloadsystemd-8e0bacab6eedbc790bb7ed3218da2e929ebfdab1.tar.xz
systemd-8e0bacab6eedbc790bb7ed3218da2e929ebfdab1.zip
sd-network: introduce sd_network_link_get_stat()
Diffstat (limited to 'src/libsystemd/sd-network')
-rw-r--r--src/libsystemd/sd-network/sd-network.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 593d5c9d7c..e1e9a399c1 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -387,6 +387,23 @@ int sd_network_link_get_carrier_bound_by(int ifindex, int **ret) {
return network_link_get_ifindexes(ifindex, "CARRIER_BOUND_BY", ret);
}
+int sd_network_link_get_stat(int ifindex, struct stat *ret) {
+ char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex)];
+ struct stat st;
+
+ assert_return(ifindex > 0, -EINVAL);
+
+ xsprintf(path, "/run/systemd/netif/links/%i", ifindex);
+
+ if (stat(path, &st) < 0)
+ return -errno;
+
+ if (ret)
+ *ret = st;
+
+ return 0;
+}
+
static int MONITOR_TO_FD(sd_network_monitor *m) {
return (int) (unsigned long) m - 1;
}