📄 packet32.pas
字号:
{ Magenta Systems Internet Packet Monitoring Components
********************************************************************************
--------------------------------------------------------------------------------
API for the
Packet Capture Driver by Politecnico di Torino
Converted By Lars Peter Christiansen
--------------------------------------------------------------------------------
TERMS AND CONDITIONS OF USE.
some parts of this software is Copyright(C) 2000 Lars Peter Christiansen.
The author of this software assumes no liability for damages caused under
any circumstances whatsoever, and is under no obligation. Use of the software
indicates acceptance of all conditions contained in this document. If you do
not agree to these terms, you must delete this software immediately.
You may distribute the archive in which this software is distributed, but
under no circumstances must this archive be changed. Distributing a modified
archive is a violation of the software license.
If you do redistribute this software, please let me know at the email address
given below.
If you have any questions, requests, bug reports, etc., please contact me at
the address given below.
Lars Peter Christiansen
Email : lp@nzlab.dk
Website: http://www.nzlab.dk
Packet32.dll author:
old website: http://netgroup-serv.polito.it/windump
new website: http://www.winpcap.org/
Updated by Angus Robertson, Magenta Systems Ltd, England, 29th October 2005
delphi@magsys.co.uk, http://www.magsys.co.uk/delphi/
Some parts Copyright Magenta Systems Ltd
--------------------------------------------------------------------------------
Original Filename : Packet32.pas
Packet.dll written in C.
PacketOpenAdapter
PacketCloseAdapter
PacketResetAdapter
PacketGetAdapterNames
PacketSetBuff
PacketSetBpf
PacketSetHwFilter
PacketGetNetType
PacketGetStats
PacketAllocatePacket
PacketFreePacket
PacketSendPacket
PacketRecievePacket
PacketWaitPacket
PacketRequest
PacketGetDriverVersion
PacketGetVersion
PacketGetNetInfoEx
PacketSetMinToCopy
PacketSetSnapLen
********************************************************************************
CHANGES :
29 October 2005 - Angus Robertson, Magenta Systems Ltd
replaced static linkage with dynamic DLL loading
added new winpcap website
added PacketGetDriverVersion, PacketGetVersion, PacketGetNetInfoEx
added PacketSetMinToCopy, PacketSetSnapLen
tested with 3.1 final release 5th August 2005
17 January 2002 : - Added "PacketSetReadTimeout()".
- Corrected TPacket. Thanks to Deheng Xu.
20 November 2000 : TPacket Modified. No longer delivers faulty packets.
Thanks to Pol-Brieuc Lem閠ayer.
Email : pol-brieuc.lemetayer@eleve.emn.fr
}
unit Packet32;
interface
uses Windows, // OVERLAPPED syncronization structure
winsock,
bpf; // Needs bpf structures
Const
DLL = 'packet.dll'; // Name of DLL file
DEFAULT_DRIVERBUFFER = 1000000; // Dimension of the buffer in driver
MAX_LINK_NAME_LENGTH = 64; // Adapters symbolic names maximum length
type
// Adapter with which the driver communicates
Padapter = ^Tadapter;
Tadapter = packed Record
hFile : LongWord;
SymbolicLink : array [0..MAX_LINK_NAME_LENGTH-1] of char;
end;
// Packet the driver uses as means of data transport.
// both snooped data and certain device controlling
Ppacket = ^Tpacket;
Tpacket = packed record // Changed Jan.1 2002. Thanks to Deheng Xu
hevent :Thandle;
OverLapped :TOVERLAPPED;
Buffer :Pointer;
//Next :Pointer; // also commented out in "packet32.h"
Length :Longword;
ulBytesReceived :LongWord;
bIoComplete :Boolean;
end;
// [Gotten from LIBPCAP\ntddpack.h]
// Data structure to control the device driver
PPACKET_OID_DATA = ^TPACKET_OID_DATA;
TPACKET_OID_DATA = packed record
Oid : LongWord; // Device control code
Length: LongWord; // Length of data field
Data : Pointer; // Start of data field
end;
// [Gotten from BPF.h? - more appropiate here!]
Pnet_type = ^Tnet_type;
Tnet_type = packed record
LinkType,
LinkSpeed : LongWord;
end;
// from winsock2.h
// Portable socket structure (RFC 2553).
// Desired design of maximum size and alignment.
// These are implementation specific.
const
_SS_MAXSIZE = 128; // Maximum size.
{$EXTERNALSYM _SS_MAXSIZE}
_SS_ALIGNSIZE = SizeOf(Int64); // Desired alignment.
{$EXTERNALSYM _SS_ALIGNSIZE}
// Definitions used for sockaddr_storage structure paddings design (holds both ip4 and ip6 addresses)
_SS_PAD1SIZE = _SS_ALIGNSIZE - SizeOf(short);
{$EXTERNALSYM _SS_PAD1SIZE}
_SS_PAD2SIZE = _SS_MAXSIZE - (SizeOf(short) + _SS_PAD1SIZE + _SS_ALIGNSIZE);
{$EXTERNALSYM _SS_PAD2SIZE}
type
sockaddr_storage = record
ss_family: short; // Address family.
__ss_pad1: array [0.._SS_PAD1SIZE - 1] of char; // 6 byte pad, this is to make
// implementation specific pad up to
// alignment field that follows explicit
// in the data structure.
__ss_align: Int64; // Field to force desired structure.
__ss_pad2: array [0.._SS_PAD2SIZE - 1] of char; // 112 byte pad to achieve desired size;
// _SS_MAXSIZE value minus size of
// ss_family, __ss_pad1, and
// __ss_align fields is 112.
end;
{$EXTERNALSYM sockaddr_storage}
TSockAddrStorage = sockaddr_storage;
PSockAddrStorage = ^sockaddr_storage;
// from packet32.h - used by PacketGetNetInfoEx for 3.1 and later
Pnpf_if_addr = ^Tnpf_if_addr ;
Tnpf_if_addr = packed record
IPAddress: TSockAddrStorage ; // includes IP4 and IP6 addresses
SubnetMask: TSockAddrStorage ;
Broadcast: TSockAddrStorage ;
end ;
// from packet32.h - used by PacketGetNetInfoEx for 3.0 and earlier
Pnpf_if_addr30 = ^Tnpf_if_addr30 ;
Tnpf_if_addr30 = packed record
IPAddress: TSockAddrIn ;
SubnetMask: TSockAddrIn ;
Broadcast: TSockAddrIn ;
end ;
var
//------------------------------------------------------------------------------
//ULONG PacketGetAdapterNames(PTSTR pStr, PULONG BufferSize)
//------------------------------------------------------------------------------
PacketGetAdapterNames: Function (pStr: pchar; BufferSize: PLongWord) : Boolean; cdecl ;
{
This is the first function that must be used to communicate with the driver.
It returns the names of the adapters installed in the system through the user
allocated buffer pStr. BufferSize is the length of the buffer.
Warning: the result of this function is obtained querying directly the registry,
therefore the format of the result in Windows NT is different from the one in
Windows 95/98. This is due to the fact that Windows 95 uses the ASCII
encoding method to store a string, while Windows NT uses UNICODE. After a
call to PacketGetAdapterNames in Windows 95, pStr contains an ASCII string
with the names of the adapters separated by ASCII "\0". The string is
terminated by a double "\0". In Windows NT, pStr contains a UNICODE string
with the names of the adapters separated by a "\0" UNICODE character
(i.e. 2 ASCII "\0"), and the string ends with a double UNICODE "\0".
Angus - above warning only relates to WinPcap 3.0 and earlier
with WinPcap 3.1 and later only ASCII is returned
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:
1 a variable number of ASCII (Unicode for 3.0 and earlier) strings, each with the
names of an adapter, separated by a "\0"
2 a double "\0"
3 a number of ASCII strings (for all versions), each with the description of an
adapter, separated by a "\0". The number of descriptions is the same of the one
of names. The fisrt description corresponds to the first name, and so on.
4 a double "\0".
}
//------------------------------------------------------------------------------
// LPADAPTER PacketOpenAdapter(LPTSTR AdapterName)
//------------------------------------------------------------------------------
PacketOpenAdapter: Function (AdapterName:Pchar) : PAdapter; cdecl ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -