Packet32.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
3  * Copyright (c) 2005 - 2007 CACE Technologies, Davis (California)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16  * nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written
18  * permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
45 #ifndef __PACKET32
46 #define __PACKET32
47 
48 #include <winsock2.h>
49 
50 #ifdef HAVE_AIRPCAP_API
51 #include <airpcap.h>
52 #else
53 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
54 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
55 typedef struct _AirpcapHandle *PAirpcapHandle;
56 #endif /* AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ */
57 #endif /* HAVE_AIRPCAP_API */
58 
59 #ifdef HAVE_DAG_API
60 #include <dagc.h>
61 #endif /* HAVE_DAG_API */
62 
63 // Working modes
64 #define PACKET_MODE_CAPT 0x0
65 #define PACKET_MODE_STAT 0x1
66 #define PACKET_MODE_MON 0x2
67 #define PACKET_MODE_DUMP 0x10
68 #define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT
69 
70 
72 #define Packet_ALIGNMENT sizeof(int)
73 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
75 
76 #define NdisMediumNull -1
77 #define NdisMediumCHDLC -2
78 #define NdisMediumPPPSerial -3
79 #define NdisMediumBare80211 -4
80 #define NdisMediumRadio80211 -5
81 #define NdisMediumPpi -6
82 
83 // Loopback behaviour definitions
84 #define NPF_DISABLE_LOOPBACK 1
85 #define NPF_ENABLE_LOOPBACK 2
86 
87 
92 typedef struct NetType
93 {
94  UINT LinkType;
95  ULONGLONG LinkSpeed;
96 }NetType;
97 
98 
99 //some definitions stolen from libpcap
100 
101 #ifndef BPF_MAJOR_VERSION
102 
109 {
110  UINT bf_len;
111  struct bpf_insn *bf_insns;
112 };
113 
119 struct bpf_insn
120 {
121  USHORT code;
122  UCHAR jt;
123  UCHAR jf;
124  int k;
125 };
126 
132 struct bpf_stat
133 {
134  UINT bs_recv;
135  UINT bs_drop;
138  UINT ps_ifdrop;
141  UINT bs_capt;
142 };
144 
150 struct bpf_hdr
151 {
152  struct timeval bh_tstamp;
153  UINT bh_caplen;
155  UINT bh_datalen;
158  USHORT bh_hdrlen;
159 };
163 
172  struct timeval ts;
173  UINT caplen;
174  UINT len;
177 };
178 
179 
180 #endif
181 
182 struct bpf_stat;
183 
184 #define DOSNAMEPREFIX TEXT("Packet_")
185 #define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
186 #define NMAX_PACKET 65535
187 
194 typedef struct npf_if_addr {
195  struct sockaddr_storage IPAddress;
196  struct sockaddr_storage SubnetMask;
197  struct sockaddr_storage Broadcast;
198 }npf_if_addr;
199 
200 
201 #define ADAPTER_NAME_LENGTH 256 + 12
202 #define ADAPTER_DESC_LENGTH 128
203 #define MAX_MAC_ADDR_LENGTH 8
204 #define MAX_NETWORK_ADDRESSES 16
205 
206 
207 typedef struct WAN_ADAPTER_INT WAN_ADAPTER;
209 
210 #define INFO_FLAG_NDIS_ADAPTER 0
211 #define INFO_FLAG_NDISWAN_ADAPTER 1
212 #define INFO_FLAG_DAG_CARD 2
213 #define INFO_FLAG_DAG_FILE 6
214 #define INFO_FLAG_DONT_EXPORT 8
215 #define INFO_FLAG_AIRPCAP_CARD 16
216 #define INFO_FLAG_NPFIM_DEVICE 32
217 
224 typedef struct _ADAPTER {
225  HANDLE hFile;
227  int NumWrites;
228  HANDLE ReadEvent;
230 
237  UINT ReadTimeOut;
241  UINT Flags;
242 
243 #ifdef HAVE_AIRPCAP_API
244  PAirpcapHandle AirpcapAd;
245 #endif // HAVE_AIRPCAP_API
246 
247 #ifdef HAVE_NPFIM_API
248  void* NpfImHandle;
249 #endif // HAVE_NPFIM_API
250 
251 #ifdef HAVE_DAG_API
252  dagc_t *pDagCard;
253  PCHAR DagBuffer;
254  struct timeval DagReadTimeout;
255  unsigned DagFcsLen;
256  DWORD DagFastProcess;
257 #endif // HAVE_DAG_API
258 } ADAPTER, *LPADAPTER;
259 
265 typedef struct _PACKET {
266  HANDLE hEvent;
267  OVERLAPPED OverLapped;
268  PVOID Buffer;
269  UINT Length;
272  BOOLEAN bIoComplete;
274 } PACKET, *LPPACKET;
275 
284  ULONG Oid;
285  ULONG Length;
287  UCHAR Data[1];
288 };
291 
292 #ifdef __cplusplus
293 extern "C" {
294 #endif
295 
300 /*
301 BOOLEAN QueryWinPcapRegistryStringA(CHAR *SubKeyName,
302  CHAR *Value,
303  UINT *pValueLen,
304  CHAR *DefaultVal);
305 
306 BOOLEAN QueryWinPcapRegistryStringW(WCHAR *SubKeyName,
307  WCHAR *Value,
308  UINT *pValueLen,
309  WCHAR *DefaultVal);
310 */
311 
312 //---------------------------------------------------------------------------
313 // EXPORTED FUNCTIONS
314 //---------------------------------------------------------------------------
315 
316 PCHAR PacketGetVersion();
317 PCHAR PacketGetDriverVersion();
318 BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
319 BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
320 BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
321 BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
322 BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
323 BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior);
324 INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
325 BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
326 BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
327 BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
328 BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
329 LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
330 BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
331 INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
333 VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
334 VOID PacketFreePacket(LPPACKET lpPacket);
335 BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
336 BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
337 BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
338 BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
339 BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
340 HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
341 BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
342 BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
343 BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
344 BOOL PacketStopDriver();
345 VOID PacketCloseAdapter(LPADAPTER lpAdapter);
346 BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength);
347 BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags);
349 
350 //
351 // Used by PacketStartOemEx
352 //
353 #define PACKET_START_OEM_NO_NETMON 0x00000001
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 
359 #endif //__PACKET32
bpf_program::bf_insns
struct bpf_insn * bf_insns
A pointer to the first instruction of the program.
Definition: Packet32.h:111
PacketSetReadTimeout
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject, int timeout)
LPPACKET
struct _PACKET * LPPACKET
NetType::LinkSpeed
ULONGLONG LinkSpeed
The speed of the network in bits per second.
Definition: Packet32.h:95
PacketSendPackets
INT PacketSendPackets(LPADAPTER AdapterObject, PVOID PacketBuff, ULONG Size, BOOLEAN Sync)
PacketGetNetInfoEx
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr *buffer, PLONG NEntries)
bpf_insn::jt
UCHAR jt
Jump if true.
Definition: Packet32.h:122
_PACKET::bIoComplete
BOOLEAN bIoComplete
Definition: Packet32.h:273
_PACKET
Structure that contains a group of packets coming from the driver.
Definition: Packet32.h:265
PWAN_ADAPTER
WAN_ADAPTER * PWAN_ADAPTER
Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
Definition: Packet32.h:208
_PACKET::OverLapped
OVERLAPPED OverLapped
Definition: Packet32.h:267
PacketReceivePacket
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
bpf_stat::bs_recv
UINT bs_recv
Definition: Packet32.h:134
_PACKET_OID_DATA
Structure containing an OID request.
Definition: Packet32.h:283
_PACKET::Length
UINT Length
Length of the buffer.
Definition: Packet32.h:270
_PACKET_OID_DATA::Oid
ULONG Oid
for a complete list of valid codes.
Definition: Packet32.h:284
_PACKET_OID_DATA::Length
ULONG Length
Length of the data field.
Definition: Packet32.h:286
_ADAPTER
Describes an opened network adapter.
Definition: Packet32.h:224
MAX_LINK_NAME_LENGTH
#define MAX_LINK_NAME_LENGTH
Definition: Packet32.h:185
PacketAllocatePacket
LPPACKET PacketAllocatePacket(void)
bpf_hdr::bh_hdrlen
USHORT bh_hdrlen
Definition: Packet32.h:158
PacketGetNetType
BOOLEAN PacketGetNetType(LPADAPTER AdapterObject, NetType *type)
_PACKET::ulBytesReceived
DWORD ulBytesReceived
received by the last call to PacketReceivePacket()
Definition: Packet32.h:271
_PACKET::hEvent
HANDLE hEvent
Definition: Packet32.h:266
_ADAPTER::Name
CHAR Name[ADAPTER_NAME_LENGTH]
Definition: Packet32.h:239
bpf_hdr::bh_caplen
UINT bh_caplen
Definition: Packet32.h:154
bpf_hdr::bh_datalen
UINT bh_datalen
Original length of packet.
Definition: Packet32.h:157
PacketSetMode
BOOLEAN PacketSetMode(LPADAPTER AdapterObject, int mode)
PacketStartOemEx
BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags)
PAirpcapHandle
struct _AirpcapHandle * PAirpcapHandle
Definition: Packet32.h:55
PacketSetHwFilter
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject, ULONG Filter)
bpf_insn::k
int k
Generic field used for various purposes.
Definition: Packet32.h:124
NetType
Network type structure.
Definition: Packet32.h:92
_ADAPTER::hFile
HANDLE hFile
Definition: Packet32.h:225
bpf_insn
A single BPF pseudo-instruction.
Definition: Packet32.h:119
PacketGetDriverVersion
PCHAR PacketGetDriverVersion()
npf_if_addr::IPAddress
struct sockaddr_storage IPAddress
IP address.
Definition: Packet32.h:195
bpf_insn::jf
UCHAR jf
Jump if false.
Definition: Packet32.h:123
NetType
struct NetType NetType
Network type structure.
_ADAPTER::ReadTimeOut
UINT ReadTimeOut
ReadEvent will be signaled, also if no packets were captured.
Definition: Packet32.h:237
mode
int mode
Definition: aliastool.c:48
_ADAPTER::NumWrites
int NumWrites
on the wire.
Definition: Packet32.h:227
_PACKET::Buffer
PVOID Buffer
details about the organization of the data in this buffer
Definition: Packet32.h:268
PacketSetDumpName
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len)
PacketGetReadEvent
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject)
PacketIsDumpEnded
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync)
bpf_stat::bs_drop
UINT bs_drop
Definition: Packet32.h:137
dump_bpf_hdr::len
UINT len
Length of the original packet (off wire).
Definition: Packet32.h:176
PacketOpenAdapter
LPADAPTER PacketOpenAdapter(PCHAR AdapterName)
npf_if_addr
Addresses of a network adapter.
Definition: Packet32.h:194
npf_if_addr::Broadcast
struct sockaddr_storage Broadcast
Broadcast address.
Definition: Packet32.h:197
PacketSetBpf
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject, struct bpf_program *fp)
PacketGetStats
BOOLEAN PacketGetStats(LPADAPTER AdapterObject, struct bpf_stat *s)
PacketSetBuff
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject, int dim)
ADAPTER
struct _ADAPTER ADAPTER
Describes an opened network adapter.
PacketStopDriver
BOOL PacketStopDriver()
bpf_program::bf_len
UINT bf_len
Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will fol...
Definition: Packet32.h:110
PacketSetNumWrites
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject, int nwrites)
bpf_stat
Structure that contains a couple of statistics values on the current capture.
Definition: Packet32.h:132
_ADAPTER::Flags
UINT Flags
Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the...
Definition: Packet32.h:241
npf_if_addr::SubnetMask
struct sockaddr_storage SubnetMask
Netmask for that address.
Definition: Packet32.h:196
bpf_stat::ps_ifdrop
UINT ps_ifdrop
drops by interface. XXX not yet supported
Definition: Packet32.h:140
dump_bpf_hdr::caplen
UINT caplen
Definition: Packet32.h:173
PacketSetMinToCopy
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject, int nbytes)
PacketInitPacket
VOID PacketInitPacket(LPPACKET lpPacket, PVOID Buffer, UINT Length)
PacketRequest
BOOLEAN PacketRequest(LPADAPTER AdapterObject, BOOLEAN Set, PPACKET_OID_DATA OidData)
WAN_ADAPTER
struct WAN_ADAPTER_INT WAN_ADAPTER
Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
Definition: Packet32.h:207
PPACKET_OID_DATA
struct _PACKET_OID_DATA * PPACKET_OID_DATA
Definition: Packet32.h:290
npf_if_addr
struct npf_if_addr npf_if_addr
Addresses of a network adapter.
PacketStartOem
BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength)
_ADAPTER::ReadEvent
HANDLE ReadEvent
Definition: Packet32.h:229
NetType::LinkType
UINT LinkType
The MAC of the current network adapter (see function PacketGetNetType() for more information)
Definition: Packet32.h:94
PacketSetLoopbackBehavior
BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior)
PACKET
struct _PACKET PACKET
Structure that contains a group of packets coming from the driver.
PacketSetSnapLen
INT PacketSetSnapLen(LPADAPTER AdapterObject, int snaplen)
bpf_hdr::bh_tstamp
struct timeval bh_tstamp
It is stored in a TimeVal structure.
Definition: Packet32.h:152
bpf_stat::bs_capt
UINT bs_capt
thus reach the application.
Definition: Packet32.h:141
PacketSetDumpLimits
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks)
bpf_program
A BPF pseudo-assembly program.
Definition: Packet32.h:108
_ADAPTER::SymbolicLink
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]
Definition: Packet32.h:226
bpf_hdr
Packet header.
Definition: Packet32.h:150
bpf_insn::code
USHORT code
Instruction type and addressing mode.
Definition: Packet32.h:121
LPADAPTER
struct _ADAPTER * LPADAPTER
dump_bpf_hdr::ts
struct timeval ts
Time stamp of the packet.
Definition: Packet32.h:172
_ADAPTER::pWanAdapter
PWAN_ADAPTER pWanAdapter
Definition: Packet32.h:240
PacketSendPacket
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject, LPPACKET pPacket, BOOLEAN Sync)
PacketGetAdapterNames
BOOLEAN PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize)
PacketCloseAdapter
VOID PacketCloseAdapter(LPADAPTER lpAdapter)
ADAPTER_NAME_LENGTH
#define ADAPTER_NAME_LENGTH
Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
Definition: Packet32.h:201
_PACKET_OID_DATA::Data
UCHAR Data[1]
from the adapter.
Definition: Packet32.h:287
dump_bpf_hdr
Dump packet header.
Definition: Packet32.h:171
PacketGetStatsEx
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject, struct bpf_stat *s)
PacketFreePacket
VOID PacketFreePacket(LPPACKET lpPacket)
PacketGetVersion
PCHAR PacketGetVersion()
PacketGetAirPcapHandle
PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject)


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Wed Mar 2 2022 01:01:49