aboutsummaryrefslogtreecommitdiff
path: root/pcap-bt-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2010-06-04 10:48:16 -0700
committerGuy Harris <guy@alum.mit.edu>2010-06-04 10:48:16 -0700
commit85089fea5732acc004dcc7e6aebcb0510c37f675 (patch)
treeb41a5c008b7042ca047265327ba61238980413f2 /pcap-bt-linux.c
parentf0a4bdf8e0bd9a6dc5de8efd01e6f3df3516f2b0 (diff)
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.
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r--pcap-bt-linux.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c
index a36c144d..55c1b6a1 100644
--- a/pcap-bt-linux.c
+++ b/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
@@ -358,13 +363,6 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
}
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)
{
p->direction = d;