aboutsummaryrefslogtreecommitdiff
path: root/pcap-bt-linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r--pcap-bt-linux.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c
index c7bfef1dfad7..2fc51665e4bc 100644
--- a/pcap-bt-linux.c
+++ b/pcap-bt-linux.c
@@ -32,13 +32,12 @@
*
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include "pcap-int.h"
#include "pcap-bt-linux.h"
#include "pcap/bluetooth.h"
+#include "diag-control.h"
#include <errno.h>
#include <stdlib.h>
@@ -84,9 +83,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
/* if bluetooth is not supported this is not fatal*/
if (errno == EAFNOSUPPORT)
return 0;
- pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
errno, "Can't open raw Bluetooth socket");
- return -1;
+ return PCAP_ERROR;
}
dev_list = malloc(HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
@@ -94,7 +93,7 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
{
snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't allocate %zu bytes for Bluetooth device list",
HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
- ret = -1;
+ ret = PCAP_ERROR;
goto done;
}
@@ -110,9 +109,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
{
- pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
errno, "Can't get Bluetooth device list via ioctl");
- ret = -1;
+ ret = PCAP_ERROR;
goto free;
}
@@ -131,9 +130,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* the status to PCAP_IF_CONNECTION_STATUS_CONNECTED
* or PCAP_IF_CONNECTION_STATUS_DISCONNECTED.
*/
- if (add_dev(devlistp, dev_name, PCAP_IF_WIRELESS, dev_descr, err_str) == NULL)
+ if (pcapint_add_dev(devlistp, dev_name, PCAP_IF_WIRELESS, dev_descr, err_str) == NULL)
{
- ret = -1;
+ ret = PCAP_ERROR;
break;
}
}
@@ -225,39 +224,39 @@ bt_activate(pcap_t* handle)
handle->read_op = bt_read_linux;
handle->inject_op = bt_inject_linux;
- handle->setfilter_op = install_bpf_program; /* no kernel filtering */
+ handle->setfilter_op = pcapint_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;
- handle->setnonblock_op = pcap_setnonblock_fd;
+ handle->getnonblock_op = pcapint_getnonblock_fd;
+ handle->setnonblock_op = pcapint_setnonblock_fd;
handle->stats_op = bt_stats_linux;
handlep->dev_id = dev_id;
/* Create HCI socket */
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (handle->fd < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't create raw socket");
return PCAP_ERROR;
}
handle->buffer = malloc(handle->bufsize);
if (!handle->buffer) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't allocate dump buffer");
goto close_fail;
}
opt = 1;
if (setsockopt(handle->fd, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't enable data direction info");
goto close_fail;
}
opt = 1;
if (setsockopt(handle->fd, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't enable time stamp");
goto close_fail;
}
@@ -268,7 +267,7 @@ bt_activate(pcap_t* handle)
memset((void *) &flt.type_mask, 0xff, sizeof(flt.type_mask));
memset((void *) &flt.event_mask, 0xff, sizeof(flt.event_mask));
if (setsockopt(handle->fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't set filter");
goto close_fail;
}
@@ -281,7 +280,7 @@ bt_activate(pcap_t* handle)
addr.hci_channel = HCI_CHANNEL_RAW;
#endif
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't attach to device %d", handlep->dev_id);
goto close_fail;
}
@@ -301,7 +300,7 @@ bt_activate(pcap_t* handle)
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
&handle->opt.buffer_size,
sizeof(handle->opt.buffer_size)) == -1) {
- pcap_fmt_errmsg_for_errno(handle->errbuf,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf,
errno, PCAP_ERRBUF_SIZE, "SO_RCVBUF");
goto close_fail;
}
@@ -311,7 +310,7 @@ bt_activate(pcap_t* handle)
return 0;
close_fail:
- pcap_cleanup_live_common(handle);
+ pcapint_cleanup_live_common(handle);
return err;
}
@@ -340,12 +339,12 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
/* ignore interrupt system call error */
do {
- ret = recvmsg(handle->fd, &msg, 0);
if (handle->break_loop)
{
handle->break_loop = 0;
- return -2;
+ return PCAP_ERROR_BREAK;
}
+ ret = recvmsg(handle->fd, &msg, 0);
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
@@ -353,9 +352,9 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
/* Nonblocking mode, no data */
return 0;
}
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't receive packet");
- return -1;
+ return PCAP_ERROR;
}
pkth.caplen = (bpf_u_int32)ret;
@@ -372,7 +371,10 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
sizeof pkth.ts);
break;
}
+ // for musl libc CMSG_NXTHDR()
+DIAG_OFF_SIGN_COMPARE
cmsg = CMSG_NXTHDR(&msg, cmsg);
+DIAG_ON_SIGN_COMPARE
}
switch (handle->direction) {
@@ -394,7 +396,7 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
pkth.len = pkth.caplen;
if (handle->fcode.bf_insns == NULL ||
- pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
+ pcapint_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
callback(user, &pkth, pktd);
return 1;
}
@@ -425,13 +427,13 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
- pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't get stats via ioctl");
return (-1);
}
- /* we receive both rx and tx frames, so comulate all stats */
+ /* we receive both rx and tx frames, so cumulate all stats */
stats->ps_recv = s->evt_rx + s->acl_rx + s->sco_rx + s->cmd_tx +
s->acl_tx +s->sco_tx;
stats->ps_drop = s->err_rx + s->err_tx;