diff options
Diffstat (limited to 'pcap-bt-monitor-linux.c')
-rw-r--r-- | pcap-bt-monitor-linux.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/pcap-bt-monitor-linux.c b/pcap-bt-monitor-linux.c index 521d6d500d05..c222c100edb2 100644 --- a/pcap-bt-monitor-linux.c +++ b/pcap-bt-monitor-linux.c @@ -30,7 +30,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <errno.h> @@ -60,12 +60,21 @@ struct hci_mon_hdr { } __attribute__((packed)); int -bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str) +bt_monitor_findalldevs(pcap_if_list_t *devlistp, char *err_str) { int ret = 0; - if (pcap_add_if(alldevsp, INTERFACE_NAME, 0, - "Bluetooth Linux Monitor", err_str) < 0) + /* + * Bluetooth is a wireless technology. + * + * This is a device to monitor all Bluetooth interfaces, so + * there's no notion of "connected" or "disconnected", any + * more than there's a notion of "connected" or "disconnected" + * for the "any" device. + */ + if (add_dev(devlistp, INTERFACE_NAME, + PCAP_IF_WIRELESS|PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, + "Bluetooth Linux Monitor", err_str) == NULL) { ret = -1; } @@ -110,8 +119,8 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch } while ((ret == -1) && (errno == EINTR)); if (ret < 0) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "Can't receive packet: %s", strerror(errno)); + pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, + errno, "Can't receive packet"); return -1; } @@ -173,6 +182,17 @@ bt_monitor_activate(pcap_t* handle) return PCAP_ERROR_RFMON_NOTSUP; } + /* + * Turn a negative snapshot value (invalid), a snapshot value of + * 0 (unspecified), or a value bigger than the normal maximum + * value, into the maximum allowed value. + * + * If some application really *needs* a bigger snapshot + * length, we should just increase MAXIMUM_SNAPLEN. + */ + if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN) + handle->snapshot = MAXIMUM_SNAPLEN; + handle->bufsize = BT_CONTROL_SIZE + sizeof(pcap_bluetooth_linux_monitor_header) + handle->snapshot; handle->linktype = DLT_BLUETOOTH_LINUX_MONITOR; @@ -187,15 +207,15 @@ bt_monitor_activate(pcap_t* handle) handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (handle->fd < 0) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "Can't create raw socket: %s", strerror(errno)); + pcap_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_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s", - pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, + errno, "Can't allocate dump buffer"); goto close_fail; } @@ -205,15 +225,15 @@ bt_monitor_activate(pcap_t* handle) addr.hci_channel = HCI_CHANNEL_MONITOR; if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "Can't attach to interface: %s", strerror(errno)); + pcap_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_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "Can't enable time stamp: %s", strerror(errno)); + pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, + errno, "Can't enable time stamp"); goto close_fail; } |