Basic error checking when initializing ra
authorHans Dedecker <dedeckeh@gmail.com>
Sun, 1 Dec 2013 17:55:11 +0000 (18:55 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Sun, 1 Dec 2013 17:55:11 +0000 (18:55 +0100)
src/ra.c

index c8ccb888f8856172ff58f280625b5005b61ab356..64cc8d85ac7ab961382ac80f7aaf6c4557fa4030 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -59,13 +59,23 @@ int ra_init(const char *ifname, const struct in6_addr *ifid)
 {
        const pid_t ourpid = getpid();
        sock = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+       if (sock < 0)
+               return -1;
+
        if_index = if_nametoindex(ifname);
+       if (!if_index)
+               return -1;
+
        strncpy(if_name, ifname, sizeof(if_name) - 1);
        lladdr = *ifid;
 
        rtnl = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
+       if (rtnl < 0)
+               return -1;
+
        struct sockaddr_nl rtnl_kernel = { .nl_family = AF_NETLINK };
-       connect(rtnl, (const struct sockaddr*)&rtnl_kernel, sizeof(rtnl_kernel));
+       if (connect(rtnl, (const struct sockaddr*)&rtnl_kernel, sizeof(rtnl_kernel)) < 0)
+               return -1;
 
        int val = RTNLGRP_LINK;
        setsockopt(rtnl, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &val, sizeof(val));