From: Hans Dedecker Date: Sun, 1 Dec 2013 17:55:11 +0000 (+0100) Subject: Basic error checking when initializing ra X-Git-Tag: debian/1.1+git20160131-1~107^2~10 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=1234ab04386fd63eafb19ecf245b730d6461e869;p=odhcp6c.git Basic error checking when initializing ra --- diff --git a/src/ra.c b/src/ra.c index c8ccb88..64cc8d8 100644 --- 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));