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.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c
index f9f128ac..0c6c08d1 100644
--- a/pcap-bt-linux.c
+++ b/pcap-bt-linux.c
@@ -85,8 +85,8 @@ bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str)
/* if bluetooth is not supported this this is not fatal*/
if (errno == EAFNOSUPPORT)
return 0;
- snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't open raw Bluetooth socket %d:%s",
- errno, strerror(errno));
+ snprintf(err_str, PCAP_ERRBUF_SIZE,
+ "Can't open raw Bluetooth socket: %s", strerror(errno));
return -1;
}
@@ -103,8 +103,9 @@ bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str)
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
{
- snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't get Bluetooth device list via ioctl %d:%s",
- errno, strerror(errno));
+ snprintf(err_str, PCAP_ERRBUF_SIZE,
+ "Can't get Bluetooth device list via ioctl: %s",
+ strerror(errno));
ret = -1;
goto free;
}
@@ -182,8 +183,8 @@ bt_activate(pcap_t* handle)
/* Create HCI socket */
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (handle->fd < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s",
- errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't create raw socket: %s", strerror(errno));
return PCAP_ERROR;
}
@@ -196,15 +197,15 @@ bt_activate(pcap_t* handle)
opt = 1;
if (setsockopt(handle->fd, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't enable data direction info %d:%s",
- errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't enable data direction info: %s", strerror(errno));
goto close_fail;
}
opt = 1;
if (setsockopt(handle->fd, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't enable time stamp %d:%s",
- errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't enable time stamp: %s", strerror(errno));
goto close_fail;
}
@@ -214,8 +215,8 @@ 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) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't set filter %d:%s",
- errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't set filter: %s", strerror(errno));
goto close_fail;
}
@@ -224,8 +225,9 @@ bt_activate(pcap_t* handle)
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = handle->md.ifindex;
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't attach to device %d %d:%s",
- handle->md.ifindex, errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't attach to device %d: %s", handle->md.ifindex,
+ strerror(errno));
goto close_fail;
}
@@ -264,6 +266,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
struct cmsghdr *cmsg;
struct msghdr msg;
struct iovec iv;
+ ssize_t ret;
struct pcap_pkthdr pkth;
pcap_bluetooth_h4_header* bthdr;
@@ -279,21 +282,22 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
/* ignore interrupt system call error */
do {
- pkth.caplen = recvmsg(handle->fd, &msg, 0);
+ ret = recvmsg(handle->fd, &msg, 0);
if (handle->break_loop)
{
handle->break_loop = 0;
return -2;
}
- } while ((pkth.caplen == -1) && (errno == EINTR));
+ } while ((ret == -1) && (errno == EINTR));
-
- if (pkth.caplen < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't receive packet %d:%s",
- errno, strerror(errno));
+ if (ret < 0) {
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't receive packet: %s", strerror(errno));
return -1;
}
+ pkth.caplen = ret;
+
/* get direction and timestamp*/
cmsg = CMSG_FIRSTHDR(&msg);
int in=0;
@@ -348,8 +352,8 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
- snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "can get stats"
- " via ioctl %d:%s", errno, strerror(errno));
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Can't get stats via ioctl: %s", strerror(errno));
return (-1);
}