Packet32.h.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. Packet32.h
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='nvram.h.html' title=' nvram.h '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pcap-bpf.h.html' title=' pcap-bpf.h '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*
  22. * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
  23. * Copyright (c) 2005 - 2007 CACE Technologies, Davis (California)
  24. * All rights reserved.
  25. *
  26. * Redistribution and use in source and binary forms, with or without
  27. * modification, are permitted provided that the following conditions
  28. * are met:
  29. *
  30. * 1. Redistributions of source code must retain the above copyright
  31. * notice, this list of conditions and the following disclaimer.
  32. * 2. Redistributions in binary form must reproduce the above copyright
  33. * notice, this list of conditions and the following disclaimer in the
  34. * documentation and/or other materials provided with the distribution.
  35. * 3. Neither the name of the Politecnico di Torino, CACE Technologies
  36. * nor the names of its contributors may be used to endorse or promote
  37. * products derived from this software without specific prior written
  38. * permission.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  41. * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  42. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  43. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  44. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  45. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  46. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  47. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  48. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  49. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  50. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  51. *
  52. */
  53. /** @ingroup packetapi
  54. * @{
  55. */
  56. /** @defgroup packet32h Packet.dll definitions and data structures
  57. * Packet32.h contains the data structures and the definitions used by packet.dll.
  58. * The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
  59. * by the applications that use the functions of this library
  60. * @{
  61. */
  62. #ifndef __PACKET32
  63. #define __PACKET32
  64. #include &lt;winsock2.h&gt;
  65. #ifdef HAVE_AIRPCAP_API
  66. #include &lt;airpcap.h&gt;
  67. #else
  68. #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
  69. #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
  70. typedef struct _AirpcapHandle *PAirpcapHandle;
  71. #endif /* AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ */
  72. #endif /* HAVE_AIRPCAP_API */
  73. #ifdef HAVE_DAG_API
  74. #include &lt;dagc.h&gt;
  75. #endif /* HAVE_DAG_API */
  76. // Working modes
  77. #define PACKET_MODE_CAPT 0x0 ///&lt; Capture mode
  78. #define PACKET_MODE_STAT 0x1 ///&lt; Statistical mode
  79. #define PACKET_MODE_MON 0x2 ///&lt; Monitoring mode
  80. #define PACKET_MODE_DUMP 0x10 ///&lt; Dump mode
  81. #define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///&lt; Statistical dump Mode
  82. /// Alignment macro. Defines the alignment size.
  83. #define Packet_ALIGNMENT sizeof(int)
  84. /// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
  85. #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&amp;~(Packet_ALIGNMENT-1))
  86. #define NdisMediumNull -1 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  87. #define NdisMediumCHDLC -2 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  88. #define NdisMediumPPPSerial -3 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  89. #define NdisMediumBare80211 -4 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  90. #define NdisMediumRadio80211 -5 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  91. #define NdisMediumPpi -6 ///&lt; Custom linktype: NDIS doesn't provide an equivalent
  92. // Loopback behaviour definitions
  93. #define NPF_DISABLE_LOOPBACK 1 ///&lt; Drop the packets sent by the NPF driver
  94. #define NPF_ENABLE_LOOPBACK 2 ///&lt; Capture the packets sent by the NPF driver
  95. /*!
  96. \brief Network type structure.
  97. This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
  98. */
  99. typedef struct NetType
  100. {
  101. UINT LinkType; ///&lt; The MAC of the current network adapter (see function PacketGetNetType() for more information)
  102. ULONGLONG LinkSpeed; ///&lt; The speed of the network in bits per second
  103. }NetType;
  104. //some definitions stolen from libpcap
  105. #ifndef BPF_MAJOR_VERSION
  106. /*!
  107. \brief A BPF pseudo-assembly program.
  108. The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
  109. */
  110. struct bpf_program
  111. {
  112. UINT bf_len; ///&lt; Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
  113. struct bpf_insn *bf_insns; ///&lt; A pointer to the first instruction of the program.
  114. };
  115. /*!
  116. \brief A single BPF pseudo-instruction.
  117. bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
  118. */
  119. struct bpf_insn
  120. {
  121. USHORT code; ///&lt; Instruction type and addressing mode.
  122. UCHAR jt; ///&lt; Jump if true
  123. UCHAR jf; ///&lt; Jump if false
  124. int k; ///&lt; Generic field used for various purposes.
  125. };
  126. /*!
  127. \brief Structure that contains a couple of statistics values on the current capture.
  128. It is used by packet.dll to return statistics about a capture session.
  129. */
  130. struct bpf_stat
  131. {
  132. UINT bs_recv; ///&lt; Number of packets that the driver received from the network adapter
  133. ///&lt; from the beginning of the current capture. This value includes the packets
  134. ///&lt; lost by the driver.
  135. UINT bs_drop; ///&lt; number of packets that the driver lost from the beginning of a capture.
  136. ///&lt; Basically, a packet is lost when the the buffer of the driver is full.
  137. ///&lt; In this situation the packet cannot be stored and the driver rejects it.
  138. UINT ps_ifdrop; ///&lt; drops by interface. XXX not yet supported
  139. UINT bs_capt; ///&lt; number of packets that pass the filter, find place in the kernel buffer and
  140. ///&lt; thus reach the application.
  141. };
  142. /*!
  143. \brief Packet header.
  144. This structure defines the header associated with every packet delivered to the application.
  145. */
  146. struct bpf_hdr
  147. {
  148. struct timeval bh_tstamp; ///&lt; The timestamp associated with the captured packet.
  149. ///&lt; It is stored in a TimeVal structure.
  150. UINT bh_caplen; ///&lt; Length of captured portion. The captured portion &lt;b&gt;can be different&lt;/b&gt;
  151. ///&lt; from the original packet, because it is possible (with a proper filter)
  152. ///&lt; to instruct the driver to capture only a portion of the packets.
  153. UINT bh_datalen; ///&lt; Original length of packet
  154. USHORT bh_hdrlen; ///&lt; Length of bpf header (this struct plus alignment padding). In some cases,
  155. ///&lt; a padding could be added between the end of this structure and the packet
  156. ///&lt; data for performance reasons. This filed can be used to retrieve the actual data
  157. ///&lt; of the packet.
  158. };
  159. /*!
  160. \brief Dump packet header.
  161. This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
  162. It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
  163. packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
  164. */
  165. struct dump_bpf_hdr{
  166. struct timeval ts; ///&lt; Time stamp of the packet
  167. UINT caplen; ///&lt; Length of captured portion. The captured portion can smaller than the
  168. ///&lt; the original packet, because it is possible (with a proper filter) to
  169. ///&lt; instruct the driver to capture only a portion of the packets.
  170. UINT len; ///&lt; Length of the original packet (off wire).
  171. };
  172. #endif
  173. struct bpf_stat;
  174. #define DOSNAMEPREFIX TEXT(&quot;Packet_&quot;) ///&lt; Prefix added to the adapters device names to create the WinPcap devices
  175. #define MAX_LINK_NAME_LENGTH 64 //&lt; Maximum length of the devices symbolic links
  176. #define NMAX_PACKET 65535
  177. /*!
  178. \brief Addresses of a network adapter.
  179. This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
  180. an adapter.
  181. */
  182. typedef struct npf_if_addr {
  183. struct sockaddr_storage IPAddress; ///&lt; IP address.
  184. struct sockaddr_storage SubnetMask; ///&lt; Netmask for that address.
  185. struct sockaddr_storage Broadcast; ///&lt; Broadcast address.
  186. }npf_if_addr;
  187. #define ADAPTER_NAME_LENGTH 256 + 12 ///&lt; Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
  188. #define ADAPTER_DESC_LENGTH 128 ///&lt; Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
  189. #define MAX_MAC_ADDR_LENGTH 8 ///&lt; Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
  190. #define MAX_NETWORK_ADDRESSES 16 ///&lt; Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
  191. typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///&lt; Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
  192. typedef WAN_ADAPTER *PWAN_ADAPTER; ///&lt; Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
  193. #define INFO_FLAG_NDIS_ADAPTER 0 ///&lt; Flag for ADAPTER_INFO: this is a traditional ndis adapter
  194. #define INFO_FLAG_NDISWAN_ADAPTER 1 ///&lt; Flag for ADAPTER_INFO: this is a NdisWan adapter, and it's managed by WANPACKET
  195. #define INFO_FLAG_DAG_CARD 2 ///&lt; Flag for ADAPTER_INFO: this is a DAG card
  196. #define INFO_FLAG_DAG_FILE 6 ///&lt; Flag for ADAPTER_INFO: this is a DAG file
  197. #define INFO_FLAG_DONT_EXPORT 8 ///&lt; Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
  198. #define INFO_FLAG_AIRPCAP_CARD 16 ///&lt; Flag for ADAPTER_INFO: this is an airpcap card
  199. #define INFO_FLAG_NPFIM_DEVICE 32
  200. /*!
  201. \brief Describes an opened network adapter.
  202. This structure is the most important for the functioning of packet.dll, but the great part of its fields
  203. should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
  204. */
  205. typedef struct _ADAPTER {
  206. HANDLE hFile; ///&lt; \internal Handle to an open instance of the NPF driver.
  207. CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///&lt; \internal A string containing the name of the network adapter currently opened.
  208. int NumWrites; ///&lt; \internal Number of times a packets written on this adapter will be repeated
  209. ///&lt; on the wire.
  210. HANDLE ReadEvent; ///&lt; A notification event associated with the read calls on the adapter.
  211. ///&lt; It can be passed to standard Win32 functions (like WaitForSingleObject
  212. ///&lt; or WaitForMultipleObjects) to wait until the driver's buffer contains some
  213. ///&lt; data. It is particularly useful in GUI applications that need to wait
  214. ///&lt; concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
  215. ///&lt; function can be used to define the minimum amount of data in the kernel buffer
  216. ///&lt; that will cause the event to be signalled.
  217. UINT ReadTimeOut; ///&lt; \internal The amount of time after which a read on the driver will be released and
  218. ///&lt; ReadEvent will be signaled, also if no packets were captured
  219. CHAR Name[ADAPTER_NAME_LENGTH];
  220. PWAN_ADAPTER pWanAdapter;
  221. UINT Flags; ///&lt; Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
  222. #ifdef HAVE_AIRPCAP_API
  223. PAirpcapHandle AirpcapAd;
  224. #endif // HAVE_AIRPCAP_API
  225. #ifdef HAVE_NPFIM_API
  226. void* NpfImHandle;
  227. #endif // HAVE_NPFIM_API
  228. #ifdef HAVE_DAG_API
  229. dagc_t *pDagCard; ///&lt; Pointer to the dagc API adapter descriptor for this adapter
  230. PCHAR DagBuffer; ///&lt; Pointer to the buffer with the packets that is received from the DAG card
  231. struct timeval DagReadTimeout; ///&lt; Read timeout. The dagc API requires a timeval structure
  232. unsigned DagFcsLen; ///&lt; Length of the frame check sequence attached to any packet by the card. Obtained from the registry
  233. DWORD DagFastProcess; ///&lt; True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
  234. #endif // HAVE_DAG_API
  235. } ADAPTER, *LPADAPTER;
  236. /*!
  237. \brief Structure that contains a group of packets coming from the driver.
  238. This structure defines the header associated with every packet delivered to the application.
  239. */
  240. typedef struct _PACKET {
  241. HANDLE hEvent; ///&lt; \deprecated Still present for compatibility with old applications.
  242. OVERLAPPED OverLapped; ///&lt; \deprecated Still present for compatibility with old applications.
  243. PVOID Buffer; ///&lt; Buffer with containing the packets. See the PacketReceivePacket() for
  244. ///&lt; details about the organization of the data in this buffer
  245. UINT Length; ///&lt; Length of the buffer
  246. DWORD ulBytesReceived; ///&lt; Number of valid bytes present in the buffer, i.e. amount of data
  247. ///&lt; received by the last call to PacketReceivePacket()
  248. BOOLEAN bIoComplete; ///&lt; \deprecated Still present for compatibility with old applications.
  249. } PACKET, *LPPACKET;
  250. /*!
  251. \brief Structure containing an OID request.
  252. It is used by the PacketRequest() function to send an OID to the interface card driver.
  253. It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
  254. the list of the multicast groups defined on it, and so on.
  255. */
  256. struct _PACKET_OID_DATA {
  257. ULONG Oid; ///&lt; OID code. See the Microsoft DDK documentation or the file ntddndis.h
  258. ///&lt; for a complete list of valid codes.
  259. ULONG Length; ///&lt; Length of the data field
  260. UCHAR Data[1]; ///&lt; variable-lenght field that contains the information passed to or received
  261. ///&lt; from the adapter.
  262. };
  263. typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
  264. #ifdef __cplusplus
  265. extern &quot;C&quot; {
  266. #endif
  267. /**
  268. * @}
  269. */
  270. /*
  271. BOOLEAN QueryWinPcapRegistryStringA(CHAR *SubKeyName,
  272. CHAR *Value,
  273. UINT *pValueLen,
  274. CHAR *DefaultVal);
  275. BOOLEAN QueryWinPcapRegistryStringW(WCHAR *SubKeyName,
  276. WCHAR *Value,
  277. UINT *pValueLen,
  278. WCHAR *DefaultVal);
  279. */
  280. //---------------------------------------------------------------------------
  281. // EXPORTED FUNCTIONS
  282. //---------------------------------------------------------------------------
  283. PCHAR PacketGetVersion();
  284. PCHAR PacketGetDriverVersion();
  285. BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
  286. BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
  287. BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
  288. BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
  289. BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
  290. BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior);
  291. INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
  292. BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
  293. BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
  294. BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
  295. BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
  296. LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
  297. BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
  298. INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
  299. LPPACKET PacketAllocatePacket(void);
  300. VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
  301. VOID PacketFreePacket(LPPACKET lpPacket);
  302. BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
  303. BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
  304. BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
  305. BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
  306. BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
  307. HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
  308. BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
  309. BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
  310. BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
  311. BOOL PacketStopDriver();
  312. VOID PacketCloseAdapter(LPADAPTER lpAdapter);
  313. BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength);
  314. BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags);
  315. PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject);
  316. //
  317. // Used by PacketStartOemEx
  318. //
  319. #define PACKET_START_OEM_NO_NETMON 0x00000001
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif //__PACKET32
  324. </pre>
  325. <div class='footerlink'>
  326. [<a href='nvram.h.html' title=' nvram.h '>PREV</a>]
  327. [<a href='toolkit.html' title=' Index '>HOME</a>]
  328. [<a href='pcap-bpf.h.html' title=' pcap-bpf.h '>NEXT</a>]
  329. </div>
  330. </body>
  331. </html>