diff --git a/libpcap/config.h.in b/libpcap/config.h.in index ce2933aa3..0259ca29e 100644 --- a/libpcap/config.h.in +++ b/libpcap/config.h.in @@ -55,6 +55,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LIMITS_H +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_COMPILER_H + /* if tp_vlan_tci exists */ #undef HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI diff --git a/libpcap/configure b/libpcap/configure index 05d76acc5..c34c3bdd0 100755 --- a/libpcap/configure +++ b/libpcap/configure @@ -7044,7 +7044,41 @@ _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: Device for USB sniffing is /dev/$ac_usb_dev_name" >&5 $as_echo "$as_me: Device for USB sniffing is /dev/$ac_usb_dev_name" >&6;} - for ac_header in linux/usbdevice_fs.h + # + # Do we have a version of available? + # If so, we might need it for . + # + for ac_header in linux/compiler.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "linux/compiler.h" "ac_cv_header_linux_compiler_h" "$ac_includes_default" +if test "x$ac_cv_header_linux_compiler_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LINUX_COMPILER_H 1 +_ACEOF + +fi + +done + + if test "$ac_cv_header_linux_compiler_h" = yes; then + # + # Yes - include it when testing for . + # + for ac_header in linux/usbdevice_fs.h +do : + ac_fn_c_check_header_compile "$LINENO" "linux/usbdevice_fs.h" "ac_cv_header_linux_usbdevice_fs_h" "#include +" +if test "x$ac_cv_header_linux_usbdevice_fs_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LINUX_USBDEVICE_FS_H 1 +_ACEOF + +fi + +done + + else + for ac_header in linux/usbdevice_fs.h do : ac_fn_c_check_header_mongrel "$LINENO" "linux/usbdevice_fs.h" "ac_cv_header_linux_usbdevice_fs_h" "$ac_includes_default" if test "x$ac_cv_header_linux_usbdevice_fs_h" = x""yes; then : @@ -7056,6 +7090,7 @@ fi done + fi if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then # # OK, does it define bRequestType? Older versions of the kernel @@ -7075,6 +7110,9 @@ $ac_includes_default #ifdef HAVE_SYS_BITYPES_H #include #endif +#ifdef HAVE_LINUX_COMPILER_H +#include +#endif # include int main () diff --git a/libpcap/configure.in b/libpcap/configure.in index 84fc31f14..e56462b08 100644 --- a/libpcap/configure.in +++ b/libpcap/configure.in @@ -1314,7 +1314,19 @@ linux*) fi AC_DEFINE_UNQUOTED(LINUX_USB_MON_DEV, "/dev/$ac_usb_dev_name", [path for device for USB sniffing]) AC_MSG_NOTICE(Device for USB sniffing is /dev/$ac_usb_dev_name) - AC_CHECK_HEADERS(linux/usbdevice_fs.h) + # + # Do we have a version of available? + # If so, we might need it for . + # + AC_CHECK_HEADERS(linux/compiler.h) + if test "$ac_cv_header_linux_compiler_h" = yes; then + # + # Yes - include it when testing for . + # + AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include ]) + else + AC_CHECK_HEADERS(linux/usbdevice_fs.h) + fi if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then # # OK, does it define bRequestType? Older versions of the kernel @@ -1329,6 +1341,9 @@ AC_INCLUDES_DEFAULT #ifdef HAVE_SYS_BITYPES_H #include #endif +#ifdef HAVE_LINUX_COMPILER_H +#include +#endif # include ], [u_int i = sizeof(((struct usbdevfs_ctrltransfer *)0)->bRequestType)], ac_cv_usbdevfs_ctrltransfer_has_bRequestType=yes, diff --git a/libpcap/pcap-bt-linux.c b/libpcap/pcap-bt-linux.c index a36c144d8..55c1b6a1d 100644 --- a/libpcap/pcap-bt-linux.c +++ b/libpcap/pcap-bt-linux.c @@ -67,7 +67,6 @@ static const char rcsid[] _U_ = static int bt_activate(pcap_t *); static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *); static int bt_inject_linux(pcap_t *, const void *, size_t); -static int bt_setfilter_linux(pcap_t *, struct bpf_program *); static int bt_setdirection_linux(pcap_t *, pcap_direction_t); static int bt_stats_linux(pcap_t *, struct pcap_stat *); @@ -172,7 +171,7 @@ bt_activate(pcap_t* handle) handle->read_op = bt_read_linux; handle->inject_op = bt_inject_linux; - handle->setfilter_op = bt_setfilter_linux; + handle->setfilter_op = install_bpf_program; /* no kernel filtering */ handle->setdirection_op = bt_setdirection_linux; handle->set_datalink_op = NULL; /* can't change data link type */ handle->getnonblock_op = pcap_getnonblock_fd; @@ -301,10 +300,11 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us while (cmsg) { switch (cmsg->cmsg_type) { case HCI_CMSG_DIR: - in = *((int *) CMSG_DATA(cmsg)); + memcpy(&in, CMSG_DATA(cmsg), sizeof in); break; case HCI_CMSG_TSTAMP: - pkth.ts = *((struct timeval *) CMSG_DATA(cmsg)); + memcpy(&pkth.ts, CMSG_DATA(cmsg), + sizeof pkth.ts); break; } cmsg = CMSG_NXTHDR(&msg, cmsg); @@ -316,8 +316,13 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us bthdr->direction = htonl(in != 0); pkth.caplen+=sizeof(pcap_bluetooth_h4_header); pkth.len = pkth.caplen; - callback(user, &pkth, &handle->buffer[handle->offset]); - return 1; + if (handle->fcode.bf_insns == NULL || + bpf_filter(handle->fcode.bf_insns, &handle->buffer[handle->offset], + pkth.len, pkth.caplen)) { + callback(user, &pkth, &handle->buffer[handle->offset]); + return 1; + } + return 0; /* didn't pass filter */ } static int @@ -357,13 +362,6 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats) return 0; } -static int -bt_setfilter_linux(pcap_t *p, struct bpf_program *fp) -{ - return 0; -} - - static int bt_setdirection_linux(pcap_t *p, pcap_direction_t d) { diff --git a/libpcap/pcap-usb-linux.c b/libpcap/pcap-usb-linux.c index fea527f4f..f1b430c7b 100644 --- a/libpcap/pcap-usb-linux.c +++ b/libpcap/pcap-usb-linux.c @@ -61,8 +61,15 @@ static const char rcsid[] _U_ = #include #include #ifdef HAVE_LINUX_USBDEVICE_FS_H +/* + * We might need to define __user for + * . + */ +#ifdef HAVE_LINUX_COMPILER_H +#include +#endif /* HAVE_LINUX_COMPILER_H */ #include -#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 @@ -688,12 +699,6 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats) return 0; } -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) { @@ -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*/