From f0469e2ca395a01feffb8e21dbca821bd659f479 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Tue, 27 Mar 2018 20:49:40 +0200 Subject: [PATCH] ra: handle socket fail creation Signed-off-by: Hans Dedecker --- src/ra.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) { -- 2.25.1