Main Page Modules Data Structures File List Data Fields Globals Related Pages

# Packet32.h File Reference

`#include <winsock2.h>`
`#include "devioctl.h"`

Go to the source code of this file.

## Data Structures
struct | _ADAPTER
| Describes an opened network adapter. More...
struct | _ADAPTER_INFO
| Contains comprehensive information about a network adapter. More...
struct | _PACKET
| Structure that contains a group of packets coming from the driver. More...
struct | _PACKET_OID_DATA
| Structure containing an OID request. More...
struct | bpf_hdr
| Packet header. More...
struct | bpf_insn
| A single BPF pseudo-instruction. More...
struct | bpf_program
| A BPF pseudo-assembly program. More...
struct | bpf_stat
| Structure that contains a couple of statistics values on the current capture. More...
struct | dump_bpf_hdr
| Dump packet header. More...
struct | NetType
| Network type structure. More...
struct | npf_if_addr
| Addresses of a network adapter. More...
## Defines
#define | PACKET_MODE_CAPT 0x0
| Capture mode.
#define | PACKET_MODE_STAT 0x1
| Statistical mode.
#define | PACKET_MODE_MON 0x2
| Monitoring mode.
#define | PACKET_MODE_DUMP 0x10
| Dump mode.
#define | PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT
| Statistical dump Mode.
#define | FILE_DEVICE_PROTOCOL 0x8000
#define | IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define | pBIOCSETBUFFERSIZE 9592
| IOCTL code: set kernel buffer size.
#define | pBIOCSETF 9030
| IOCTL code: set packet filtering program.
#define | pBIOCGSTATS 9031
| IOCTL code: get the capture stats.
#define | pBIOCSRTIMEOUT 7416
| IOCTL code: set the read timeout.
#define | pBIOCSMODE 7412
| IOCTL code: set working mode.
#define | pBIOCSWRITEREP 7413
| IOCTL code: set number of physical repetions of every packet written by the app.
#define | pBIOCSMINTOCOPY 7414
| IOCTL code: set minimum amount of data in the kernel buffer that unlocks a read call.
#define | pBIOCSETOID 2147483648
| IOCTL code: set an OID value.
#define | pBIOCQUERYOID 2147483652
| IOCTL code: get an OID value.
#define | pATTACHPROCESS 7117
| IOCTL code: attach a process to the driver. Used in Win9x only.
#define | pDETACHPROCESS 7118
| IOCTL code: detach a process from the driver. Used in Win9x only.
#define | pBIOCSETDUMPFILENAME 9029
| IOCTL code: set the name of a the file used by kernel dump mode.
#define | pBIOCEVNAME 7415
| IOCTL code: get the name of the event that the driver signals when some data is present in the buffer.
#define | pBIOCSENDPACKETSNOSYNC 9032
| IOCTL code: Send a buffer containing multiple packets to the network, ignoring the timestamps associated with the packets.
#define | pBIOCSENDPACKETSSYNC 9033
| IOCTL code: Send a buffer containing multiple packets to the network, respecting the timestamps associated with the packets.
#define | pBIOCSETDUMPLIMITS 9034
| IOCTL code: Set the dump file limits. See the PacketSetDumpLimits() function.
#define | pBIOCISDUMPENDED 7411
| IOCTL code: Get the status of the kernel dump process. See the PacketIsDumpEnded() function.
#define | pBIOCSTIMEZONE 7471
| IOCTL code: set time zone. Used in Win9x only.
#define | Packet_ALIGNMENT sizeof(int)
| Alignment macro. Defines the alignment size.
#define | Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
| Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
#define | NdisMediumNull -1
#define | NdisMediumCHDLC -2
#define | NdisMediumPPPSerial -3
#define | DOSNAMEPREFIX TEXT("Packet_")
| Prefix added to the adapters device names to create the WinPcap devices.
#define | MAX_LINK_NAME_LENGTH 64
#define | NMAX_PACKET 65535
#define | ADAPTER_NAME_LENGTH 256 + 12
| Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
#define | ADAPTER_DESC_LENGTH 128
| Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
#define | MAX_MAC_ADDR_LENGTH 8
| Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define | MAX_NETWORK_ADDRESSES 16
| Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define | INFO_FLAG_NDIS_ADAPTER 0
| Flag for ADAPTER_INFO: this is a traditional ndis adapter.
#define | INFO_FLAG_NDISWAN_ADAPTER 1
| Flag for ADAPTER_INFO: this is a NdisWan adapter.
#define | INFO_FLAG_DAG_CARD 2
| Flag for ADAPTER_INFO: this is a DAG card.
#define | INFO_FLAG_DAG_FILE 6
| Flag for ADAPTER_INFO: this is a DAG file.
#define | ODS(_x)
| Macro to print a debug string. The behavior differs depending on the debug level.
#define | ODSEx(_x, _y)
| Macro to print debug data with the printf convention. The behavior differs depending on the debug level.
## Typedefs
typedef NetType | NetType
| Network type structure.
typedef npf_if_addr | npf_if_addr
| Addresses of a network adapter.
typedef WAN_ADAPTER_INT | WAN_ADAPTER
| Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
typedef WAN_ADAPTER * | PWAN_ADAPTER
| Describes an opened wan (dialup, VPN...) network adapter using the NetMon API.
typedef _ADAPTER_INFO | ADAPTER_INFO
| Contains comprehensive information about a network adapter.
typedef _ADAPTER_INFO * | PADAPTER_INFO
| Contains comprehensive information about a network adapter.
typedef _ADAPTER | ADAPTER
| Describes an opened network adapter.
typedef _ADAPTER * | LPADAPTER
| Describes an opened network adapter.
typedef _PACKET | PACKET
| Structure that contains a group of packets coming from the driver.
typedef _PACKET * | LPPACKET
| Structure that contains a group of packets coming from the driver.
typedef _PACKET_OID_DATA PACKET_OID_DATA * | PPACKET_OID_DATA
## Functions
LONG | PacketDumpRegistryKey (PCHAR KeyName, PCHAR FileName)
| Dumps a registry key to disk in text format. Uses regedit.
void | PacketPopulateAdaptersInfoList ()
PWCHAR | SChar2WChar (PCHAR string)
| Converts an ASCII string to UNICODE. Uses the MultiByteToWideChar() system function.
PCHAR | WChar2SChar (PWCHAR string)
| Converts an UNICODE string to ASCII. Uses the WideCharToMultiByte() system function.
BOOL | PacketGetFileVersion (LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen)
| Returns the version of a dll or exe file.
PADAPTER_INFO | PacketFindAdInfo (PCHAR AdapterName)
BOOLEAN | PacketUpdateAdInfo (PCHAR AdapterName)
PCHAR | PacketGetVersion ()
| Return a string with the dll version.
PCHAR | PacketGetDriverVersion ()
| Return a string with the version of the NPF.sys device driver.
BOOLEAN | PacketSetMinToCopy (LPADAPTER AdapterObject, int nbytes)
| Defines the minimum amount of data that will be received in a read.
BOOLEAN | PacketSetNumWrites (LPADAPTER AdapterObject, int nwrites)
| Sets the number of times a single packet written with PacketSendPacket() will be repeated on the network.
BOOLEAN | PacketSetMode (LPADAPTER AdapterObject, int mode)
| Sets the working mode of an adapter.
BOOLEAN | PacketSetReadTimeout (LPADAPTER AdapterObject, int timeout)
| Sets the timeout after which a read on an adapter returns.
BOOLEAN | PacketSetBpf (LPADAPTER AdapterObject, struct bpf_program *fp)
| Sets a kernel-level packet filter.
INT | PacketSetSnapLen (LPADAPTER AdapterObject, int snaplen)
| Sets the snap len on the adapters that allow it.
BOOLEAN | PacketGetStats (LPADAPTER AdapterObject, struct bpf_stat *s)
| Returns a couple of statistic values about the current capture session.
BOOLEAN | PacketGetStatsEx (LPADAPTER AdapterObject, struct bpf_stat *s)
| Returns statistic values about the current capture session. Enhanced version of PacketGetStats().
BOOLEAN | PacketSetBuff (LPADAPTER AdapterObject, int dim)
| Sets the size of the kernel-level buffer associated with a capture.
BOOLEAN | PacketGetNetType (LPADAPTER AdapterObject, NetType *type)
| Returns information about the MAC type of an adapter.
LPADAPTER | PacketOpenAdapter (PCHAR AdapterName)
| Opens an adapter.
BOOLEAN | PacketSendPacket (LPADAPTER AdapterObject, LPPACKET pPacket, BOOLEAN Sync)
| Sends one (or more) copies of a packet to the network.
INT | PacketSendPackets (LPADAPTER AdapterObject, PVOID PacketBuff, ULONG Size, BOOLEAN Sync)
| Sends a buffer of packets to the network.
LPPACKET | PacketAllocatePacket (void)
| Allocates a _PACKET structure.
VOID | PacketInitPacket (LPPACKET lpPacket, PVOID Buffer, UINT Length)
| Initializes a _PACKET structure.
VOID | PacketFreePacket (LPPACKET lpPacket)
| Frees a _PACKET structure.
BOOLEAN | PacketReceivePacket (LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
| Read data (packets or statistics) from the NPF driver.
BOOLEAN | PacketSetHwFilter (LPADAPTER AdapterObject, ULONG Filter)
| Sets a hardware filter on the incoming packets.
BOOLEAN | PacketGetAdapterNames (PTSTR pStr, PULONG BufferSize)
| Retrieve the list of available network adapters and their description.
BOOLEAN | PacketGetNetInfoEx (PCHAR AdapterName, npf_if_addr *buffer, PLONG NEntries)
| Returns comprehensive information the addresses of an adapter.
BOOLEAN | PacketRequest (LPADAPTER AdapterObject, BOOLEAN Set, PPACKET_OID_DATA OidData)
| Performs a query/set operation on an internal variable of the network card driver.
HANDLE | PacketGetReadEvent (LPADAPTER AdapterObject)
| Returns the notification event associated with the read calls on an adapter.
BOOLEAN | PacketSetDumpName (LPADAPTER AdapterObject, void *name, int len)
| Sets the name of the file that will receive the packet when the adapter is in dump mode.
BOOLEAN | PacketSetDumpLimits (LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks)
| Set the dump mode limits.
BOOLEAN | PacketIsDumpEnded (LPADAPTER AdapterObject, BOOLEAN sync)
| Returns the status of the kernel dump process, i.e. tells if one of the limits defined with PacketSetDumpLimits() was reached.
BOOL | PacketStopDriver ()
| Stops and unloads the WinPcap device driver.
VOID | PacketCloseAdapter (LPADAPTER lpAdapter)
| Closes an adapter.

## Function Documentation

PADAPTER_INFO PacketFindAdInfo | ( | PCHAR | AdapterName | ) |

| Referenced by PacketGetNetInfoEx(), PacketGetNetType(), and PacketOpenAdapter().

BOOL PacketGetFileVersion | ( | LPTSTR | FileName,
|  | PCHAR | VersionBuff,
|  | UINT | VersionBuffLen
| ) |

  | Returns the version of a dll or exe file. Parameters:
  FileName | Name of the file whose version has to be retrieved.
  VersionBuff | Buffer that will contain the string with the file version.
  VersionBuffLen | Length of the buffer poited by VersionBuff.
Returns: If the function succeeds, the return value is TRUE. Note: uses the GetFileVersionInfoSize() and GetFileVersionInfo() WIN32 API functions Definition at line 419 of file Packet32.c. References ODS, ODSEx, and WChar2SChar(). Referenced by DllMain().

void PacketPopulateAdaptersInfoList | ( |  | ) |

| Referenced by PacketGetAdapterNames().

BOOLEAN PacketUpdateAdInfo | ( | PCHAR | AdapterName | ) |

| Referenced by PacketCloseAdapter(), PacketGetNetInfoEx(), and PacketOpenAdapter().

PWCHAR SChar2WChar | ( | PCHAR | string | ) |

  | Converts an ASCII string to UNICODE. Uses the MultiByteToWideChar() system function. Parameters:
  string | The string to convert.
Returns: The converted string. Definition at line 213 of file Packet32.c. Referenced by PacketOpenAdapter(), and PacketSetDumpName().

PCHAR WChar2SChar | ( | PWCHAR | string | ) |

  | Converts an UNICODE string to ASCII. Uses the WideCharToMultiByte() system function. Parameters:
  string | The string to convert.
Returns: The converted string. Definition at line 229 of file Packet32.c. Referenced by PacketGetFileVersion(), PacketGetNetInfoEx(), and PacketOpenAdapter().

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.