Cherry-pick changes to require <linux/compiler.h>.

I needed this to build with --with-libpcap=included on Linux 2.6.16,
otherwise I got this error:

gcc -g -O2 -O2 -fpic -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -c ./pcap-usb-linux.c
./pcap-usb-linux.c: In function ‘probe_devices’:
./pcap-usb-linux.c:234: error: storage size of ‘ctrl’ isn’t known
./pcap-usb-linux.c:279: error: ‘USBDEVFS_CONTROL’ undeclared (first use in this function)
./pcap-usb-linux.c:279: error: (Each undeclared identifier is reported only once
./pcap-usb-linux.c:279: error: for each function it appears in.)
make[1]: *** [pcap-usb-linux.o] Error 1

commit a092bafeee07c97352d2c6d06780220286ab2db0
Author: Guy Harris <guy@alum.mit.edu>
Date:   Tue Nov 30 15:52:45 2010 -0800

    In test programs, just as in pcap-usb-linux.c, if we have
    <linux/compiler.h> we (probably need to include it before including
    <linux/usbdevice_fs.h>, otherwise the test may fail when it shouldn't.

commit b019cc06cb4fdc01f99a36581fe7b55e2533d663
Author: Guy Harris <guy@alum.mit.edu>
Date:   Thu Nov 25 14:06:01 2010 -0800

    Check whether we have <linux/compiler.h>.

    Not all distributions have it in /usr/include; I guess the ones that
    don't have it have versions of other kernel headers that don't require
    it.

commit 0920898be2ede72baafa2a02e77ea223ecbe4f9a
Author: Guy Harris <guy@alum.mit.edu>
Date:   Thu Nov 25 13:49:16 2010 -0800

    Include <linux/compiler.h> before including <linux/usbdevice_fs.h>.

    Some versions of the Linux kernel require that.

commit 85089fea5732acc004dcc7e6aebcb0510c37f675
Author: Guy Harris <guy@alum.mit.edu>
Date:   Fri Jun 4 10:48:16 2010 -0700

    Do filtering on USB and Bluetooth capturing.

    Do the standard userland filtering on USB and Bluetooth captures, rather
    than returning "success" when the filter is installed without doing
    anything with the filter.

    Also, squelch some "dereferencing type-punned pointer will break
    strict-aliasing rules" warnings in pcap-bt-linux.c, by using memcpy
    rather than pointer-casting.
This commit is contained in:
david 2011-10-27 15:38:30 +00:00
parent 05187ede6f
commit 7197d18d52
5 changed files with 102 additions and 33 deletions

View file

@ -55,6 +55,9 @@
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <linux/compiler.h> header file. */
#undef HAVE_LINUX_COMPILER_H
/* if tp_vlan_tci exists */
#undef HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI

40
libpcap/configure vendored
View file

@ -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 <linux/compiler.h> available?
# If so, we might need it for <linux/usbdevice_fs.h>.
#
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 <linux/usbdevice_fs.h>.
#
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 <linux/compiler.h>
"
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 <sys/bitypes.h>
#endif
#ifdef HAVE_LINUX_COMPILER_H
#include <linux/compiler.h>
#endif
# include <linux/usbdevice_fs.h>
int
main ()

View file

@ -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 <linux/compiler.h> available?
# If so, we might need it for <linux/usbdevice_fs.h>.
#
AC_CHECK_HEADERS(linux/compiler.h)
if test "$ac_cv_header_linux_compiler_h" = yes; then
#
# Yes - include it when testing for <linux/usbdevice_fs.h>.
#
AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
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 <sys/bitypes.h>
#endif
#ifdef HAVE_LINUX_COMPILER_H
#include <linux/compiler.h>
#endif
# include <linux/usbdevice_fs.h>],
[u_int i = sizeof(((struct usbdevfs_ctrltransfer *)0)->bRequestType)],
ac_cv_usbdevfs_ctrltransfer_has_bRequestType=yes,

View file

@ -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)
{

View file

@ -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
@ -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*/