{
#ifdef SOCK_CLOEXEC
- return socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC, 0);
+ return socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
#else
int s, flags;
close(s);
return -1;
}
+ if ((flags = fcntl(s, F_GETFL, 0)) == -1 ||
+ fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+ {
+ close(s);
+ return -1;
+ }
return s;
#endif
}
int flags;
#endif
#ifdef _PATH_BPF
- fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC);
+ fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC | O_NONBLOCK);
#else
char device[32];
int n = 0;
do {
snprintf(device, sizeof(device), "/dev/bpf%d", n++);
- fd = open(device, O_RDWR | O_CLOEXEC);
+ fd = open(device, O_RDWR | O_CLOEXEC | O_NONBLOCK);
} while (fd == -1 && errno == EBUSY);
#endif
if (ioctl(fd, BIOCSETF, &pf) == -1)
goto eexit;
+#ifdef __OpenBSD__
+ /* For some reason OpenBSD fails to open the fd as non blocking */
+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
+ goto eexit;
+#endif
+
return fd;
eexit:
#endif
#ifdef SOCK_CLOEXEC
- if ((s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC,
+ if ((s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
htons(protocol))) == -1)
return -1;
#else
close(s);
return -1;
}
+ if ((flags = fcntl(s, F_GETFL, 0)) == -1 ||
+ fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+ {
+ close(s);
+ return -1;
+ }
#endif
/* Install the DHCP filter */
memset(&pf, 0, sizeof(pf));