dect
/
libpcap
Archived
13
0
Fork 0

From Paolo Abeni:

Fix the copyright notice.

	Use the new DLT_BLUETOOTH_HCI_H4_WITH_PHDR DLT, and add a
	direction indication.

	Now that we have a direction indication, support
	pcap_setdirection().

Update FILES and INSTALL.txt appropriately, and fix some problems in
INSTALL.txt.
This commit is contained in:
guy 2007-09-22 02:10:17 +00:00
parent 59a4fbc8f7
commit e4238ca93c
4 changed files with 71 additions and 12 deletions

1
FILES
View File

@ -75,6 +75,7 @@ nlpid.h
optimize.c
packaging/pcap.spec
packaging/pcap.spec.in
pcap/bluetooth.h
pcap/bpf.h
pcap/namedb.h
pcap/pcap.h

View File

@ -1,4 +1,4 @@
@(#) $Header: /tcpdump/master/libpcap/INSTALL.txt,v 1.20 2007-09-12 19:09:50 guy Exp $ (LBL)
@(#) $Header: /tcpdump/master/libpcap/INSTALL.txt,v 1.21 2007-09-22 02:10:17 guy Exp $ (LBL)
To build libpcap, run "./configure" (a shell script). The configure
script will determine your system attributes and generate an
@ -351,11 +351,12 @@ nlpid.h - OSI network layer protocol identifier definitions
net - symlink to bpf/net
optimize.c - BPF optimization routines
packaging - packaging information for building libpcap RPMs
pcap/pcap-bpf.h - BPF definitions
pcap/bluetooth.h - public definition of DLT_BLUETOOTH_HCI_H4_WITH_PHDR header
pcap/bpf.h - BPF definitions
pcap/namedb.h - public libpcap name database definitions
pcap/pcap.h - public libpcap definitions
pcap/sll.h - public definition of DLT_LINUX_SLL header
pcap/usb.h - public definition of DLT_USB headeer
pcap/usb.h - public definition of DLT_USB header
pcap-bpf.c - BSD Packet Filter support
pcap-bpf.h - header for backwards compatibility
pcap-bt-linux.c - Bluetooth capture support for Linux

View File

@ -11,8 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
@ -34,7 +33,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.8 2007-08-18 20:54:52 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.9 2007-09-22 02:10:17 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -43,6 +42,7 @@ static const char rcsid[] _U_ =
#include "pcap-int.h"
#include "pcap-bt-linux.h"
#include "pcap/bluetooth.h"
#ifdef NEED_STRERROR_H
#include "strerror.h"
@ -55,6 +55,7 @@ static const char rcsid[] _U_ =
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
@ -162,9 +163,9 @@ bt_open_live(const char* bus, int snaplen, int promisc , int to_ms, char* errmsg
memset(handle, 0, sizeof(*handle));
handle->snapshot = snaplen;
handle->md.timeout = to_ms;
handle->bufsize = snaplen+BT_CTRL_SIZE;
handle->bufsize = snaplen+BT_CTRL_SIZE+sizeof(pcap_bluetooth_h4_header);
handle->offset = BT_CTRL_SIZE;
handle->linktype = DLT_BLUETOOTH_HCI_H4;
handle->linktype = DLT_BLUETOOTH_HCI_H4_WITH_PHDR;
handle->read_op = bt_read_linux;
handle->inject_op = bt_inject_linux;
@ -186,7 +187,7 @@ bt_open_live(const char* bus, int snaplen, int promisc , int to_ms, char* errmsg
return NULL;
}
handle->buffer = malloc(snaplen+BT_CTRL_SIZE);
handle->buffer = malloc(handle->bufsize);
if (!handle->buffer) {
snprintf(errmsg, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s",
pcap_strerror(errno));
@ -244,8 +245,10 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
struct msghdr msg;
struct iovec iv;
struct pcap_pkthdr pkth;
pcap_bluetooth_h4_header* bthdr;
iv.iov_base = &handle->buffer[handle->offset];
bthdr = (pcap_bluetooth_h4_header*) &handle->buffer[handle->offset];
iv.iov_base = &handle->buffer[handle->offset+sizeof(pcap_bluetooth_h4_header)];
iv.iov_len = handle->snapshot;
memset(&msg, 0, sizeof(msg));
@ -273,8 +276,8 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
/* get direction and timestamp*/
cmsg = CMSG_FIRSTHDR(&msg);
int in=0;
while (cmsg) {
int in;
switch (cmsg->cmsg_type) {
case HCI_CMSG_DIR:
in = *((int *) CMSG_DATA(cmsg));
@ -285,8 +288,14 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
}
cmsg = CMSG_NXTHDR(&msg, cmsg);
}
if ((in && (handle->direction == PCAP_D_OUT)) ||
((!in) && (handle->direction == PCAP_D_IN)))
return 0;
bthdr->direction = htonl(in != 0);
pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
pkth.len = pkth.caplen;
callback(user, &pkth, iv.iov_base);
callback(user, &pkth, &handle->buffer[handle->offset]);
return 1;
}

48
pcap/bluetooth.h Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* bluetooth data struct
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007-09-22 02:10:17 guy Exp $
*/
#ifndef _PCAP_BLUETOOTH_STRUCTS_H__
#define _PCAP_BLUETOOTH_STRUCTS_H__
/*
* Header prepended libpcap to each bluetooth h:4 frame.
* fields are in network byte order
*/
typedef struct _pcap_bluetooth_h4_header {
u_int32_t direction; /* if first bit is set direction is incoming */
} pcap_bluetooth_h4_header;
#endif