From: Hans Dedecker Date: Tue, 27 Mar 2018 18:49:40 +0000 (+0200) Subject: ra: handle socket fail creation X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f0469e2ca395a01feffb8e21dbca821bd659f479;p=project%2Fodhcp6c.git ra: handle socket fail creation Signed-off-by: Hans Dedecker --- diff --git a/src/ra.c b/src/ra.c index 299762e..397608a 100644 --- a/src/ra.c +++ b/src/ra.c @@ -301,11 +301,13 @@ bool ra_process(void) socklen_t alen = sizeof(addr); int sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (!connect(sock, (struct sockaddr*)&addr, sizeof(addr)) && - !getsockname(sock, (struct sockaddr*)&addr, &alen)) - lladdr = addr.sin6_addr; + if (sock >= 0) { + if (!connect(sock, (struct sockaddr*)&addr, sizeof(addr)) && + !getsockname(sock, (struct sockaddr*)&addr, &alen)) + lladdr = addr.sin6_addr; - close(sock); + close(sock); + } } while (true) {