aboutsummaryrefslogtreecommitdiff
path: root/pcap.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-10-19 18:07:04 -0700
committerElliott Hughes <enh@google.com>2015-10-20 14:06:47 -0700
commitd8845d7191ca81aae8aab4c29410fc8a3d012687 (patch)
tree93eface1b79d0172beec96c422f5921661455849 /pcap.c
parentc442bf68e06f961ad0f8fc5a7d19e0984985ea30 (diff)
downloadlibpcap-d8845d7191ca81aae8aab4c29410fc8a3d012687.tar.gz
Upgrade to libpcap 1.7.4.
Bug: http://b/24902618 Change-Id: I1bb6c1163b573eb01b4bed7c494a6d447e8d45cf
Diffstat (limited to 'pcap.c')
-rw-r--r--pcap.c72
1 files changed, 54 insertions, 18 deletions
diff --git a/pcap.c b/pcap.c
index 6b16ceab..4e9c94a7 100644
--- a/pcap.c
+++ b/pcap.c
@@ -31,11 +31,6 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.128 2008-12-23 20:13:29 guy Exp $ (LBL)";
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -93,6 +88,10 @@ static const char rcsid[] _U_ =
#include "pcap-bt-linux.h"
#endif
+#ifdef PCAP_SUPPORT_BT_MONITOR
+#include "pcap-bt-monitor-linux.h"
+#endif
+
#ifdef PCAP_SUPPORT_CAN
#include "pcap-can-linux.h"
#endif
@@ -109,7 +108,7 @@ static const char rcsid[] _U_ =
#include "pcap-dbus.h"
#endif
-int
+int
pcap_not_initialized(pcap_t *pcap _U_)
{
/* this means 'not initialized' */
@@ -221,7 +220,7 @@ pcap_next(pcap_t *p, struct pcap_pkthdr *h)
return (pkt);
}
-int
+int
pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
const u_char **pkt_data)
{
@@ -281,7 +280,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
- return (dag_create(source, errbuf));
+ int is_ours;
+ return (dag_create(source, errbuf, &is_ours));
}
#elif defined(SEPTEL_ONLY)
int
@@ -293,7 +293,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
- return (septel_create(source, errbuf));
+ int is_ours;
+ return (septel_create(source, errbuf, &is_ours));
}
#elif defined(SNF_ONLY)
int
@@ -305,7 +306,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
- return (snf_create(source, errbuf));
+ int is_ours;
+ return (snf_create(source, errbuf, &is_ours));
}
#else /* regular pcap */
struct capture_source_type {
@@ -324,6 +326,9 @@ struct capture_source_type {
#ifdef PCAP_SUPPORT_BT
{ bt_findalldevs, bt_create },
#endif
+#ifdef PCAP_SUPPORT_BT_MONITOR
+ { bt_monitor_findalldevs, bt_monitor_create },
+#endif
#if PCAP_SUPPORT_CANUSB
{ canusb_findalldevs, canusb_create },
#endif
@@ -355,7 +360,7 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
/*
* Get the list of regular interfaces first.
- */
+ */
if (pcap_findalldevs_interfaces(alldevsp, errbuf) == -1)
return (-1); /* failure */
@@ -392,6 +397,7 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
return (-1);
}
}
+
return (0);
}
@@ -506,7 +512,7 @@ pcap_alloc_pcap_t(char *ebuf, size_t size)
#ifndef WIN32
p->fd = -1; /* not opened yet */
p->selectable_fd = -1;
-#endif
+#endif
if (size == 0) {
/* No private data was requested. */
@@ -550,14 +556,20 @@ pcap_create_common(const char *source, char *ebuf, size_t size)
initialize_ops(p);
/* put in some defaults*/
- pcap_set_snaplen(p, 65535); /* max packet size */
- p->opt.timeout = 0; /* no timeout specified */
- p->opt.buffer_size = 0; /* use the platform's default */
+ pcap_set_snaplen(p, MAXIMUM_SNAPLEN); /* max packet size */
+ p->opt.timeout = 0; /* no timeout specified */
+ p->opt.buffer_size = 0; /* use the platform's default */
p->opt.promisc = 0;
p->opt.rfmon = 0;
p->opt.immediate = 0;
p->opt.tstamp_type = -1; /* default to not setting time stamp type */
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
+
+ /*
+ * Start out with no BPF code generation flags set.
+ */
+ p->bpf_codegen_flags = 0;
+
return (p);
}
@@ -1182,6 +1194,7 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_AX25_KISS, "AX.25 with KISS header"),
DLT_CHOICE(DLT_IEEE802_15_4_NONASK_PHY, "IEEE 802.15.4 with non-ASK PHY data"),
DLT_CHOICE(DLT_MPLS, "MPLS with label as link-layer header"),
+ DLT_CHOICE(DLT_LINUX_EVDEV, "Linux evdev events"),
DLT_CHOICE(DLT_USB_LINUX_MMAPPED, "USB with padded Linux header"),
DLT_CHOICE(DLT_DECT, "DECT"),
DLT_CHOICE(DLT_AOS, "AOS Space Data Link protocol"),
@@ -1193,16 +1206,33 @@ static struct dlt_choice dlt_choices[] = {
DLT_CHOICE(DLT_IPV4, "Raw IPv4"),
DLT_CHOICE(DLT_IPV6, "Raw IPv6"),
DLT_CHOICE(DLT_IEEE802_15_4_NOFCS, "IEEE 802.15.4 without FCS"),
+ DLT_CHOICE(DLT_DBUS, "D-Bus"),
DLT_CHOICE(DLT_JUNIPER_VS, "Juniper Virtual Server"),
DLT_CHOICE(DLT_JUNIPER_SRX_E2E, "Juniper SRX E2E"),
DLT_CHOICE(DLT_JUNIPER_FIBRECHANNEL, "Juniper Fibre Channel"),
DLT_CHOICE(DLT_DVB_CI, "DVB-CI"),
+ DLT_CHOICE(DLT_MUX27010, "MUX27010"),
+ DLT_CHOICE(DLT_STANAG_5066_D_PDU, "STANAG 5066 D_PDUs"),
DLT_CHOICE(DLT_JUNIPER_ATM_CEMIC, "Juniper ATM CEMIC"),
DLT_CHOICE(DLT_NFLOG, "Linux netfilter log messages"),
DLT_CHOICE(DLT_NETANALYZER, "Ethernet with Hilscher netANALYZER pseudo-header"),
DLT_CHOICE(DLT_NETANALYZER_TRANSPARENT, "Ethernet with Hilscher netANALYZER pseudo-header and with preamble and SFD"),
DLT_CHOICE(DLT_IPOIB, "RFC 4391 IP-over-Infiniband"),
- DLT_CHOICE(DLT_DBUS, "D-Bus"),
+ DLT_CHOICE(DLT_MPEG_2_TS, "MPEG-2 transport stream"),
+ DLT_CHOICE(DLT_NG40, "ng40 protocol tester Iub/Iur"),
+ DLT_CHOICE(DLT_NFC_LLCP, "NFC LLCP PDUs with pseudo-header"),
+ DLT_CHOICE(DLT_INFINIBAND, "InfiniBand"),
+ DLT_CHOICE(DLT_SCTP, "SCTP"),
+ DLT_CHOICE(DLT_USBPCAP, "USB with USBPcap header"),
+ DLT_CHOICE(DLT_RTAC_SERIAL, "Schweitzer Engineering Laboratories RTAC packets"),
+ DLT_CHOICE(DLT_BLUETOOTH_LE_LL, "Bluetooth Low Energy air interface"),
+ DLT_CHOICE(DLT_NETLINK, "Linux netlink"),
+ DLT_CHOICE(DLT_BLUETOOTH_LINUX_MONITOR, "Bluetooth Linux Monitor"),
+ DLT_CHOICE(DLT_BLUETOOTH_BREDR_BB, "Bluetooth Basic Rate/Enhanced Data Rate baseband packets"),
+ DLT_CHOICE(DLT_BLUETOOTH_LE_LL_WITH_PHDR, "Bluetooth Low Energy air interface with pseudo-header"),
+ DLT_CHOICE(DLT_PROFIBUS_DL, "PROFIBUS data link layer"),
+ DLT_CHOICE(DLT_PKTAP, "Apple DLT_PKTAP"),
+ DLT_CHOICE(DLT_EPON, "Ethernet with 802.3 Clause 65 EPON preamble"),
DLT_CHOICE_SENTINEL
};
@@ -1458,7 +1488,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf)
#ifdef WIN32
/*
- * Generate a string for the last Win32-specific error (i.e. an error generated when
+ * Generate a string for the last Win32-specific error (i.e. an error generated when
* calling a Win32 API).
* For errors occurred during standard C calls, we still use pcap_strerror()
*/
@@ -1810,6 +1840,12 @@ pcap_open_dead_with_tstamp_precision(int linktype, int snaplen, u_int precision)
p->setmintocopy_op = pcap_setmintocopy_dead;
#endif
p->cleanup_op = pcap_cleanup_dead;
+
+ /*
+ * A "dead" pcap_t never requires special BPF code generation.
+ */
+ p->bpf_codegen_flags = 0;
+
p->activated = 1;
return (p);
}
@@ -1866,7 +1902,7 @@ pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
{
const struct bpf_insn *fcode = fp->bf_insns;
- if (fcode != NULL)
+ if (fcode != NULL)
return (bpf_filter(fcode, pkt, h->len, h->caplen));
else
return (0);