This is in linux select(2) man page:
-------------
Under Linux, select() may report a socket file descriptor as "ready for
reading", while nevertheless a subsequent read blocks. This could for
example happen when data has arrived but upon examination has wrong
checksum and is discarded. There may be other circumstances in which a
file descriptor is spuriously reported as ready. Thus it may be safer
to use O_NONBLOCK on sockets that should not block.
-------------
Fix it by using MSG_DONTWAIT in recvfrom() (sets non-blocking mode).
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/packet.c b/src/packet.c
index 3432081..2770ee8 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -169,7 +169,8 @@ void packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
socklen_t fromlen = sizeof(struct sockaddr_ll);
ssize_t len;
- len = recvfrom(fd, pkt->pkt_buf, pkt->pkt_bufsize, MSG_TRUNC,
+ len = recvfrom(fd, pkt->pkt_buf, pkt->pkt_bufsize,
+ MSG_TRUNC | MSG_DONTWAIT,
(struct sockaddr *) &from, &fromlen);
if (len > 0) {
pkt->pkt_len = len;
--
1.7.8.4