Main Page   Modules   Data Structures   File List   Data Fields   Globals  

Packet32.c File Reference

#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. More...

#define ODSEx(_x, _y)
 Macro to print debug data with the printf convention. The behavior differs depending on the debug level. More...


Functions

LONG PacketDumpRegistryKey (PCHAR KeyName, PCHAR FileName)
 Dumps a registry key to disk in text format. Uses regedit. More...

BOOL APIENTRY DllMain (HANDLE DllHandle, DWORD Reason, LPVOID lpReserved)
 The main dll function. More...

WCHAR * SChar2WChar (char *string)
 Converts an ASCII string to UNICODE. Uses the MultiByteToWideChar() system function. More...

BOOLEAN PacketSetMaxLookaheadsize (LPADAPTER AdapterObject)
 Sets the maximum possible lookahead buffer for the driver's Packet_tap() function. More...

BOOLEAN PacketSetReadEvt (LPADAPTER AdapterObject)
 Retrieves the event associated in the driver with a capture instance and stores it in an _ADAPTER structure. More...

BOOL PacketInstallDriver (SC_HANDLE ascmHandle, SC_HANDLE *srvHandle, TCHAR *driverPath)
 Installs the NPF device driver. More...

ULONG inet_addrU (const WCHAR *cp)
 Convert a Unicode dotted-quad to a 32-bit IP address. More...

PCHAR PacketGetVersion ()
 Returns a string with the dll version. More...

BOOLEAN PacketGetNetType (LPADAPTER AdapterObject, NetType *type)
 Returns information about the MAC type of an adapter. More...

BOOL PacketStopDriver ()
 Stops and unloads the WinPcap device driver. More...

LPADAPTER PacketOpenAdapter (LPTSTR AdapterName)
 Opens an adapter. More...

VOID PacketCloseAdapter (LPADAPTER lpAdapter)
 Closes an adapter. More...

LPPACKET PacketAllocatePacket (void)
 Allocates a _PACKET structure. More...

VOID PacketFreePacket (LPPACKET lpPacket)
 Frees a _PACKET structure. More...

VOID PacketInitPacket (LPPACKET lpPacket, PVOID Buffer, UINT Length)
 Initializes a _PACKET structure. More...

BOOLEAN PacketReceivePacket (LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
 Read data (packets or statistics) from the NPF driver. More...

BOOLEAN PacketSendPacket (LPADAPTER AdapterObject, LPPACKET lpPacket, BOOLEAN Sync)
 Sends one (or more) copies of a packet to the network. More...

INT PacketSendPackets (LPADAPTER AdapterObject, PVOID PacketBuff, ULONG Size, BOOLEAN Sync)
 Sends a buffer of packets to the network. More...

BOOLEAN PacketSetMinToCopy (LPADAPTER AdapterObject, int nbytes)
 Defines the minimum amount of data that will be received in a read. More...

BOOLEAN PacketSetMode (LPADAPTER AdapterObject, int mode)
 Sets the working mode of an adapter. More...

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. More...

BOOLEAN PacketSetDumpLimits (LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks)
 Set the dump mode limits. More...

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. More...

HANDLE PacketGetReadEvent (LPADAPTER AdapterObject)
 Returns the notification event associated with the read calls on an adapter. More...

BOOLEAN PacketSetNumWrites (LPADAPTER AdapterObject, int nwrites)
 Sets the number of times a single packet written with PacketSendPacket() will be repeated on the network. More...

BOOLEAN PacketSetReadTimeout (LPADAPTER AdapterObject, int timeout)
 Sets the timeout after which a read on an adapter returns. More...

BOOLEAN PacketSetBuff (LPADAPTER AdapterObject, int dim)
 Sets the size of the kernel-level buffer associated with a capture. More...

BOOLEAN PacketSetBpf (LPADAPTER AdapterObject, struct bpf_program *fp)
 Sets a kernel-level packet filter. More...

BOOLEAN PacketGetStats (LPADAPTER AdapterObject, struct bpf_stat *s)
 Returns a couple of statistic values about the current capture session. More...

BOOLEAN PacketGetStatsEx (LPADAPTER AdapterObject, struct bpf_stat *s)
 Returns statistic values about the current capture session. Enhanced version of PacketGetStats(). More...

BOOLEAN PacketRequest (LPADAPTER AdapterObject, BOOLEAN Set, PPACKET_OID_DATA OidData)
 Performs a query/set operation on an internal variable of the network card driver. More...

BOOLEAN PacketSetHwFilter (LPADAPTER AdapterObject, ULONG Filter)
 Sets a hardware filter on the incoming packets. More...

BOOLEAN PacketGetAdapterNames (PTSTR pStr, PULONG BufferSize)
 Retrieve the list of available network adapters and their description. More...

BOOLEAN PacketGetNetInfoEx (LPTSTR AdapterName, npf_if_addr *buffer, PLONG NEntries)
 Returns comprehensive information the addresses of an adapter. More...

BOOLEAN PacketGetNetInfo (LPTSTR AdapterName, PULONG netp, PULONG maskp)
 Returns the IP address and the netmask of an adapter. More...


Variables

TCHAR szWindowTitle [] = TEXT("PACKET.DLL")
 Title of error windows. More...

SC_HANDLE scmHandle = NULL
SC_HANDLE srvHandle = NULL
LPCTSTR NPFServiceName = TEXT("NPF")
LPCTSTR NPFServiceDesc = TEXT("Netgroup Packet Filter")
LPCTSTR NPFDriverName = TEXT("\\npf.sys")
LPCTSTR NPFRegistryLocation = TEXT("SYSTEM\\CurrentControlSet\\Services\\NPF")
char PacketLibraryVersion [] = "2.3"
 Current packet.dll Version. It can be retrieved directly or through the PacketGetVersion() function. More...


Define Documentation

#define ODS _x   
 

Value:

{ \
    FILE *f; \
    f = fopen("winpcap_debug.txt", "a"); \
    fprintf(f, "%s", _x); \
    fclose(f); \
}
Macro to print a debug string. The behavior differs depending on the debug level.

Definition at line 44 of file Packet32.c.

Referenced by DllMain, PacketAllocatePacket, PacketGetAdapterNames, PacketGetNetType, PacketInstallDriver, PacketOpenAdapter, PacketSendPackets, PacketSetHwFilter, PacketSetMaxLookaheadsize, and PacketSetReadEvt.

#define ODSEx _x,
_y   
 

Value:

{ \
    FILE *f; \
    f = fopen("winpcap_debug.txt", "a"); \
    fprintf(f, _x, _y); \
    fclose(f); \
}
Macro to print debug data with the printf convention. The behavior differs depending on the debug level.

Definition at line 54 of file Packet32.c.

Referenced by PacketGetAdapterNames, PacketGetNetType, PacketInstallDriver, PacketOpenAdapter, and PacketRequest.

#define UNICODE   1
 

Definition at line 22 of file Packet32.c.


Function Documentation

BOOL APIENTRY DllMain HANDLE    DllHandle,
DWORD    Reason,
LPVOID    lpReserved
 

The main dll function.

Definition at line 83 of file Packet32.c.

References ODS, and PacketDumpRegistryKey.

ULONG inet_addrU const WCHAR *    cp
 

Convert a Unicode dotted-quad to a 32-bit IP address.

Parameters:
cp  A string containing the address.
Returns:
the converted 32-bit numeric address.
Doesn't check to make sure the address is valid.

Definition at line 274 of file Packet32.c.

References val.

Referenced by PacketGetNetInfo, and PacketGetNetInfoEx.

LONG PacketDumpRegistryKey PCHAR    KeyName,
PCHAR    FileName
 

Dumps a registry key to disk in text format. Uses regedit.

Parameters:
KeyName  Name of the ket to dump. All its subkeys will be saved recursively.
FileName  Name of the file that will contain the dump.
Returns:
If the function succeeds, the return value is nonzero.
For debugging purposes, we use this function to obtain some registry keys from the user's machine.

Definition at line 313 of file Packet32.c.

Referenced by DllMain.

BOOL PacketInstallDriver SC_HANDLE    ascmHandle,
SC_HANDLE *    srvHandle,
TCHAR *    driverPath
 

Installs the NPF device driver.

Parameters:
ascmHandle  Handle to the service control manager.
ascmHandle  A pointer to a handle that will receive the pointer to the driver's service.
driverPath  The full path of the .sys file to load.
Returns:
If the function succeeds, the return value is nonzero.
This function installs the driver's service in the system using the CreateService function.

Definition at line 224 of file Packet32.c.

References NPFServiceDesc, NPFServiceName, ODS, ODSEx, and srvHandle.

Referenced by PacketOpenAdapter.

BOOLEAN PacketSetMaxLookaheadsize LPADAPTER    AdapterObject
 

Sets the maximum possible lookahead buffer for the driver's Packet_tap() function.

Parameters:
AdapterObject  Handle to the service control manager.
Returns:
If the function succeeds, the return value is nonzero.
The lookahead buffer is the portion of packet that Packet_tap() can access from the NIC driver's memory without performing a copy. This function tries to increase the size of that buffer.

Definition at line 141 of file Packet32.c.

References ODS, PacketRequest, and PPACKET_OID_DATA.

Referenced by PacketOpenAdapter.

BOOLEAN PacketSetReadEvt LPADAPTER    AdapterObject
 

Retrieves the event associated in the driver with a capture instance and stores it in an _ADAPTER structure.

Parameters:
AdapterObject  Handle to the service control manager.
Returns:
If the function succeeds, the return value is nonzero.
This function is used by PacketOpenAdapter() to retrieve the read event from the driver by means of an ioctl call and set it in the _ADAPTER structure pointed by AdapterObject.

Definition at line 173 of file Packet32.c.

References _ADAPTER::hFile, ODS, pBIOCEVNAME, _ADAPTER::ReadEvent, and _ADAPTER::ReadTimeOut.

Referenced by PacketOpenAdapter.

WCHAR* SChar2WChar char *    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 122 of file Packet32.c.

Referenced by PacketGetNetInfo, PacketGetNetInfoEx, PacketOpenAdapter, and PacketSetDumpName.


Variable Documentation

LPCTSTR NPFDriverName = TEXT("\\npf.sys")
 

Definition at line 73 of file Packet32.c.

Referenced by PacketOpenAdapter.

LPCTSTR NPFRegistryLocation = TEXT("SYSTEM\\CurrentControlSet\\Services\\NPF")
 

Definition at line 74 of file Packet32.c.

Referenced by PacketOpenAdapter.

LPCTSTR NPFServiceDesc = TEXT("Netgroup Packet Filter")
 

Definition at line 72 of file Packet32.c.

Referenced by PacketInstallDriver.

LPCTSTR NPFServiceName = TEXT("NPF")
 

Definition at line 71 of file Packet32.c.

Referenced by PacketInstallDriver, PacketOpenAdapter, and PacketStopDriver.

SC_HANDLE scmHandle = NULL
 

Definition at line 69 of file Packet32.c.

Referenced by PacketOpenAdapter, and PacketStopDriver.

SC_HANDLE srvHandle = NULL
 

Definition at line 70 of file Packet32.c.

Referenced by PacketInstallDriver, and PacketOpenAdapter.

TCHAR szWindowTitle[] = TEXT("PACKET.DLL")
 

Title of error windows.

Definition at line 33 of file Packet32.c.

Referenced by PacketGetAdapterNames.


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