|
| 1 | +/***********************IMPORTANT NPCAP LICENSE TERMS*********************** |
| 2 | + * |
| 3 | + * Npcap (https://npcap.com) is a Windows packet sniffing driver and library and |
| 4 | + * is copyright (c) 2013-2023 by Nmap Software LLC ("The Nmap Project"). All |
| 5 | + * rights reserved. |
| 6 | + * |
| 7 | + * Even though Npcap source code is publicly available for review, it is not |
| 8 | + * open source software and may not be redistributed or used in other software |
| 9 | + * without special permission from the Nmap Project. The standard (free) version |
| 10 | + * is usually limited to installation on five systems. For more details, see the |
| 11 | + * LICENSE file included with Npcap and also available at |
| 12 | + * https://github.com/nmap/npcap/blob/master/LICENSE. This header file |
| 13 | + * summarizes a few important aspects of the Npcap license, but is not a |
| 14 | + * substitute for that full Npcap license agreement. |
| 15 | + * |
| 16 | + * We fund the Npcap project by selling two types of commercial licenses to a |
| 17 | + * special Npcap OEM edition: |
| 18 | + * |
| 19 | + * 1) The Npcap OEM Redistribution License allows companies distribute Npcap OEM |
| 20 | + * within their products. Licensees generally use the Npcap OEM silent |
| 21 | + * installer, ensuring a seamless experience for end users. Licensees may choose |
| 22 | + * between a perpetual unlimited license or a quarterly term license, along with |
| 23 | + * options for commercial support and updates. Prices and details: |
| 24 | + * https://npcap.com/oem/redist.html |
| 25 | + * |
| 26 | + * 2) The Npcap OEM Internal-Use License is for organizations that wish to use |
| 27 | + * Npcap OEM internally, without redistribution outside their organization. This |
| 28 | + * allows them to bypass the 5-system usage cap of the Npcap free edition. It |
| 29 | + * includes commercial support and update options, and provides the extra Npcap |
| 30 | + * OEM features such as the silent installer for automated deployment. Prices |
| 31 | + * and details: https://npcap.com/oem/internal.html |
| 32 | + * |
| 33 | + * Both of these licenses include updates and support as well as a warranty. |
| 34 | + * Npcap OEM also includes a silent installer for unattended installation. |
| 35 | + * Further details about Npcap OEM are available from https://npcap.com/oem/, |
| 36 | + * and you are also welcome to contact us at [email protected] to ask any questions |
| 37 | + * or set up a license for your organization. |
| 38 | + * |
| 39 | + * Free and open source software producers are also welcome to contact us for |
| 40 | + * redistribution requests. However, we normally recommend that such authors |
| 41 | + * instead ask your users to download and install Npcap themselves. It will be |
| 42 | + * free for them if they need 5 or fewer copies. |
| 43 | + * |
| 44 | + * If the Nmap Project (directly or through one of our commercial licensing |
| 45 | + * customers) has granted you additional rights to Npcap or Npcap OEM, those |
| 46 | + * additional rights take precedence where they conflict with the terms of the |
| 47 | + * license agreement. |
| 48 | + * |
| 49 | + * Since the Npcap source code is available for download and review, users |
| 50 | + * sometimes contribute code patches to fix bugs or add new features. By sending |
| 51 | + * these changes to the Nmap Project (including through direct email or our |
| 52 | + * mailing lists or submitting pull requests through our source code |
| 53 | + * repository), it is understood unless you specify otherwise that you are |
| 54 | + * offering the Nmap Project the unlimited, non-exclusive right to reuse, |
| 55 | + * modify, and relicense your code contribution so that we may (but are not |
| 56 | + * obligated to) incorporate it into Npcap. If you wish to specify special |
| 57 | + * license conditions or restrictions on your contributions, just say so when |
| 58 | + * you send them. |
| 59 | + * |
| 60 | + * This software is distributed in the hope that it will be useful, but WITHOUT |
| 61 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 62 | + * FOR A PARTICULAR PURPOSE. Warranty rights and commercial support are |
| 63 | + * available for the OEM Edition described above. |
| 64 | + * |
| 65 | + * Other copyright notices and attribution may appear below this license header. |
| 66 | + * We have kept those for attribution purposes, but any license terms granted by |
| 67 | + * those notices apply only to their original work, and not to any changes made |
| 68 | + * by the Nmap Project or to this entire file. |
| 69 | + * |
| 70 | + ***************************************************************************/ |
| 71 | +/* Portions of this file |
| 72 | + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
| 73 | + * The Regents of the University of California. All rights reserved. |
| 74 | + * |
| 75 | + * This code is derived from the Stanford/CMU enet packet filter, |
| 76 | + * (net/enet.c) distributed as part of 4.3BSD, and code contributed |
| 77 | + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence |
| 78 | + * Berkeley Laboratory. |
| 79 | + * |
| 80 | + * Redistribution and use in source and binary forms, with or without |
| 81 | + * modification, are permitted provided that the following conditions |
| 82 | + * are met: |
| 83 | + * 1. Redistributions of source code must retain the above copyright |
| 84 | + * notice, this list of conditions and the following disclaimer. |
| 85 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 86 | + * notice, this list of conditions and the following disclaimer in the |
| 87 | + * documentation and/or other materials provided with the distribution. |
| 88 | + * 3. All advertising materials mentioning features or use of this software |
| 89 | + * must display the following acknowledgement: |
| 90 | + * This product includes software developed by the University of |
| 91 | + * California, Berkeley and its contributors. |
| 92 | + * 4. Neither the name of the University nor the names of its contributors |
| 93 | + * may be used to endorse or promote products derived from this software |
| 94 | + * without specific prior written permission. |
| 95 | + * |
| 96 | + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 97 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 98 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 99 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 100 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 101 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 102 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 103 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 104 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 105 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 106 | + * SUCH DAMAGE. |
| 107 | + * |
| 108 | + */ |
| 109 | +#ifndef NPCAP_BPF_H |
| 110 | +#define NPCAP_BPF_H |
| 111 | + |
| 112 | +/* These are defined by libpcap's bpf.h, so if that has already been included, |
| 113 | + * we want to avoid redefining them here. |
| 114 | + */ |
| 115 | +#ifndef lib_pcap_bpf_h |
| 116 | + |
| 117 | +#ifndef _NTDDK_ |
| 118 | +#include <winsock2.h> |
| 119 | +#endif |
| 120 | + |
| 121 | +/*! |
| 122 | + \brief A BPF pseudo-assembly program. |
| 123 | +
|
| 124 | + The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet. |
| 125 | +*/ |
| 126 | +struct bpf_program |
| 127 | +{ |
| 128 | + UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow. |
| 129 | +#ifdef _Field_size_full_ /* SAL annotation */ |
| 130 | + _Field_size_full_(bf_len) |
| 131 | +#endif |
| 132 | + struct bpf_insn* bf_insns; ///< A pointer to the first instruction of the program. |
| 133 | +}; |
| 134 | + |
| 135 | +/*! |
| 136 | + \brief A single BPF pseudo-instruction. |
| 137 | +
|
| 138 | + bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver. |
| 139 | +*/ |
| 140 | +struct bpf_insn |
| 141 | +{ |
| 142 | + USHORT code; ///< Instruction type and addressing mode. |
| 143 | + UCHAR jt; ///< Jump if true |
| 144 | + UCHAR jf; ///< Jump if false |
| 145 | + ULONG k; ///< Generic field used for various purposes. |
| 146 | +}; |
| 147 | + |
| 148 | +/*! |
| 149 | + \brief Structure that contains a couple of statistics values on the current capture. |
| 150 | +
|
| 151 | + It is used by packet.dll to return statistics about a capture session. |
| 152 | +*/ |
| 153 | +struct bpf_stat |
| 154 | +{ |
| 155 | + UINT bs_recv; ///< Number of packets that the driver received from the network adapter |
| 156 | + ///< from the beginning of the current capture. This value includes the packets |
| 157 | + ///< lost by the driver. |
| 158 | + UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture. |
| 159 | + ///< Basically, a packet is lost when the the buffer of the driver is full. |
| 160 | + ///< In this situation the packet cannot be stored and the driver rejects it. |
| 161 | + UINT ps_ifdrop; ///< drops by interface. XXX not yet supported |
| 162 | + UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and |
| 163 | + ///< thus reach the application. |
| 164 | +}; |
| 165 | + |
| 166 | +/* Current version number of filter architecture. */ |
| 167 | +#define BPF_MAJOR_VERSION 1 |
| 168 | +#define BPF_MINOR_VERSION 1 |
| 169 | + |
| 170 | +/*! |
| 171 | + \brief Packet header. |
| 172 | +
|
| 173 | + This structure defines the header associated with every packet delivered to the application. |
| 174 | +*/ |
| 175 | +struct bpf_hdr |
| 176 | +{ |
| 177 | + struct timeval bh_tstamp; ///< The timestamp associated with the captured packet. |
| 178 | + ///< It is stored in a TimeVal structure. |
| 179 | + UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b> |
| 180 | + ///< from the original packet, because it is possible (with a proper filter) |
| 181 | + ///< to instruct the driver to capture only a portion of the packets. |
| 182 | + UINT bh_datalen; ///< Original length of packet |
| 183 | + USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases, |
| 184 | + ///< a padding could be added between the end of this structure and the packet |
| 185 | + ///< data for performance reasons. This filed can be used to retrieve the actual data |
| 186 | + ///< of the packet. |
| 187 | +}; |
| 188 | + |
| 189 | +/*! |
| 190 | + \brief Dump packet header. |
| 191 | +
|
| 192 | + This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets(). |
| 193 | + It is simpler than the bpf_hdr, because it corresponds to the header in the pcap-savefile(5) format. |
| 194 | + This makes straightforward sending WinPcap dump files to the network. |
| 195 | +*/ |
| 196 | +struct dump_bpf_hdr |
| 197 | +{ |
| 198 | + struct timeval ts; ///< Time stamp of the packet |
| 199 | + UINT caplen; ///< Length of captured portion. The captured portion can smaller than the |
| 200 | + ///< the original packet, because it is possible (with a proper filter) to |
| 201 | + ///< instruct the driver to capture only a portion of the packets. |
| 202 | + UINT len; ///< Length of the original packet (off wire). |
| 203 | +}; |
| 204 | + |
| 205 | +#endif /* lib_pcap_bpf_h */ |
| 206 | + |
| 207 | +/* BPF extensions */ |
| 208 | +/* Special offsets to mimic Linux kernel's BPF extensions. |
| 209 | + * The names are taken directly from Linux in order to allow libpcap's |
| 210 | + * gencode.c to use the same code for both, but the values are different. |
| 211 | + */ |
| 212 | +/* The base offset for these extensions */ |
| 213 | +#define SKF_AD_OFF (-0x1000) |
| 214 | +/* The extensions are numbered in the order they were added. |
| 215 | + * Since they are treated like offsets, we space them by 4 to avoid the |
| 216 | + * appearance of reading overlapped memory segments. |
| 217 | + * User can issue BIOCGETINFO(NPF_GETINFO_BPFEXT) to retrieve the value of |
| 218 | + * SKF_AD_MAX, and any extension less than or equal to that value will be |
| 219 | + * supported. |
| 220 | + */ |
| 221 | +/* Halfword (2 bytes) representing the 802.1q header. */ |
| 222 | +#define SKF_AD_VLAN_TAG 0 |
| 223 | +/* Boolean: is there VLAN metadata present? Currently, we cannot distinguish VLAN |
| 224 | + * 0 and priority class 0 (both defaults) from the case of no VLAN tag present, |
| 225 | + * so this will return false in that case. */ |
| 226 | +#define SKF_AD_VLAN_TAG_PRESENT 4 |
| 227 | +#define SKF_AD_MAX 4 |
| 228 | + |
| 229 | +#endif /* NPCAP_BPF_H */ |
0 commit comments