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;
226  CHAR SymbolicLink[MAX_LINK_NAME_LENGTH];
227  int NumWrites;
228  HANDLE ReadEvent;
230 
237  UINT ReadTimeOut;
238  CHAR Name[ADAPTER_NAME_LENGTH];
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);
332 LPPACKET PacketAllocatePacket(void);
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);
348 PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject);
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
PCHAR PacketGetDriverVersion()
struct _ADAPTER ADAPTER
Describes an opened network adapter.
A single BPF pseudo-instruction.
Definition: Packet32.h:119
Describes an opened network adapter.
Definition: Packet32.h:224
Structure that contains a couple of statistics values on the current capture.
Definition: Packet32.h:132
VOID PacketFreePacket(LPPACKET lpPacket)
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len)
USHORT code
Instruction type and addressing mode.
Definition: Packet32.h:121
ULONG Oid
for a complete list of valid codes.
Definition: Packet32.h:284
Addresses of a network adapter.
Definition: Packet32.h:194
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject, ULONG Filter)
BOOLEAN PacketGetStats(LPADAPTER AdapterObject, struct bpf_stat *s)
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject, int timeout)
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject, int dim)
INT PacketSendPackets(LPADAPTER AdapterObject, PVOID PacketBuff, ULONG Size, BOOLEAN Sync)
int NumWrites
on the wire.
Definition: Packet32.h:227
Structure that contains a group of packets coming from the driver.
Definition: Packet32.h:265
UCHAR jf
Jump if false.
Definition: Packet32.h:123
WAN_ADAPTER * PWAN_ADAPTER
Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
Definition: Packet32.h:208
OVERLAPPED OverLapped
Definition: Packet32.h:267
PCHAR PacketGetVersion()
UINT Flags
Adapter&#39;s flags. Tell if this adapter must be treated in a different way, using the Netmon API or the...
Definition: Packet32.h:241
BOOLEAN PacketSetMode(LPADAPTER AdapterObject, int mode)
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject, struct bpf_program *fp)
DWORD ulBytesReceived
received by the last call to PacketReceivePacket()
Definition: Packet32.h:271
UINT caplen
Definition: Packet32.h:173
#define MAX_LINK_NAME_LENGTH
Definition: Packet32.h:185
BOOL PacketStopDriver()
BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags)
A BPF pseudo-assembly program.
Definition: Packet32.h:108
struct _PACKET_OID_DATA * PPACKET_OID_DATA
Definition: Packet32.h:290
Structure containing an OID request.
Definition: Packet32.h:283
VOID PacketCloseAdapter(LPADAPTER lpAdapter)
LPPACKET PacketAllocatePacket(void)
struct _AirpcapHandle * PAirpcapHandle
Definition: Packet32.h:55
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
#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
UINT ReadTimeOut
ReadEvent will be signaled, also if no packets were captured.
Definition: Packet32.h:237
LPADAPTER PacketOpenAdapter(PCHAR AdapterName)
struct _ADAPTER * LPADAPTER
struct npf_if_addr npf_if_addr
Addresses of a network adapter.
BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength)
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject, int nbytes)
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject, int nwrites)
HANDLE hFile
Definition: Packet32.h:225
struct bpf_insn * bf_insns
A pointer to the first instruction of the program.
Definition: Packet32.h:111
struct NetType NetType
Network type structure.
BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior)
BOOLEAN PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize)
BOOLEAN PacketRequest(LPADAPTER AdapterObject, BOOLEAN Set, PPACKET_OID_DATA OidData)
PWAN_ADAPTER pWanAdapter
Definition: Packet32.h:240
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject, LPPACKET pPacket, BOOLEAN Sync)
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync)
Network type structure.
Definition: Packet32.h:92
INT PacketSetSnapLen(LPADAPTER AdapterObject, int snaplen)
struct _PACKET * LPPACKET
UCHAR jt
Jump if true.
Definition: Packet32.h:122
Dump packet header.
Definition: Packet32.h:171
struct WAN_ADAPTER_INT WAN_ADAPTER
Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
Definition: Packet32.h:207
UINT bs_capt
thus reach the application.
Definition: Packet32.h:141
PVOID Buffer
details about the organization of the data in this buffer
Definition: Packet32.h:268
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject)
UINT bs_recv
Definition: Packet32.h:134
VOID PacketInitPacket(LPPACKET lpPacket, PVOID Buffer, UINT Length)
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr *buffer, PLONG NEntries)
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks)
Packet header.
Definition: Packet32.h:150
USHORT bh_hdrlen
Definition: Packet32.h:158
HANDLE hEvent
Definition: Packet32.h:266
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject, struct bpf_stat *s)
struct _PACKET PACKET
Structure that contains a group of packets coming from the driver.
int mode
Definition: aliastool.c:48
BOOLEAN PacketGetNetType(LPADAPTER AdapterObject, NetType *type)
UINT LinkType
The MAC of the current network adapter (see function PacketGetNetType() for more information) ...
Definition: Packet32.h:94
int k
Generic field used for various purposes.
Definition: Packet32.h:124
ULONG Length
Length of the data field.
Definition: Packet32.h:286
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
ULONGLONG LinkSpeed
The speed of the network in bits per second.
Definition: Packet32.h:95
PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject)


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Sat Jun 27 2020 03:48:21