#include <packet32.h>
#include <windows.h>
#include <windowsx.h>
#include <ntddndis.h>
#include <stdio.h>
Go to the source code of this file.
Defines | |
#define | UNICODE 1 |
#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. | |
Functions | |
LONG | PacketDumpRegistryKey (PCHAR KeyName, PCHAR FileName) |
Dumps a registry key to disk in text format. Uses regedit. | |
BOOL APIENTRY | DllMain (HANDLE DllHandle, DWORD Reason, LPVOID lpReserved) |
The main dll function. | |
WCHAR * | SChar2WChar (char *string) |
Converts an ASCII string to UNICODE. Uses the MultiByteToWideChar() system function. | |
BOOLEAN | PacketSetMaxLookaheadsize (LPADAPTER AdapterObject) |
Sets the maximum possible lookahead buffer for the driver's Packet_tap() function. | |
BOOLEAN | PacketSetReadEvt (LPADAPTER AdapterObject) |
Retrieves the event associated in the driver with a capture instance and stores it in an _ADAPTER structure. | |
BOOL | PacketInstallDriver (SC_HANDLE ascmHandle, SC_HANDLE *srvHandle) |
Installs the NPF device driver. | |
ULONG | inet_addrU (const WCHAR *cp) |
Convert a Unicode dotted-quad to a 32-bit IP address. | |
PCHAR | PacketGetVersion () |
Returns a string with the dll version. | |
BOOLEAN | PacketGetNetType (LPADAPTER AdapterObject, NetType *type) |
Returns information about the MAC type of an adapter. | |
BOOL | PacketStopDriver () |
Stops and unloads the WinPcap device driver. | |
LPADAPTER | PacketOpenAdapter (LPTSTR 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 lpPacket, 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. | |
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 (LPTSTR AdapterName, npf_if_addr *buffer, PLONG NEntries) |
Returns comprehensive information the addresses of an adapter. | |
BOOLEAN | PacketGetNetInfo (LPTSTR AdapterName, PULONG netp, PULONG maskp) |
Returns the IP address and the netmask of an adapter. | |
Variables | |
TCHAR | szWindowTitle [] = TEXT("PACKET.DLL") |
Title of error windows. | |
SC_HANDLE | scmHandle = NULL |
SC_HANDLE | srvHandle = NULL |
LPCTSTR | NPFServiceName = TEXT("NPF") |
LPCTSTR | NPFServiceDesc = TEXT("Netgroup Packet Filter") |
LPCTSTR | NPFRegistryLocation = TEXT("SYSTEM\\CurrentControlSet\\Services\\NPF") |
LPCTSTR | NPFDriverPath = TEXT("system32\\drivers\\npf.sys") |
char | PacketLibraryVersion [] = "3.0 alpha3" |
Current packet.dll Version. It can be retrieved directly or through the PacketGetVersion() function. |
|
Value: { \ FILE *f; \ f = fopen("winpcap_debug.txt", "a"); \ fprintf(f, "%s", _x); \ fclose(f); \ }
Definition at line 44 of file Packet32.c. Referenced by DllMain(), PacketAllocatePacket(), PacketGetAdapterNames(), PacketGetNetType(), PacketInstallDriver(), PacketOpenAdapter(), PacketSendPackets(), PacketSetHwFilter(), PacketSetMaxLookaheadsize(), and PacketSetReadEvt(). |
|
Value: { \ FILE *f; \ f = fopen("winpcap_debug.txt", "a"); \ fprintf(f, _x, _y); \ fclose(f); \ }
Definition at line 54 of file Packet32.c. Referenced by PacketGetAdapterNames(), PacketGetNetType(), PacketInstallDriver(), PacketOpenAdapter(), and PacketRequest(). |
|
Definition at line 22 of file Packet32.c. |
|
The main dll function.
Definition at line 84 of file Packet32.c. References ODS, and PacketDumpRegistryKey(). |
|
Convert a Unicode dotted-quad to a 32-bit IP address.
Definition at line 275 of file Packet32.c. References val. Referenced by PacketGetNetInfo(), and PacketGetNetInfoEx(). |
|
Allocates a _PACKET structure.
Definition at line 686 of file Packet32.c. References ODS. Referenced by main(), pcap_open_live(), and pcap_sendpacket(). |
|
Closes an adapter.
Definition at line 666 of file Packet32.c. References _ADAPTER::hFile, and _ADAPTER::ReadEvent. Referenced by main(), PacketGetAdapterNames(), pcap_close(), and pcap_open_live(). |
|
Dumps a registry key to disk in text format. Uses regedit.
Let regedit do the dirt work for us Definition at line 314 of file Packet32.c. Referenced by DllMain(). |
|
Frees a _PACKET structure.
Definition at line 707 of file Packet32.c. Referenced by main(), and pcap_sendpacket(). |
|
Retrieve the list of available network adapters and their description.
Warning: the result of this function is obtained querying the registry, therefore the format of the result in Windows NTx is different from the one in Windows 9x. Windows 9x uses the ASCII encoding method to store a string, while Windows NTx uses UNICODE. After a call to PacketGetAdapterNames in Windows 95x, pStr contains, in succession:
In Windows NTx, pStr contains: the names of the adapters, in UNICODE format, separated by a single UNICODE "" (i.e. 2 ASCII ""), a double UNICODE "", followed by the descriptions of the adapters, in ASCII format, separated by a single ASCII "" . The string is terminated by a double ASCII "".
Definition at line 1353 of file Packet32.c. References ODS, ODSEx, PacketCloseAdapter(), PacketOpenAdapter(), PacketRequest(), and PPACKET_OID_DATA. Referenced by main(). |
|
Returns the IP address and the netmask of an adapter.
Definition at line 1936 of file Packet32.c. References inet_addrU(), maskp, netp, and SChar2WChar(). |
|
Returns comprehensive information the addresses of an adapter.
Definition at line 1690 of file Packet32.c. References inet_addrU(), and SChar2WChar(). |
|
Returns information about the MAC type of an adapter.
Definition at line 369 of file Packet32.c. References NetType::LinkSpeed, NetType::LinkType, ODS, ODSEx, PacketRequest(), and PPACKET_OID_DATA. Referenced by pcap_open_live(). |
|
Returns the notification event associated with the read calls on an adapter.
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 1100 of file Packet32.c. References _ADAPTER::ReadEvent. Referenced by pcap_getevent(). |
|
Returns a couple of statistic values about the current capture session.
Definition at line 1202 of file Packet32.c. References bpf_stat::bs_drop, bpf_stat::bs_recv, and _ADAPTER::hFile. Referenced by main(), and pcap_stats(). |
|
Returns statistic values about the current capture session. Enhanced version of PacketGetStats().
Definition at line 1236 of file Packet32.c. References bpf_stat::bs_capt, bpf_stat::bs_drop, bpf_stat::bs_recv, _ADAPTER::hFile, and bpf_stat::ps_ifdrop. Referenced by pcap_stats_ex(). |
|
Returns a string with the dll version.
Definition at line 349 of file Packet32.c. References PacketLibraryVersion. Referenced by main(). |
|
Initializes a _PACKET structure.
Definition at line 729 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(). |
|
Installs the NPF device driver.
Definition at line 224 of file Packet32.c. References ODS, ODSEx, and srvHandle. Referenced by PacketOpenAdapter(). |
|
Returns the status of the kernel dump process, i.e. tells if one of the limits defined with PacketSetDumpLimits() was reached.
Definition at line 1058 of file Packet32.c. References _ADAPTER::hFile, and _ADAPTER::ReadEvent. Referenced by pcap_live_dump_ended(). |
|
Opens an adapter.
Definition at line 468 of file Packet32.c. References _ADAPTER::hFile, _ADAPTER::NumWrites, ODS, ODSEx, PacketInstallDriver(), PacketSetMaxLookaheadsize(), PacketSetReadEvt(), SChar2WChar(), scmHandle, srvHandle, and _ADAPTER::SymbolicLink. Referenced by main(), PacketGetAdapterNames(), and pcap_open_live(). |
|
Read data (packets or statistics) from the NPF driver.
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 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 768 of file Packet32.c. References _PACKET::Buffer, _ADAPTER::hFile, _PACKET::Length, _ADAPTER::ReadEvent, _ADAPTER::ReadTimeOut, and _PACKET::ulBytesReceived. Referenced by main(), and pcap_read(). |
|
Performs a query/set operation on an internal variable of the network card driver.
Definition at line 1271 of file Packet32.c. References _ADAPTER::hFile, and ODSEx. Referenced by PacketGetAdapterNames(), PacketGetNetType(), PacketSetHwFilter(), and PacketSetMaxLookaheadsize(). |
|
Sends one (or more) copies of a packet to the network.
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.
Definition at line 809 of file Packet32.c. References _PACKET::Buffer, _ADAPTER::hFile, and _PACKET::Length. Referenced by main(), and pcap_sendpacket(). |
|
Sends a buffer of packets to the network.
Definition at line 845 of file Packet32.c. References _ADAPTER::hFile, and ODS. Referenced by pcap_sendqueue_transmit(). |
|
Sets a kernel-level packet filter.
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 1183 of file Packet32.c. References bpf_program::bf_insns, bpf_program::bf_len, and _ADAPTER::hFile. Referenced by pcap_setfilter(). |
|
Sets the size of the kernel-level buffer associated with a capture.
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 1157 of file Packet32.c. References _ADAPTER::hFile. Referenced by main(), pcap_open_live(), and pcap_setbuff(). |
|
Set the dump mode limits.
Definition at line 1027 of file Packet32.c. References _ADAPTER::hFile. Referenced by pcap_live_dump(). |
|
Sets the name of the file that will receive the packet when the adapter is in dump mode.
Definition at line 980 of file Packet32.c. References _ADAPTER::hFile, and SChar2WChar(). Referenced by pcap_live_dump(). |
|
Sets a hardware filter on the incoming packets.
Definition at line 1305 of file Packet32.c. References ODS, PacketRequest(), and PPACKET_OID_DATA. Referenced by main(), and pcap_open_live(). |
|
Sets the maximum possible lookahead buffer for the driver's Packet_tap() function.
Definition at line 142 of file Packet32.c. References ODS, PacketRequest(), and PPACKET_OID_DATA. Referenced by PacketOpenAdapter(). |
|
Defines the minimum amount of data that will be received in a read.
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 917 of file Packet32.c. References _ADAPTER::hFile. Referenced by pcap_open_live(), and pcap_setmintocopy(). |
|
Sets the working mode of an adapter.
![]() data structure returned by statistical mode
![]() data structure returned by statistical dump mode Definition at line 959 of file Packet32.c. References _ADAPTER::hFile. Referenced by pcap_live_dump(), and pcap_setmode(). |
|
Sets the number of times a single packet written with PacketSendPacket() will be repeated on the network.
Definition at line 1113 of file Packet32.c. References _ADAPTER::hFile. Referenced by main(). |
|
Retrieves the event associated in the driver with a capture instance and stores it in an _ADAPTER structure.
Definition at line 174 of file Packet32.c. References _ADAPTER::hFile, ODS, _ADAPTER::ReadEvent, and _ADAPTER::ReadTimeOut. Referenced by PacketOpenAdapter(). |
|
Sets the timeout after which a read on an adapter returns.
Definition at line 1131 of file Packet32.c. References _ADAPTER::hFile, and _ADAPTER::ReadTimeOut. Referenced by main(), pcap_open_live(), and pcap_setnonblock(). |
|
Stops and unloads the WinPcap device driver.
Definition at line 407 of file Packet32.c. References scmHandle. |
|
Converts an ASCII string to UNICODE. Uses the MultiByteToWideChar() system function.
Definition at line 123 of file Packet32.c. Referenced by PacketGetNetInfo(), PacketGetNetInfoEx(), PacketOpenAdapter(), and PacketSetDumpName(). |
|
Definition at line 76 of file Packet32.c. |
|
Definition at line 75 of file Packet32.c. |
|
Definition at line 74 of file Packet32.c. |
|
Definition at line 73 of file Packet32.c. |
|
Definition at line 71 of file Packet32.c. Referenced by PacketOpenAdapter(), and PacketStopDriver(). |
|
Definition at line 72 of file Packet32.c. Referenced by PacketInstallDriver(), and PacketOpenAdapter(). |
|
Title of error windows.
Definition at line 33 of file Packet32.c. |
documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.