chiark / gitweb /
include <poll.h> instead of <sys/poll.h>
[elogind.git] / src / libsystemd / sd-network / sd-network.c
index 3a3f53576f365cf68f264103bae7baef22b8459e..c4713feb5d97f3ac47df14baa5e7136e0d7e9e61 100644 (file)
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/inotify.h>
-#include <sys/poll.h>
+#include <poll.h>
 #include <net/if.h>
 
 #include "util.h"
@@ -120,6 +120,30 @@ _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
         return 0;
 }
 
+_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
+        assert_return(filename, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (isempty(s))
+                return -ENODATA;
+
+        *filename = s;
+        s = NULL;
+
+        return 0;
+}
+
 _public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
         _cleanup_free_ char *s = NULL, *p = NULL;
         int r;
@@ -168,6 +192,32 @@ _public_ int sd_network_link_get_llmnr(int ifindex, char **llmnr) {
         return 0;
 }
 
+_public_ int sd_network_link_get_lldp(int ifindex, char **lldp) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        size_t size;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
+        assert_return(lldp, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/lldp/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = read_full_file(p, &s, &size);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (size <= 0)
+                return -ENODATA;
+
+        *lldp = s;
+        s = NULL;
+
+        return 0;
+}
+
+
 static int network_get_link_strv(const char *key, int ifindex, char ***ret) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         _cleanup_strv_free_ char **a = NULL;