2007-01-04 16:25:26 +00:00
|
|
|
--- pcap-bpf.c
|
|
|
|
+++ pcap-bpf.c
|
2008-09-05 19:34:28 +00:00
|
|
|
@@ -231,7 +231,7 @@
|
2007-01-04 16:25:26 +00:00
|
|
|
fd = open(device, O_RDWR);
|
|
|
|
if (fd == -1 && errno == EACCES)
|
|
|
|
fd = open(device, O_RDONLY);
|
|
|
|
- } while (fd < 0 && errno == EBUSY);
|
|
|
|
+ } while (fd < 0 && errno == EBUSY && n < 1000);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX better message for all minors used
|
|
|
|
--- pcap-linux.c
|
|
|
|
+++ pcap-linux.c
|
2008-09-05 19:34:28 +00:00
|
|
|
@@ -1144,8 +1144,30 @@
|
2007-01-04 16:25:26 +00:00
|
|
|
if (can_filter_in_kernel) {
|
|
|
|
if ((err = set_kernel_filter(handle, &fcode)) == 0)
|
|
|
|
{
|
|
|
|
+ char buf[1024];
|
|
|
|
+ int oldflags;
|
|
|
|
+ int ret;
|
|
|
|
+ unsigned int received = 0, rec_len = 0;
|
|
|
|
+ socklen_t optlen = sizeof(rec_len);
|
|
|
|
/* Installation succeded - using kernel filter. */
|
|
|
|
handle->md.use_bpf = 1;
|
|
|
|
+
|
|
|
|
+ oldflags = fcntl(handle->fd, F_GETFL, 0);
|
|
|
|
+ oldflags |= O_NONBLOCK;
|
|
|
|
+ fcntl(handle->fd, F_SETFL, oldflags);
|
|
|
|
+ getsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
|
|
|
|
+ (char *)&rec_len, &optlen);
|
|
|
|
+
|
|
|
|
+ /* now read all packets received until now */
|
|
|
|
+ while((ret = read(handle->fd, buf, 1024)) > 0
|
|
|
|
+ && received < rec_len) {
|
|
|
|
+ received += ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(oldflags > 0) {
|
|
|
|
+ oldflags &= ~O_NONBLOCK;
|
|
|
|
+ fcntl(handle->fd, F_SETFL, oldflags);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
else if (err == -1) /* Non-fatal error */
|
|
|
|
{
|