libpcap/libpcap-1.5.2-filter-fix.patch

54 lines
1.8 KiB
Diff
Raw Normal View History

---
pcap-bpf.c | 2 +-
pcap-linux.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
Index: libpcap-1.5.2/pcap-bpf.c
===================================================================
--- libpcap-1.5.2.orig/pcap-bpf.c 2013-11-07 23:23:22.000000000 +0000
+++ libpcap-1.5.2/pcap-bpf.c 2013-12-14 11:28:40.000000000 +0000
@@ -494,7 +494,7 @@ bpf_open(pcap_t *p)
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
Index: libpcap-1.5.2/pcap-linux.c
===================================================================
--- libpcap-1.5.2.orig/pcap-linux.c 2013-12-03 15:11:24.000000000 +0000
+++ libpcap-1.5.2/pcap-linux.c 2013-12-14 11:30:29.000000000 +0000
@@ -2475,8 +2475,30 @@ pcap_setfilter_linux_common(pcap_t *hand
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. */
handlep->filtering_in_kernel = 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 */
{