1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-10 09:49:05 +00:00

Update libpcap to 1.9.0 (no patches applied yet)

This commit is contained in:
dmiller
2019-03-30 03:24:44 +00:00
parent 7d860b04e5
commit a2442ea29f
197 changed files with 26419 additions and 22082 deletions

View File

@@ -33,17 +33,13 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include "pcap-int.h"
#include "pcap-bt-linux.h"
#include "pcap/bluetooth.h"
#ifdef NEED_STRERROR_H
#include "strerror.h"
#endif
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
@@ -74,7 +70,7 @@ struct pcap_bt {
};
int
bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
{
struct hci_dev_list_req *dev_list;
struct hci_dev_req *dev_req;
@@ -87,8 +83,8 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
/* if bluetooth is not supported this this is not fatal*/
if (errno == EAFNOSUPPORT)
return 0;
pcap_snprintf(err_str, PCAP_ERRBUF_SIZE,
"Can't open raw Bluetooth socket: %s", strerror(errno));
pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
errno, "Can't open raw Bluetooth socket");
return -1;
}
@@ -105,9 +101,8 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
{
pcap_snprintf(err_str, PCAP_ERRBUF_SIZE,
"Can't get Bluetooth device list via ioctl: %s",
strerror(errno));
pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
errno, "Can't get Bluetooth device list via ioctl");
ret = -1;
goto free;
}
@@ -119,13 +114,19 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
pcap_snprintf(dev_name, 20, BT_IFACE"%d", dev_req->dev_id);
pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
if (pcap_add_if(alldevsp, dev_name, 0,
dev_descr, err_str) < 0)
/*
* Bluetooth is a wireless technology.
* XXX - if there's the notion of associating with a
* network, and we can determine whether the interface
* is associated with a network, check that and set
* 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)
{
ret = -1;
break;
}
}
free:
@@ -198,6 +199,17 @@ bt_activate(pcap_t* handle)
return PCAP_ERROR;
}
/*
* 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;
/* Initialize some components of the pcap structure. */
handle->bufsize = BT_CTRL_SIZE+sizeof(pcap_bluetooth_h4_header)+handle->snapshot;
handle->linktype = DLT_BLUETOOTH_HCI_H4_WITH_PHDR;
@@ -215,29 +227,29 @@ bt_activate(pcap_t* handle)
/* Create HCI socket */
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;
}
opt = 1;
if (setsockopt(handle->fd, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't enable data direction info: %s", strerror(errno));
pcap_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_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;
}
@@ -247,8 +259,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) {
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't set filter: %s", strerror(errno));
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't set filter");
goto close_fail;
}
@@ -256,13 +268,12 @@ bt_activate(pcap_t* handle)
/* Bind socket to the HCI device */
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = handlep->dev_id;
#ifdef SOCKADDR_HCI_HAS_HCI_CHANNEL
#ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
addr.hci_channel = HCI_CHANNEL_RAW;
#endif
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't attach to device %d: %s", handlep->dev_id,
strerror(errno));
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't attach to device %d", handlep->dev_id);
goto close_fail;
}
@@ -281,8 +292,8 @@ bt_activate(pcap_t* handle)
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
&handle->opt.buffer_size,
sizeof(handle->opt.buffer_size)) == -1) {
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"SO_RCVBUF: %s", pcap_strerror(errno));
pcap_fmt_errmsg_for_errno(handle->errbuf,
errno, PCAP_ERRBUF_SIZE, "SO_RCVBUF");
goto close_fail;
}
}
@@ -296,7 +307,7 @@ close_fail:
}
static int
bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *user)
{
struct cmsghdr *cmsg;
struct msghdr msg;
@@ -329,8 +340,8 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
} 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;
}
@@ -366,7 +377,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
}
static int
bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
bt_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on "
"bluetooth devices");
@@ -389,8 +400,8 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get stats via ioctl: %s", strerror(errno));
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "Can't get stats via ioctl");
return (-1);
}