ra: handle socket fail creation
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 27 Mar 2018 18:49:40 +0000 (20:49 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Tue, 27 Mar 2018 18:59:01 +0000 (20:59 +0200)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/ra.c

index 299762e57bcb0247fe88bf1baa6f755c84f37962..397608a246e0a26fa466afb1b3856d1ea10e6a13 100644 (file)
--- 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) {