2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
15 #include <sys/socket.h>
20 # define POLLRDNORM 0x0040
23 # define POLLWRNORM 0x0100
26 # define POLLRDHUP 0x2000
29 #define POLL_NEXT_PKT 0
30 #define POLL_MOVE_OUT 1
32 static inline void prepare_polling(int sock
, struct pollfd
*pfd
)
34 memset(pfd
, 0, sizeof(*pfd
));
38 pfd
->events
= POLLIN
| POLLRDNORM
| POLLERR
;
41 static inline int poll_error_maybe_die(int sock
, struct pollfd
*pfd
)
43 if ((pfd
->revents
& (POLLHUP
| POLLRDHUP
| POLLERR
| POLLNVAL
)) == 0)
46 if (pfd
->revents
& (POLLHUP
| POLLRDHUP
))
47 error_and_die(EXIT_FAILURE
, "Hangup on socket occured!\n");
49 if (pfd
->revents
& POLLERR
) {
53 /* recv is more specififc on the error */
54 if (recv(sock
, &tmp
, sizeof(tmp
), MSG_PEEK
) >= 0)
57 if (errno
== ENETDOWN
)
58 error_and_die(EXIT_FAILURE
, "Interface went down!\n");
62 if (pfd
->revents
& POLLNVAL
) {
63 whine("Invalid polling request on socket!\n");