aboutsummaryrefslogtreecommitdiff
path: root/pcap-bt-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-05-06 14:16:14 -0700
committerGuy Harris <guy@alum.mit.edu>2013-05-06 14:16:14 -0700
commite9e96bbc3efd45ba6d1dbb097bc09845ba54c5d6 (patch)
tree88c0719044762ff35a1adedafcea69ab4dc005b5 /pcap-bt-linux.c
parent5c18aa3e68e7d54712102e359efe4567fa81eca8 (diff)
Move platform-dependent pcap_t data out of the pcap_t structure.
Put the private data right after the pcap_t structure, with a pointer to it in the pcap_t. The initial goal is to allow new pcap modules to be added without having to hack pcap-int.h. In the longer term, we may want to freeze the pcap_t structure, except possibly for adding new method pointers at the end, and provide an ABI for adding modules. We also put the stuff used by the read path at the beginning of the pcap_t structure, to try to keep it on the same set of cache lines.
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r--pcap-bt-linux.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c
index 037f64b9..e2268b8e 100644
--- a/pcap-bt-linux.c
+++ b/pcap-bt-linux.c
@@ -70,6 +70,13 @@ static int bt_inject_linux(pcap_t *, const void *, size_t);
static int bt_setdirection_linux(pcap_t *, pcap_direction_t);
static int bt_stats_linux(pcap_t *, struct pcap_stat *);
+/*
+ * Private data for capturing on Linux Bluetooth devices.
+ */
+struct pcap_bt {
+ int dev_id; /* device ID of device we're bound to */
+};
+
int
bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
@@ -169,7 +176,7 @@ bt_create(const char *device, char *ebuf, int *is_ours)
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(device, ebuf);
+ p = pcap_create_common(device, ebuf, sizeof (struct pcap_bt));
if (p == NULL)
return (NULL);
@@ -180,6 +187,7 @@ bt_create(const char *device, char *ebuf, int *is_ours)
static int
bt_activate(pcap_t* handle)
{
+ struct pcap_bt *handlep = handle->private;
struct sockaddr_hci addr;
int opt;
int dev_id;
@@ -208,7 +216,7 @@ bt_activate(pcap_t* handle)
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
handle->stats_op = bt_stats_linux;
- handle->md.ifindex = dev_id;
+ handlep->dev_id = dev_id;
/* Create HCI socket */
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
@@ -253,13 +261,13 @@ bt_activate(pcap_t* handle)
/* Bind socket to the HCI device */
addr.hci_family = AF_BLUETOOTH;
- addr.hci_dev = handle->md.ifindex;
+ addr.hci_dev = handlep->dev_id;
#ifdef SOCKADDR_HCI_HAS_HCI_CHANNEL
addr.hci_channel = HCI_CHANNEL_RAW;
#endif
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
- "Can't attach to device %d: %s", handle->md.ifindex,
+ "Can't attach to device %d: %s", handlep->dev_id,
strerror(errno));
goto close_fail;
}
@@ -374,10 +382,11 @@ bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
static int
bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
+ struct pcap_bt *handlep = handle->private;
int ret;
struct hci_dev_info dev_info;
struct hci_dev_stats * s = &dev_info.stat;
- dev_info.dev_id = handle->md.ifindex;
+ dev_info.dev_id = handlep->dev_id;
/* ignore eintr */
do {