diff options
author | delphij <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
commit | a3451bb93bbf335a8f6b5feb9b80b256b0e304fe (patch) | |
tree | 158e6045ed438c41ac8de6cb27ac3c73cdc6643a /contrib/libpcap/pcap-usb-linux.c | |
parent | a17ebbd192e814c313397aefc289ab32a0ece772 (diff) | |
parent | e11c3f548e0bd184480800016b8567824dc35516 (diff) | |
download | FreeBSD-src-a3451bb93bbf335a8f6b5feb9b80b256b0e304fe.zip FreeBSD-src-a3451bb93bbf335a8f6b5feb9b80b256b0e304fe.tar.gz |
Merge from vendor branch: update libpcap to 1.2.1.
MFC after: 2 weeks
Diffstat (limited to 'contrib/libpcap/pcap-usb-linux.c')
-rw-r--r-- | contrib/libpcap/pcap-usb-linux.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/contrib/libpcap/pcap-usb-linux.c b/contrib/libpcap/pcap-usb-linux.c index fea527f..f1b430c 100644 --- a/contrib/libpcap/pcap-usb-linux.c +++ b/contrib/libpcap/pcap-usb-linux.c @@ -61,8 +61,15 @@ static const char rcsid[] _U_ = #include <sys/ioctl.h> #include <sys/mman.h> #ifdef HAVE_LINUX_USBDEVICE_FS_H +/* + * We might need <linux/compiler.h> to define __user for + * <linux/usbdevice_fs.h>. + */ +#ifdef HAVE_LINUX_COMPILER_H +#include <linux/compiler.h> +#endif /* HAVE_LINUX_COMPILER_H */ #include <linux/usbdevice_fs.h> -#endif +#endif /* HAVE_LINUX_USBDEVICE_FS_H */ #define USB_IFACE "usbmon" #define USB_TEXT_DIR_OLD "/sys/kernel/debug/usbmon" @@ -122,7 +129,6 @@ static int usb_read_linux(pcap_t *, int , pcap_handler , u_char *); static int usb_read_linux_bin(pcap_t *, int , pcap_handler , u_char *); static int usb_read_linux_mmap(pcap_t *, int , pcap_handler , u_char *); static int usb_inject_linux(pcap_t *, const void *, size_t); -static int usb_setfilter_linux(pcap_t *, struct bpf_program *); static int usb_setdirection_linux(pcap_t *, pcap_direction_t); static void usb_cleanup_linux_mmap(pcap_t *); @@ -301,7 +307,7 @@ usb_activate(pcap_t* handle) handle->linktype = DLT_USB_LINUX; handle->inject_op = usb_inject_linux; - handle->setfilter_op = usb_setfilter_linux; + handle->setfilter_op = install_bpf_program; /* no kernel filtering */ handle->setdirection_op = usb_setdirection_linux; handle->set_datalink_op = NULL; /* can't change data link type */ handle->getnonblock_op = pcap_getnonblock_fd; @@ -597,12 +603,17 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u got: uhdr->data_len = data_len; - handle->md.packets_read++; if (pkth.caplen > handle->snapshot) pkth.caplen = handle->snapshot; - callback(user, &pkth, handle->buffer); - return 1; + if (handle->fcode.bf_insns == NULL || + bpf_filter(handle->fcode.bf_insns, handle->buffer, + pkth.len, pkth.caplen)) { + handle->md.packets_read++; + callback(user, &pkth, handle->buffer); + return 1; + } + return 0; /* didn't pass filter */ } static int @@ -689,12 +700,6 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats) } static int -usb_setfilter_linux(pcap_t *p, struct bpf_program *fp) -{ - return 0; -} - -static int usb_setdirection_linux(pcap_t *p, pcap_direction_t d) { p->direction = d; @@ -767,9 +772,15 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha pkth.ts.tv_sec = info.hdr->ts_sec; pkth.ts.tv_usec = info.hdr->ts_usec; - handle->md.packets_read++; - callback(user, &pkth, handle->buffer); - return 1; + if (handle->fcode.bf_insns == NULL || + bpf_filter(handle->fcode.bf_insns, handle->buffer, + pkth.len, pkth.caplen)) { + handle->md.packets_read++; + callback(user, &pkth, handle->buffer); + return 1; + } + + return 0; /* didn't pass filter */ } /* @@ -841,9 +852,13 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch pkth.ts.tv_sec = hdr->ts_sec; pkth.ts.tv_usec = hdr->ts_usec; - handle->md.packets_read++; - callback(user, &pkth, (u_char*) hdr); - packets++; + if (handle->fcode.bf_insns == NULL || + bpf_filter(handle->fcode.bf_insns, (u_char*) hdr, + pkth.len, pkth.caplen)) { + handle->md.packets_read++; + callback(user, &pkth, (u_char*) hdr); + packets++; + } } /* with max_packets <= 0 we stop afer the first chunk*/ |