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

Packet32.c File Reference

#include <stdio.h>
#include <packet32.h>
#include "wanpacket/wanpacket.h"
#include <windows.h>
#include <windowsx.h>
#include <Iphlpapi.h>
#include <IPIfCons.h>
#include <ntddndis.h>

Go to the source code of this file.

Defines

#define UNICODE   1

Typedefs

typedef VOID(* GAAHandler )(ULONG, DWORD, PVOID, PIP_ADAPTER_ADDRESSES, PULONG)

Functions

BOOLEAN PacketAddAdapterDag (PCHAR name, PCHAR description, BOOLEAN IsAFile)
BOOL APIENTRY DllMain (HANDLE DllHandle, DWORD Reason, LPVOID lpReserved)
 The main dll function.

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

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.

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.

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

BOOL PacketGetFileVersion (LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen)
 Returns the version of a dll or exe file.

LPADAPTER PacketOpenAdapterNPF (PCHAR AdapterName)
 Opens an adapter using the NPF device driver.

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

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.


Variables

char PacketLibraryVersion [64]
 Current packet.dll Version. It can be retrieved directly or through the PacketGetVersion() function.

char PacketDriverVersion [64]
 Current NPF.sys Version. It can be retrieved directly or through the PacketGetVersion() function.

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")
PADAPTER_INFO AdaptersInfoList
HANDLE AdaptersInfoMutex
GAAHandler GetAdaptersAddressesPointer = NULL


Define Documentation

#define UNICODE   1
 

Definition at line 22 of file Packet32.c.


Typedef Documentation

typedef VOID(* GAAHandler)(ULONG, DWORD, PVOID, PIP_ADAPTER_ADDRESSES, PULONG)
 

Definition at line 53 of file Packet32.c.

Referenced by DllMain().


Function Documentation

BOOL APIENTRY DllMain HANDLE  DllHandle,
DWORD  Reason,
LPVOID  lpReserved
 

The main dll function.

Definition at line 85 of file Packet32.c.

References AdaptersInfoList, AdaptersInfoMutex, GAAHandler, GetAdaptersAddressesPointer, _ADAPTER_INFO::NetworkAddresses, _ADAPTER_INFO::Next, ODS, PacketDriverVersion, PacketDumpRegistryKey(), PacketGetFileVersion(), and PacketLibraryVersion.

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 194 of file Packet32.c.

BOOLEAN PacketAddAdapterDag PCHAR  name,
PCHAR  description,
BOOLEAN  IsAFile
 

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 433 of file Packet32.c.

References ODS, ODSEx, and WChar2SChar().

Referenced by DllMain().

BOOL PacketInstallDriver SC_HANDLE  ascmHandle,
SC_HANDLE *  srvHandle
 

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.
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 353 of file Packet32.c.

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

Referenced by PacketOpenAdapterNPF().

LPADAPTER PacketOpenAdapterNPF PCHAR  AdapterName  ) 
 

Opens an adapter using the NPF device driver.

Parameters:
AdapterName A string containing the name of the device to open.
Returns:
If the function succeeds, the return value is the pointer to a properly initialized ADAPTER object, otherwise the return value is NULL.
Note:
internal function used by PacketOpenAdapter() and AddAdapter()

Definition at line 526 of file Packet32.c.

References ADAPTER, ADAPTER_NAME_LENGTH, _ADAPTER::hFile, MAX_LINK_NAME_LENGTH, _ADAPTER::Name, NPFRegistryLocation, NPFServiceName, _ADAPTER::NumWrites, ODS, ODSEx, PacketInstallDriver(), PacketSetMaxLookaheadsize(), PacketSetReadEvt(), scmHandle, srvHandle, and _ADAPTER::SymbolicLink.

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 272 of file Packet32.c.

References ODS, PacketRequest(), and PPACKET_OID_DATA.

Referenced by PacketOpenAdapterNPF().

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 304 of file Packet32.c.

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

Referenced by PacketOpenAdapterNPF().

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 228 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 244 of file Packet32.c.

Referenced by PacketGetFileVersion(), PacketGetNetInfoEx(), and PacketOpenAdapter().


Variable Documentation

PADAPTER_INFO AdaptersInfoList
 

Definition at line 50 of file Packet32.c.

Referenced by DllMain(), and PacketGetAdapterNames().

HANDLE AdaptersInfoMutex
 

Definition at line 51 of file Packet32.c.

Referenced by DllMain(), PacketGetAdapterNames(), PacketGetNetInfoEx(), PacketGetNetType(), and PacketOpenAdapter().

GAAHandler GetAdaptersAddressesPointer = NULL
 

Definition at line 59 of file Packet32.c.

Referenced by DllMain().

LPCTSTR NPFDriverPath = TEXT("system32\\drivers\\npf.sys")
 

Definition at line 48 of file Packet32.c.

Referenced by PacketInstallDriver().

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

Definition at line 47 of file Packet32.c.

Referenced by PacketOpenAdapterNPF().

LPCTSTR NPFServiceDesc = TEXT("Netgroup Packet Filter")
 

Definition at line 46 of file Packet32.c.

Referenced by PacketInstallDriver().

LPCTSTR NPFServiceName = TEXT("NPF")
 

Definition at line 45 of file Packet32.c.

Referenced by PacketInstallDriver(), PacketOpenAdapterNPF(), and PacketStopDriver().

char PacketDriverVersion[64]
 

Current NPF.sys Version. It can be retrieved directly or through the PacketGetVersion() function.

Definition at line 40 of file Packet32.c.

Referenced by DllMain(), and PacketGetDriverVersion().

char PacketLibraryVersion[64]
 

Current packet.dll Version. It can be retrieved directly or through the PacketGetVersion() function.

Definition at line 38 of file Packet32.c.

Referenced by DllMain(), and PacketGetVersion().

SC_HANDLE scmHandle = NULL
 

Definition at line 43 of file Packet32.c.

Referenced by PacketOpenAdapterNPF(), and PacketStopDriver().

SC_HANDLE srvHandle = NULL
 

Definition at line 44 of file Packet32.c.

Referenced by PacketInstallDriver(), and PacketOpenAdapterNPF().


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