2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
15 #include <sys/socket.h>
20 # define POLLRDNORM 0x0040
23 # define POLLWRNORM 0x0100
26 # define POLLRDHUP 0x2000
28 #define POLL_NEXT_PKT 0
29 #define POLL_MOVE_OUT 1
31 static inline void prepare_polling(int sock
, struct pollfd
*pfd
)
33 memset(pfd
, 0, sizeof(*pfd
));
36 pfd
->events
= POLLIN
| POLLRDNORM
| POLLERR
;
39 static inline int poll_error_maybe_die(int sock
, struct pollfd
*pfd
)
41 if ((pfd
->revents
& (POLLHUP
| POLLRDHUP
| POLLERR
| POLLNVAL
)) == 0)
43 if (pfd
->revents
& (POLLHUP
| POLLRDHUP
))
44 panic("Hangup on socket occured!\n");
45 if (pfd
->revents
& POLLERR
) {
48 /* recv is more specififc on the error */
49 if (recv(sock
, &tmp
, sizeof(tmp
), MSG_PEEK
) >= 0)
51 if (errno
== ENETDOWN
)
52 panic("Interface went down!\n");
55 if (pfd
->revents
& POLLNVAL
) {
56 whine("Invalid polling request on socket!\n");