summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-rtnl/sd-rtnl.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-02-01 22:12:33 +0100
committerTom Gundersen <teg@jklm.no>2015-02-02 11:57:52 +0100
commita9944163fe5600bce85898dae78cd68442a6ff7c (patch)
treee24bdde9c5d43dc74f7f7de4b41bad5a1f648b16 /src/libsystemd/sd-rtnl/sd-rtnl.c
parente56cdb7ae2657d62c9a8b6d3427382b209dff8e7 (diff)
sd-rtnl: introduce sd_rtnl_new_from_netlink
Diffstat (limited to 'src/libsystemd/sd-rtnl/sd-rtnl.c')
-rw-r--r--src/libsystemd/sd-rtnl/sd-rtnl.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index 7f1ec308a8..767c583735 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -67,6 +67,31 @@ static int sd_rtnl_new(sd_rtnl **ret) {
return 0;
}
+int sd_rtnl_new_from_netlink(sd_rtnl **ret, int fd) {
+ _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+ socklen_t addrlen;
+ int r;
+
+ assert_return(ret, -EINVAL);
+
+ r = sd_rtnl_new(ret);
+ if (r < 0)
+ return r;
+
+ addrlen = sizeof(rtnl->sockaddr);
+
+ r = getsockname(fd, &rtnl->sockaddr.sa, &addrlen);
+ if (r < 0)
+ return -errno;
+
+ rtnl->fd = fd;
+
+ *ret = rtnl;
+ rtnl = NULL;
+
+ return 0;
+}
+
static bool rtnl_pid_changed(sd_rtnl *rtnl) {
assert(rtnl);
@@ -126,7 +151,7 @@ static int rtnl_open_fd_ap(sd_rtnl **ret, int fd, unsigned n_groups, va_list ap)
r = getsockname(fd, &rtnl->sockaddr.sa, &addrlen);
if (r < 0)
- return r;
+ return -errno;
rtnl->fd = fd;