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

# Packet.dll exported functions and variables
[Packet Driver API developer's manual]

Opens an adapter using the DAG capture API. More...

## Functions
PCHAR | PacketGetVersion ()
| Return a string with the dll version.
PCHAR | PacketGetDriverVersion ()
| Return a string with the version of the NPF.sys device driver.
BOOL | PacketStopDriver ()
| Stops and unloads the WinPcap device driver.
LPADAPTER | PacketOpenAdapter (PCHAR AdapterName)
| Opens an adapter.
VOID | PacketCloseAdapter (LPADAPTER lpAdapter)
| Closes an adapter.
LPPACKET | PacketAllocatePacket (void)
| Allocates a _PACKET structure.
VOID | PacketFreePacket (LPPACKET lpPacket)
| Frees a _PACKET structure.
VOID | PacketInitPacket (LPPACKET lpPacket, PVOID Buffer, UINT Length)
| Initializes a _PACKET structure.
BOOLEAN | PacketReceivePacket (LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
| Read data (packets or statistics) from the NPF driver.
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.
BOOLEAN | PacketSetMinToCopy (LPADAPTER AdapterObject, int nbytes)
| Defines the minimum amount of data that will be received in a read.
BOOLEAN | PacketSetMode (LPADAPTER AdapterObject, int mode)
| Sets the working mode of 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.
HANDLE | PacketGetReadEvent (LPADAPTER AdapterObject)
| Returns the notification event associated with the read calls on an adapter.
BOOLEAN | PacketSetNumWrites (LPADAPTER AdapterObject, int nwrites)
| Sets the number of times a single packet written with PacketSendPacket() will be repeated on the network.
BOOLEAN | PacketSetReadTimeout (LPADAPTER AdapterObject, int timeout)
| Sets the timeout after which a read on an adapter returns.
BOOLEAN | PacketSetBuff (LPADAPTER AdapterObject, int dim)
| Sets the size of the kernel-level buffer associated with a capture.
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 | PacketRequest (LPADAPTER AdapterObject, BOOLEAN Set, PPACKET_OID_DATA OidData)
| Performs a query/set operation on an internal variable of the network card 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 | PacketGetNetType (LPADAPTER AdapterObject, NetType *type)
| Returns information about the MAC type of an adapter.

## Detailed Description

Opens an adapter using the DAG capture API.

## Function Documentation

LPPACKET PacketAllocatePacket | ( | void |  | ) |

| Allocates a _PACKET structure. Returns: On succeess, the return value is the pointer to a _PACKET structure otherwise the return value is NULL. The structure returned will be passed to the PacketReceivePacket() function to receive the packets from the driver. Warning: The Buffer field of the _PACKET structure is not set by this function. The buffer must be allocated by the application, and associated to the PACKET structure with a call to PacketInitPacket. Definition at line 1123 of file Packet32.c. References ODS. Referenced by main(), pcap_open_live(), and pcap_sendpacket().

VOID PacketCloseAdapter | ( | LPADAPTER | lpAdapter | ) |

  | Closes an adapter. Parameters:
  lpAdapter | the pointer to the adapter to close.
PacketCloseAdapter closes the given adapter and frees the associated ADAPTER structure Definition at line 1081 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, INFO_FLAG_DAG_FILE, _ADAPTER::Name, PacketUpdateAdInfo(), _ADAPTER::pWanAdapter, and _ADAPTER::ReadEvent. Referenced by main(), pcap_close_win32(), and pcap_open_live().

VOID PacketFreePacket | ( | LPPACKET | lpPacket | ) |

  | Frees a _PACKET structure. Parameters:
  lpPacket | The structure to free.
Warning: the user-allocated buffer associated with the _PACKET structure is not deallocated by this function and must be explicitly deallocated by the programmer. Definition at line 1144 of file Packet32.c. Referenced by main(), pcap_open_live(), and pcap_sendpacket().

BOOLEAN PacketGetAdapterNames | ( | PTSTR | pStr,
|  | PULONG | BufferSize
| ) |

  | Retrieve the list of available network adapters and their description. Parameters:
  pStr | User allocated string that will be filled with the names of the adapters.
  BufferSize | Length of the buffer pointed by pStr. If the function fails, this variable contains the number of bytes that are needed to contain the adapter list.
Returns: If the function succeeds, the return value is nonzero. If the return value is zero, BufferSize contains the number of bytes that are needed to contain the adapter list. Usually, this is the first function that should be used to communicate with the driver. It returns the names of the adapters installed on the system and supported by WinPcap. After the names of the adapters, pStr contains a string that describes each of them. After a call to PacketGetAdapterNames pStr contains, in succession: a variable number of ASCII strings, each with the names of an adapter, separated by a "" a double "" a number of ASCII strings, each with the description of an adapter, separated by a "". The number of descriptions is the same of the one of names. The fisrt description corresponds to the first name, and so on. a double "". Definition at line 2010 of file Packet32.c. References AdaptersInfoList, _ADAPTER_INFO::Description, _ADAPTER_INFO::Name, _ADAPTER_INFO::Next, ODS, ODSEx, and PacketPopulateAdaptersInfoList(). Referenced by main().

PCHAR PacketGetDriverVersion | ( |  | ) |

| Return a string with the version of the NPF.sys device driver. Returns: A char pointer to the version of the driver. Definition at line 879 of file Packet32.c. References PacketDriverVersion.

BOOLEAN PacketGetNetInfoEx | ( | PCHAR | AdapterName,
|  | npf_if_addr * | buffer,
|  | PLONG | NEntries
| ) |

  | Returns comprehensive information the addresses of an adapter. Parameters:
  AdapterName | String that contains the name of the adapter.
  buffer | A user allocated array of npf_if_addr that will be filled by the function.
  NEntries | Size of the array (in npf_if_addr).
Returns: If the function succeeds, the return value is nonzero. This function grabs from the registry information like the IP addresses, the netmasks and the broadcast addresses of an interface. The buffer passed by the user is filled with npf_if_addr structures, each of which contains the data for a single address. If the buffer is full, the reaming addresses are dropeed, therefore set its dimension to sizeof(npf_if_addr) if you want only the first address. Definition at line 2095 of file Packet32.c. References _ADAPTER_INFO::NetworkAddresses, _ADAPTER_INFO::NNetworkAddresses, ODS, PacketFindAdInfo(), PacketUpdateAdInfo(), and WChar2SChar().

BOOLEAN PacketGetNetType | ( | LPADAPTER | AdapterObject,
|  | NetType * | type
| ) |

  | Returns information about the MAC type of an adapter. Parameters:
  AdapterObject | The adapter on which information is needed.
  type | Pointer to a NetType structure that will be filled by the function.
Returns: If the function succeeds, the return value is nonzero, otherwise the return value is zero. This function return the link layer and the speed (in bps) of an opened adapter. The LinkType field of the type parameter can have one of the following values: NdisMedium802_3: Ethernet (802.3) NdisMediumWan: WAN NdisMedium802_5: Token Ring (802.5) NdisMediumFddi: FDDI NdisMediumAtm: ATM NdisMediumArcnet878_2: ARCNET (878.2) Definition at line 2166 of file Packet32.c. References _ADAPTER_INFO::LinkLayer, _ADAPTER::Name, ODS, and PacketFindAdInfo(). Referenced by pcap_open_live().

HANDLE PacketGetReadEvent | ( | LPADAPTER | AdapterObject | ) |

  | Returns the notification event associated with the read calls on an adapter. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
Returns: The handle of the event that the driver signals when some data is available in the kernel buffer. The event returned by this function is signaled by the driver if: The adapter pointed by AdapterObject is in capture mode and an amount of data greater or equal than the one set with the PacketSetMinToCopy() function is received from the network. the adapter pointed by AdapterObject is in capture mode, no data has been received from the network but the the timeout set with the PacketSetReadTimeout() function has elapsed. the adapter pointed by AdapterObject is in statics mode and the the timeout set with the PacketSetReadTimeout() function has elapsed. This means that a new statistic sample is available. In every case, a call to PacketReceivePacket() will return immediately. The event can be passed to standard Win32 functions (like WaitForSingleObject or WaitForMultipleObjects) to wait until the driver's buffer contains some data. It is particularly useful in GUI applications that need to wait concurrently on several events. Definition at line 1616 of file Packet32.c. References _ADAPTER::ReadEvent. Referenced by pcap_getevent().

BOOLEAN PacketGetStats | ( | LPADAPTER | AdapterObject,
|  | struct bpf_stat * | s
| ) |

  | Returns a couple of statistic values about the current capture session. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  s | Pointer to a user provided bpf_stat structure that will be filled by the function.
Returns: If the function succeeds, the return value is nonzero. With this function, the programmer can know the value of two internal variables of the driver: the number of packets that have been received by the adapter AdapterObject, starting at the time in which it was opened with PacketOpenAdapter. the number of packets that have been dropped by the driver. A packet is dropped when the kernel buffer associated with the adapter is full. Definition at line 1809 of file Packet32.c. References bpf_stat::bs_drop, bpf_stat::bs_recv, _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, and _ADAPTER::pWanAdapter. Referenced by main(), and pcap_stats_win32().

BOOLEAN PacketGetStatsEx | ( | LPADAPTER | AdapterObject,
|  | struct bpf_stat * | s
| ) |

  | Returns statistic values about the current capture session. Enhanced version of PacketGetStats(). Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  s | Pointer to a user provided bpf_stat structure that will be filled by the function.
Returns: If the function succeeds, the return value is nonzero. With this function, the programmer can retireve the sname values provided by PacketGetStats(), plus: the number of drops by interface (not yet supported, always 0). the number of packets that reached the application, i.e that were accepted by the kernel filter and that fitted in the kernel buffer. Definition at line 1871 of file Packet32.c. References bpf_stat::bs_capt, bpf_stat::bs_drop, bpf_stat::bs_recv, _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, bpf_stat::ps_ifdrop, and _ADAPTER::pWanAdapter. Referenced by pcap_stats_ex().

PCHAR PacketGetVersion | ( |  | ) |

| Return a string with the dll version. Returns: A char pointer to the version of the library. Definition at line 870 of file Packet32.c. References PacketLibraryVersion. Referenced by main(), and pcap_lib_version().

VOID PacketInitPacket | ( | LPPACKET | lpPacket,
|  | PVOID | Buffer,
|  | UINT | Length
| ) |

  | Initializes a _PACKET structure. Parameters:
  lpPacket | The structure to initialize.
  Buffer | A pointer to a user-allocated buffer that will contain the captured data.
  Length | the length of the buffer. This is the maximum buffer size that will be transferred from the driver to the application using a single read.
Note: the size of the buffer associated with the PACKET structure is a parameter that can sensibly influence the performance of the capture process, since this buffer will contain the packets received from the the driver. The driver is able to return several packets using a single read call (see the PacketReceivePacket() function for details), and the number of packets transferable to the application in a call is limited only by the size of the buffer associated with the PACKET structure passed to PacketReceivePacket(). Therefore setting a big buffer with PacketInitPacket can noticeably decrease the number of system calls, reducing the impcat of the capture process on the processor. Definition at line 1166 of file Packet32.c. References _PACKET::bIoComplete, _PACKET::Buffer, _PACKET::Length, and _PACKET::ulBytesReceived. Referenced by main(), pcap_open_live(), pcap_sendpacket(), and pcap_setuserbuffer().

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. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  sync | if TRUE, the function blocks until the dump is finished, otherwise it returns immediately.
Returns: TRUE if the dump is ended, FALSE otherwise. PacketIsDumpEnded() informs the user about the limits that were set with a previous call to PacketSetDumpLimits(). Warning: If no calls to PacketSetDumpLimits() were performed or if the dump process has no limits (i.e. if the arguments of the last call to PacketSetDumpLimits() were both 0), setting sync to TRUE will block the application on this call forever. Definition at line 1566 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, ODS, and _ADAPTER::ReadEvent. Referenced by pcap_live_dump_ended().

LPADAPTER PacketOpenAdapter | ( | PCHAR | AdapterName | ) |

  | Opens an adapter. Parameters:
  AdapterName | A string containing the name of the device to open. Use the PacketGetAdapterNames() function to retrieve the list of available devices.
Returns: If the function succeeds, the return value is the pointer to a properly initialized ADAPTER object, otherwise the return value is NULL. Definition at line 938 of file Packet32.c. References _ADAPTER_INFO::Flags, _ADAPTER::Flags, INFO_FLAG_DAG_CARD, INFO_FLAG_NDIS_ADAPTER, INFO_FLAG_NDISWAN_ADAPTER, _ADAPTER::Name, ODSEx, PacketFindAdInfo(), PacketOpenAdapterNPF(), PacketUpdateAdInfo(), _ADAPTER::pWanAdapter, _ADAPTER::ReadEvent, SChar2WChar(), and WChar2SChar(). Referenced by main(), and pcap_open_live().

BOOLEAN PacketReceivePacket | ( | LPADAPTER | AdapterObject,
|  | LPPACKET | lpPacket,
|  | BOOLEAN | Sync
| ) |

  | Read data (packets or statistics) from the NPF driver. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure identifying the network adapter from which the data is received.
  lpPacket | Pointer to a PACKET structure that will contain the data.
  Sync | This parameter is deprecated and will be ignored. It is present for compatibility with older applications.
Returns: If the function succeeds, the return value is nonzero. The data received with this function can be a group of packets or a static on the network traffic, depending on the working mode of the driver. The working mode can be set with the PacketSetMode() function. Give a look at that function if you are interested in the format used to return statistics values, here only the normal capture mode will be described. The number of packets received with this function is variable. It depends on the number of packets currently stored in the driver’s buffer, on the size of these packets and on the size of the buffer associated to the lpPacket parameter. The following figure shows the format used by the driver to pass packets to the application. method used to encode the packets Packets are stored in the buffer associated with the lpPacket _PACKET structure. The Length field of that structure is updated with the amount of data copied in the buffer. Each packet has a header consisting in a bpf_hdr structure that defines its length and contains its timestamp. A padding field is used to word-align the data in the buffer (to speed up the access to the packets). The bh_datalen and bh_hdrlen fields of the bpf_hdr structures should be used to extract the packets from the buffer. Examples can be seen either in the TestApp sample application (see the Packet.dll samples page) provided in the developer's pack, or in the pcap_read() function of wpcap. Definition at line 1205 of file Packet32.c. References _PACKET::Buffer, _ADAPTER::hFile, _PACKET::Length, _ADAPTER::pWanAdapter, _ADAPTER::ReadEvent, _ADAPTER::ReadTimeOut, and _PACKET::ulBytesReceived. Referenced by main(), and pcap_read_win32_npf().

BOOLEAN PacketRequest | ( | LPADAPTER | AdapterObject,
|  | BOOLEAN | Set,
|  | PPACKET_OID_DATA | OidData
| ) |

  | Performs a query/set operation on an internal variable of the network card driver. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  Set | Determines if the operation is a set (Set=TRUE) or a query (Set=FALSE).
  OidData | A pointer to a _PACKET_OID_DATA structure that contains or receives the data.
Returns: If the function succeeds, the return value is nonzero. Note: not all the network adapters implement all the query/set functions. There is a set of mandatory OID functions that is granted to be present on all the adapters, and a set of facultative functions, not provided by all the cards (see the Microsoft DDKs to see which functions are mandatory). If you use a facultative function, be careful to enclose it in an if statement to check the result. Definition at line 1926 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, and ODSEx. Referenced by PacketSetHwFilter(), and PacketSetMaxLookaheadsize().

BOOLEAN PacketSendPacket | ( | LPADAPTER | AdapterObject,
|  | LPPACKET | lpPacket,
|  | BOOLEAN | Sync
| ) |

  | Sends one (or more) copies of a packet to the network. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure identifying the network adapter that will send the packets.
  lpPacket | Pointer to a PACKET structure with the packet to send.
  Sync | This parameter is deprecated and will be ignored. It is present for compatibility with older applications.
Returns: If the function succeeds, the return value is nonzero. This function is used to send a raw packet to the network. 'Raw packet' means that the programmer will have to include the protocol headers, since the packet is sent to the network 'as is'. The CRC needs not to be calculated and put at the end of the packet, because it will be transparently added by the network interface. The behavior of this function is influenced by the PacketSetNumWrites() function. With PacketSetNumWrites(), it is possible to change the number of times a single write must be repeated. The default is 1, i.e. every call to PacketSendPacket() will correspond to one packet sent to the network. If this number is greater than 1, for example 1000, every raw packet written by the application will be sent 1000 times on the network. This feature mitigates the overhead of the context switches and therefore can be used to generate high speed traffic. It is particularly useful for tools that test networks, routers, and servers and need to obtain high network loads. The optimized sending process is still limited to one packet at a time: for the moment it cannot be used to send a buffer with multiple packets. Note: The ability to write multiple packets is currently present only in the Windows NTx version of the packet driver. In Windows 95/98/ME it is emulated at user level in packet.dll. This means that an application that uses the multiple write method will run in Windows 9x as well, but its performance will be very low compared to the one of WindowsNTx. Definition at line 1268 of file Packet32.c. References _PACKET::Buffer, _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, _PACKET::Length, and ODS. Referenced by main(), and pcap_sendpacket().

INT PacketSendPackets | ( | LPADAPTER | AdapterObject,
|  | PVOID | PacketBuff,
|  | ULONG | Size,
|  | BOOLEAN | Sync
| ) |

  | Sends a buffer of packets to the network. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure identifying the network adapter that will send the packets.
  PacketBuff | Pointer to buffer with the packets to send.
  Size | Size of the buffer pointed by the PacketBuff argument.
  Sync | if TRUE, the packets are sent respecting the timestamps. If FALSE, the packets are sent as fast as possible
Returns: The amount of bytes actually sent. If the return value is smaller than the Size parameter, an error occurred during the send. The error can be caused by a driver/adapter problem or by an inconsistent/bogus packet buffer. This function is used to send a buffer of raw packets to the network. The buffer can contain an arbitrary number of raw packets, each of which preceded by a dump_bpf_hdr structure. The dump_bpf_hdr is the same used by WinPcap and libpcap to store the packets in a file, therefore sending a capture file is straightforward. 'Raw packets' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface. Note: Using this function if more efficient than issuing a series of PacketSendPacket(), because the packets are buffered in the kernel driver, so the number of context switches is reduced. When Sync is set to TRUE, the packets are synchronized in the kerenl with a high precision timestamp. This requires a remarkable amount of CPU, but allows to send the packets with a precision of some microseconds (depending on the precision of the performance counter of the machine). Such a precision cannot be reached sending the packets separately with PacketSendPacket(). Definition at line 1312 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, and ODS. Referenced by pcap_sendqueue_transmit().

BOOLEAN PacketSetBpf | ( | LPADAPTER | AdapterObject,
|  | struct bpf_program * | fp
| ) |

  | Sets a kernel-level packet filter. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  fp | Pointer to a filtering program that will be associated with this capture or monitoring instance and that will be executed on every incoming packet.
Returns: This function returns TRUE if the filter is set successfully, FALSE if an error occurs or if the filter program is not accepted after a safeness check by the driver. The driver performs the check in order to avoid system crashes due to buggy or malicious filters, and it rejects non conformat filters. This function associates a new BPF filter to the adapter AdapterObject. The filter, pointed by fp, is a set of bpf_insn instructions. A filter can be automatically created by using the pcap_compile() function of wpcap. This function converts a human readable text expression with the syntax of WinDump (see the manual of WinDump at http://netgroup.polito.it/windump for details) into a BPF program. If your program doesn't link wpcap, but you need to know the code of a particular filter, you can launch WinDump with the -d or -dd or -ddd flags to obtain the pseudocode. Definition at line 1753 of file Packet32.c. References bpf_program::bf_insns, bpf_program::bf_len, _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, and _ADAPTER::pWanAdapter. Referenced by pcap_setfilter_win32_npf().

BOOLEAN PacketSetBuff | ( | LPADAPTER | AdapterObject,
|  | int | dim
| ) |

  | Sets the size of the kernel-level buffer associated with a capture. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  dim | New size of the buffer, in kilobytes.
Returns: The function returns TRUE if successfully completed, FALSE if there is not enough memory to allocate the new buffer. When a new dimension is set, the data in the old buffer is discarded and the packets stored in it are lost. Note: the dimension of the kernel buffer affects heavily the performances of the capture process. An adequate buffer in the driver is able to keep the packets while the application is busy, compensating the delays of the application and avoiding the loss of packets during bursts or high network activity. The buffer size is set to 0 when an instance of the driver is opened: the programmer should remember to set it to a proper value. As an example, wpcap sets the buffer size to 1MB at the beginning of a capture. Definition at line 1715 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, and _ADAPTER::pWanAdapter. Referenced by main(), pcap_open_live(), and pcap_setbuff().

BOOLEAN PacketSetDumpLimits | ( | LPADAPTER | AdapterObject,
|  | UINT | maxfilesize,
|  | UINT | maxnpacks
| ) |

  | Set the dump mode limits. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  maxfilesize | The maximum dimension of the dump file, in bytes. 0 means no limit.
  maxnpacks | The maximum number of packets contained in the dump file. 0 means no limit.
Returns: If the function succeeds, the return value is nonzero. This function sets the limits after which the NPF driver stops to save the packets to file when an adapter is in dump mode. This allows to limit the dump file to a precise number of bytes or packets, avoiding that very long dumps fill the disk space. If both maxfilesize and maxnpacks are set, the dump is stopped when the first of the two is reached. Note: When a limit is reached, the dump is stopped, but the file remains opened. In order to flush correctly the data and access the file consistently, you need to close the adapter with PacketCloseAdapter(). Definition at line 1527 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, and ODS. Referenced by pcap_live_dump().

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. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  name | the file name, in ASCII or UNICODE.
  len | the length of the buffer containing the name, in bytes.
Returns: If the function succeeds, the return value is nonzero. This function defines the file name that the driver will open to store the packets on disk when it works in dump mode. The adapter must be in dump mode, i.e. PacketSetMode() should have been called previously with mode = PACKET_MODE_DUMP. otherwise this function will fail. If PacketSetDumpName was already invoked on the adapter pointed by AdapterObject, the driver closes the old file and opens the new one. Definition at line 1472 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, ODS, and SChar2WChar(). Referenced by pcap_live_dump().

BOOLEAN PacketSetHwFilter | ( | LPADAPTER | AdapterObject,
|  | ULONG | Filter
| ) |

  | Sets a hardware filter on the incoming packets. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  Filter | The identifier of the filter.
Returns: If the function succeeds, the return value is nonzero. The filter defined with this filter is evaluated by the network card, at a level that is under the NPF device driver. Here is a list of the most useful hardware filters (A complete list can be found in ntddndis.h): NDIS_PACKET_TYPE_PROMISCUOUS: sets promiscuous mode. Every incoming packet is accepted by the adapter. NDIS_PACKET_TYPE_DIRECTED: only packets directed to the workstation's adapter are accepted. NDIS_PACKET_TYPE_BROADCAST: only broadcast packets are accepted. NDIS_PACKET_TYPE_MULTICAST: only multicast packets belonging to groups of which this adapter is a member are accepted. NDIS_PACKET_TYPE_ALL_MULTICAST: every multicast packet is accepted. NDIS_PACKET_TYPE_ALL_LOCAL: all local packets, i.e. NDIS_PACKET_TYPE_DIRECTED + NDIS_PACKET_TYPE_BROADCAST + NDIS_PACKET_TYPE_MULTICAST Definition at line 1965 of file Packet32.c. References _ADAPTER::Flags, INFO_FLAG_NDIS_ADAPTER, ODS, PacketRequest(), and PPACKET_OID_DATA. Referenced by main(), and pcap_open_live().

BOOLEAN PacketSetMinToCopy | ( | LPADAPTER | AdapterObject,
|  | int | nbytes
| ) |

  | Defines the minimum amount of data that will be received in a read. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure
  nbytes | the minimum amount of data in the kernel buffer that will cause the driver to release a read on this adapter.
Returns: If the function succeeds, the return value is nonzero. In presence of a large value for nbytes, the kernel waits for the arrival of several packets before copying the data to the user. This guarantees a low number of system calls, i.e. lower processor usage, i.e. better performance, which is a good setting for applications like sniffers. Vice versa, a small value means that the kernel will copy the packets as soon as the application is ready to receive them. This is suggested for real time applications (like, for example, a bridge) that need the better responsiveness from the kernel. note: this function has effect only in Windows NTx. The driver for Windows 9x doesn't offer this possibility, therefore PacketSetMinToCopy is implemented under these systems only for compatibility. Definition at line 1392 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, INFO_FLAG_NDISWAN_ADAPTER, and _ADAPTER::pWanAdapter. Referenced by pcap_open_live(), and pcap_setmintocopy().

BOOLEAN PacketSetMode | ( | LPADAPTER | AdapterObject,
|  | int | mode
| ) |

  | Sets the working mode of an adapter. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  mode | The new working mode of the adapter.
Returns: If the function succeeds, the return value is nonzero. The device driver of WinPcap has 4 working modes: Capture mode (mode = PACKET_MODE_CAPT): normal capture mode. The packets transiting on the wire are copied to the application when PacketReceivePacket() is called. This is the default working mode of an adapter. Statistical mode (mode = PACKET_MODE_STAT): programmable statistical mode. PacketReceivePacket() returns, at precise intervals, statics values on the network traffic. The interval between the statistic samples is by default 1 second but it can be set to any other value (with a 1 ms precision) with the PacketSetReadTimeout() function. The data returned by PacketReceivePacket() when the adapter is in statistical mode is shown in the following figure: data structure returned by statistical mode Two 64-bit counters are provided: the number of packets and the amount of bytes that satisfy a filter previously set with PacketSetBPF(). If no filter has been set, all the packets are counted. The counters are encapsulated in a bpf_hdr structure, so that they will be parsed correctly by wpcap. Statistical mode has a very low impact on system performance compared to capture mode. Dump mode (mode = PACKET_MODE_DUMP): the packets are dumped to disk by the driver, in libpcap format. This method is much faster than saving the packets after having captured them. No data is returned by PacketReceivePacket(). If the application sets a filter with PacketSetBPF(), only the packets that satisfy this filter are dumped to disk. Statitical Dump mode (mode = PACKET_MODE_STAT_DUMP): the packets are dumped to disk by the driver, in libpcap format, like in dump mode. PacketReceivePacket() returns, at precise intervals, statics values on the network traffic and on the amount of data saved to file, in a way similar to statistical mode. The data returned by PacketReceivePacket() when the adapter is in statistical dump mode is shown in the following figure: data structure returned by statistical dump mode Three 64-bit counters are provided: the number of packets accepted, the amount of bytes accepted and the effective amount of data (including headers) dumped to file. If no filter has been set, all the packets are dumped to disk. The counters are encapsulated in a bpf_hdr structure, so that they will be parsed correctly by wpcap. Look at the NetMeter example in the WinPcap developer's pack to see how to use statistics mode. Definition at line 1446 of file Packet32.c. References _ADAPTER::hFile, and _ADAPTER::pWanAdapter. Referenced by pcap_live_dump(), and pcap_setmode().

BOOLEAN PacketSetNumWrites | ( | LPADAPTER | AdapterObject,
|  | int | nwrites
| ) |

  | Sets the number of times a single packet written with PacketSendPacket() will be repeated on the network. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  nwrites | Number of copies of a packet that will be physically sent by the interface.
Returns: If the function succeeds, the return value is nonzero. See PacketSendPacket() for details. Definition at line 1629 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_NDIS_ADAPTER, and ODS. Referenced by main().

BOOLEAN PacketSetReadTimeout | ( | LPADAPTER | AdapterObject,
|  | int | timeout
| ) |

  | Sets the timeout after which a read on an adapter returns. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  timeout | indicates the timeout, in milliseconds, after which a call to PacketReceivePacket() on the adapter pointed by AdapterObject will be released, also if no packets have been captured by the driver. Setting timeout to 0 means no timeout, i.e. PacketReceivePacket() never returns if no packet arrives. A timeout of -1 causes PacketReceivePacket() to always return immediately.
Returns: If the function succeeds, the return value is nonzero. Note: This function works also if the adapter is working in statistics mode, and can be used to set the time interval between two statistic reports. Definition at line 1656 of file Packet32.c. References _ADAPTER::Flags, _ADAPTER::hFile, INFO_FLAG_DAG_CARD, _ADAPTER::pWanAdapter, and _ADAPTER::ReadTimeOut. Referenced by main(), pcap_open_live(), and pcap_setnonblock_win32().

INT PacketSetSnapLen | ( | LPADAPTER | AdapterObject,
|  | int | snaplen
| ) |

  | Sets the snap len on the adapters that allow it. Parameters:
  AdapterObject | Pointer to an _ADAPTER structure.
  snaplen | Desired snap len for this capture.
Returns: If the function succeeds, the return value is nonzero and specifies the actual snaplen that the card is using. If the function fails or if the card does't allow to set sna length, the return value is 0. The snap len is the amount of packet that is actually captured by the interface and received by the application. Some interfaces allow to capture only a portion of any packet for performance reasons. Note: : the return value can be different from the snaplen parameter, for example some boards round the snaplen to 4 bytes. Definition at line 1785 of file Packet32.c. References _ADAPTER::Flags, and INFO_FLAG_DAG_CARD. Referenced by pcap_open_live().

BOOL PacketStopDriver | ( |  | ) |

| Stops and unloads the WinPcap device driver. Returns: If the function succeeds, the return value is nonzero, otherwise it is zero. This function can be used to unload the driver from memory when the application no more needs it. Note that the driver is physically stopped and unloaded only when all the files on its devices are closed, i.e. when all the applications that use WinPcap close all their adapters. Definition at line 892 of file Packet32.c. References scmHandle.

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