aboutsummaryrefslogtreecommitdiff
path: root/pcap-bt-monitor-linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcap-bt-monitor-linux.c')
-rw-r--r--pcap-bt-monitor-linux.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/pcap-bt-monitor-linux.c b/pcap-bt-monitor-linux.c
index 206e65b52122..dfba80516dda 100644
--- a/pcap-bt-monitor-linux.c
+++ b/pcap-bt-monitor-linux.c
@@ -29,9 +29,7 @@
*
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include <errno.h>
#include <stdint.h>
@@ -43,6 +41,7 @@
#include "pcap/bluetooth.h"
#include "pcap-int.h"
+#include "diag-control.h"
#include "pcap-bt-monitor-linux.h"
@@ -80,11 +79,11 @@ bt_monitor_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* more than there's a notion of "connected" or "disconnected"
* for the "any" device.
*/
- if (add_dev(devlistp, INTERFACE_NAME,
+ if (pcapint_add_dev(devlistp, INTERFACE_NAME,
PCAP_IF_WIRELESS|PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
"Bluetooth Linux Monitor", err_str) == NULL)
{
- ret = -1;
+ ret = PCAP_ERROR;
}
return ret;
@@ -118,12 +117,12 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
msg.msg_controllen = BT_CONTROL_SIZE;
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) {
@@ -131,15 +130,18 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
/* 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 - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header));
pkth.len = pkth.caplen;
+ // for musl libc CMSG_NXTHDR()
+DIAG_OFF_SIGN_COMPARE
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+DIAG_ON_SIGN_COMPARE
if (cmsg->cmsg_level != SOL_SOCKET) continue;
if (cmsg->cmsg_type == SCM_TIMESTAMP) {
@@ -151,7 +153,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
bthdr->opcode = htons(hdr.opcode);
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;
}
@@ -163,7 +165,7 @@ bt_monitor_inject(pcap_t *handle, const void *buf _U_, int size _U_)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Packet injection is not supported yet on Bluetooth monitor devices");
- return -1;
+ return PCAP_ERROR;
}
static int
@@ -204,23 +206,23 @@ bt_monitor_activate(pcap_t* handle)
handle->read_op = bt_monitor_read;
handle->inject_op = bt_monitor_inject;
- handle->setfilter_op = install_bpf_program; /* no kernel filtering */
+ handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
handle->setdirection_op = NULL; /* Not implemented */
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_monitor_stats;
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;
}
@@ -231,14 +233,14 @@ bt_monitor_activate(pcap_t* handle)
addr.hci_channel = HCI_CHANNEL_MONITOR;
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 interface");
goto close_fail;
}
opt = 1;
if (setsockopt(handle->fd, SOL_SOCKET, SO_TIMESTAMP, &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;
}
@@ -248,7 +250,7 @@ bt_monitor_activate(pcap_t* handle)
return 0;
close_fail:
- pcap_cleanup_live_common(handle);
+ pcapint_cleanup_live_common(handle);
return err;
}