mirror of
https://github.com/nmap/nmap.git
synced 2025-12-24 00:19:01 +00:00
Upgrade libpcap to 1.8.1 (Nmap-specific patches not yet applied)
This commit is contained in:
@@ -34,12 +34,12 @@
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/mgmt.h>
|
||||
|
||||
#include "pcap/bluetooth.h"
|
||||
#include "pcap-int.h"
|
||||
@@ -49,6 +49,16 @@
|
||||
#define BT_CONTROL_SIZE 32
|
||||
#define INTERFACE_NAME "bluetooth-monitor"
|
||||
|
||||
/*
|
||||
* Fields and alignment must match the declaration in the Linux kernel 3.4+.
|
||||
* See struct hci_mon_hdr in include/net/bluetooth/hci_mon.h.
|
||||
*/
|
||||
struct hci_mon_hdr {
|
||||
uint16_t opcode;
|
||||
uint16_t index;
|
||||
uint16_t len;
|
||||
} __attribute__((packed));
|
||||
|
||||
int
|
||||
bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str)
|
||||
{
|
||||
@@ -72,13 +82,15 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
ssize_t ret;
|
||||
struct pcap_pkthdr pkth;
|
||||
pcap_bluetooth_linux_monitor_header *bthdr;
|
||||
struct mgmt_hdr hdr;
|
||||
u_char *pktd;
|
||||
struct hci_mon_hdr hdr;
|
||||
|
||||
bthdr = (pcap_bluetooth_linux_monitor_header*) &handle->buffer[handle->offset];
|
||||
pktd = (u_char *)handle->buffer + BT_CONTROL_SIZE;
|
||||
bthdr = (pcap_bluetooth_linux_monitor_header*)(void *)pktd;
|
||||
|
||||
iv[0].iov_base = &hdr;
|
||||
iv[0].iov_len = MGMT_HDR_SIZE;
|
||||
iv[1].iov_base = &handle->buffer[handle->offset + sizeof(pcap_bluetooth_linux_monitor_header)];
|
||||
iv[0].iov_len = sizeof(hdr);
|
||||
iv[1].iov_base = pktd + sizeof(pcap_bluetooth_linux_monitor_header);
|
||||
iv[1].iov_len = handle->snapshot;
|
||||
|
||||
memset(&pkth.ts, 0, sizeof(pkth.ts));
|
||||
@@ -86,7 +98,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
msg.msg_iov = iv;
|
||||
msg.msg_iovlen = 2;
|
||||
msg.msg_control = handle->buffer;
|
||||
msg.msg_controllen = handle->offset;
|
||||
msg.msg_controllen = BT_CONTROL_SIZE;
|
||||
|
||||
do {
|
||||
ret = recvmsg(handle->fd, &msg, 0);
|
||||
@@ -98,12 +110,12 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
if (ret < 0) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Can't receive packet: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pkth.caplen = ret - MGMT_HDR_SIZE + sizeof(pcap_bluetooth_linux_monitor_header);
|
||||
pkth.caplen = ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header);
|
||||
pkth.len = pkth.caplen;
|
||||
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
@@ -118,9 +130,8 @@ 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 ||
|
||||
bpf_filter(handle->fcode.bf_insns, &handle->buffer[handle->offset],
|
||||
pkth.len, pkth.caplen)) {
|
||||
callback(user, &pkth, &handle->buffer[handle->offset]);
|
||||
bpf_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
callback(user, &pkth, pktd);
|
||||
return 1;
|
||||
}
|
||||
return 0; /* didn't pass filter */
|
||||
@@ -129,7 +140,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
static int
|
||||
bt_monitor_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
|
||||
{
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet");
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -162,8 +173,7 @@ bt_monitor_activate(pcap_t* handle)
|
||||
return PCAP_ERROR_RFMON_NOTSUP;
|
||||
}
|
||||
|
||||
handle->bufsize = handle->snapshot + BT_CONTROL_SIZE + sizeof(pcap_bluetooth_linux_monitor_header);
|
||||
handle->offset = BT_CONTROL_SIZE;
|
||||
handle->bufsize = BT_CONTROL_SIZE + sizeof(pcap_bluetooth_linux_monitor_header) + handle->snapshot;
|
||||
handle->linktype = DLT_BLUETOOTH_LINUX_MONITOR;
|
||||
|
||||
handle->read_op = bt_monitor_read;
|
||||
@@ -177,14 +187,14 @@ bt_monitor_activate(pcap_t* handle)
|
||||
|
||||
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||
if (handle->fd < 0) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Can't create raw socket: %s", strerror(errno));
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
handle->buffer = malloc(handle->bufsize);
|
||||
if (!handle->buffer) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s",
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s",
|
||||
pcap_strerror(errno));
|
||||
goto close_fail;
|
||||
}
|
||||
@@ -195,14 +205,14 @@ bt_monitor_activate(pcap_t* handle)
|
||||
addr.hci_channel = HCI_CHANNEL_MONITOR;
|
||||
|
||||
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Can't attach to interface: %s", strerror(errno));
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(handle->fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Can't enable time stamp: %s", strerror(errno));
|
||||
goto close_fail;
|
||||
}
|
||||
@@ -232,7 +242,7 @@ bt_monitor_create(const char *device, char *ebuf, int *is_ours)
|
||||
}
|
||||
|
||||
*is_ours = 1;
|
||||
p = pcap_create_common(device, ebuf, 0);
|
||||
p = pcap_create_common(ebuf, 0);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user