{****************************************************************************
** **
** PSSDK HNPacket module **
** Copyright (c) 1997 - 2007 microOLAP Technologies LTD, **
** Khalturin A.P., Naumov D.A. **
** **
****************************************************************************}
unit HNPacket;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
HNPSManager, HNPsSdkDef;
type
//---------------------------------------------------------------------------
// Class THNPacket
//---------------------------------------------------------------------------
THNPacket = class
private
hPkt : Pointer;
private
//---------------------------------------------------------------------------
// Add in 2.2
function GetMediumType: DWORD;
procedure SetMediumType(MediumType: DWORD);
function GetUserData: Pointer;
procedure SetUserData(UserData : Pointer);
function GetMaxPacketSize: DWORD;
function GetPacketSize: DWORD;
procedure SetPacketSize(PacketSize: DWORD);
function GetIncPacketSize: DWORD;
procedure SetIncPacketSize(IncPacketSize: DWORD);
function GetPacketData: Pointer;
//---------------------------------------------------------------------------
// Add in 3.2
function GetMark: DWORD;
procedure SetMark(Value: DWORD);
public
constructor Create();
destructor Destroy(); override;
function IsValid: BOOL;
function InetCheckSum(pData: Pointer; Length: DWORD): WORD;
function TransportCheckSum(pPacket: Pointer; PacketLen: DWORD; Proto: DWORD; SrcIP : DWORD; DstIP : DWORD): WORD;
function IPGenerate(pIPPacket: Pointer; PacketLen : DWORD; Proto : DWORD; SrcIP : DWORD; DstIP : DWORD): DWORD;
function UDPGenerate(pUDPPacket: Pointer; PacketLen : DWORD; SrcPort : WORD; DstPort : WORD): DWORD;
function TCPGenerate(pTCPPacket: Pointer; SrcPort: WORD; DstPort: WORD; Seq: DWORD; Ack: DWORD; Win: WORD): DWORD;
//---------------------------------------------------------------------------
// Add in 2.2
property Handle: Pointer read hPkt write hPkt;
function AllocatePacket(MaxPacketSize: DWORD): Pointer;
function FreePacket(hPacket: Pointer): DWORD;
property MediumType: DWORD read GetMediumType write SetMediumType;
property UserData: Pointer read GetUserData write SetUserData;
property MaxPacketSize: DWORD read GetMaxPacketSize;
property PacketSize: DWORD read GetPacketSize write SetPacketSize;
property IncPacketSize: DWORD read GetIncPacketSize write SetIncPacketSize;
property PacketData: Pointer read GetPacketData;
function Get_Id(HiValue: PUINT): UINT;
function Set_Id(LowPart : DWORD; HiPart : DWORD): DWORD;
function Get_TimeStamp(HiValue: PUINT): UINT;
function Set_TimeStamp(LowPart : DWORD; HiPart : DWORD): DWORD;
function CopyToPacket(hPacket: Pointer): DWORD;
function CopyFromPacket(hPacket: Pointer): DWORD;
//---------------------------------------------------------------------------
// Add in 3.2
property Mark: DWORD read GetMark write SetMark;
published
end;
implementation
{$INCLUDE 'HNPsSdkFun.pas'}
//---------------------------------------------------------------------------
// Create - Creates the HNPacket object.
//---------------------------------------------------------------------------
constructor THNPacket.Create();
begin
hPkt := nil;
end;
//---------------------------------------------------------------------------
// Destroy - Destroys the HNPacket object
//---------------------------------------------------------------------------
destructor THNPacket.Destroy();
begin
end;
//---------------------------------------------------------------------------
// v2.2 - Method - IsValid - Checks if the HNPacket object has been created correctly.
//---------------------------------------------------------------------------
function THNPacket.IsValid: BOOL;
begin
Result := (hPkt <> nil);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - AllocatePacket - Creates the HNPacket object.
//---------------------------------------------------------------------------
function THNPacket.AllocatePacket(MaxPacketSize: DWORD): Pointer;
begin
Result := PktCreate(MaxPacketSize);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - FreePacket - Destroys the HNPacket object.
//---------------------------------------------------------------------------
function THNPacket.FreePacket(hPacket: Pointer): DWORD;
begin
Result := PktDestroy(hPacket);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - MediumType - Returns the network adapter type.
//---------------------------------------------------------------------------
function THNPacket.GetMediumType(): DWORD;
begin
Result := PktGetMediumType(hPkt);
end;
//---------------------------------------------------------------------------
// v2.3 - Property - MediumType - Sets the network adapter type.
//---------------------------------------------------------------------------
procedure THNPacket.SetMediumType(MediumType : DWORD);
begin
PktSetMediumType(hPkt,MediumType);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - UserData - Returns the value definded by the user, and associated with this packet.
//---------------------------------------------------------------------------
function THNPacket.GetUserData(): Pointer;
begin
Result := PktGetUserData(hPkt);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - UserData - Sets the value definded by the user, and associated with this packet.
//---------------------------------------------------------------------------
procedure THNPacket.SetUserData(UserData : Pointer);
begin
PktSetUserData(hPkt,UserData);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - MaxPacketSize - Returns the size of the buffer allocated for packet data.
//---------------------------------------------------------------------------
function THNPacket.GetMaxPacketSize(): DWORD;
begin
Result := PktGetMaxPacketSize(hPkt);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - PacketSize - Returns the actual size of the packet received by PSSDK internal driver.
//---------------------------------------------------------------------------
function THNPacket.GetPacketSize(): DWORD;
begin
Result := PktGetPacketSize(hPkt);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - PacketSize - Sets the actual size of the packet received by PSSDK internal driver.
//---------------------------------------------------------------------------
procedure THNPacket.SetPacketSize(PacketSize: DWORD);
begin
PktSetPacketSize(hPkt,PacketSize);
end;
//---------------------------------------------------------------------------
// v2.2 - Property - IncPacketSize - Returns the size of the packet's data sent by PSSDK driver to the user application.
//---------------------------------------------------------------------------
function THNPacket.GetIncPacketSize(): DWORD;
begin
Result := PktGetIncPacketSize(hPkt)
end;
//---------------------------------------------------------------------------
// v2.3 - Property - IncPacketSize - Sets the size of the packet's data sent by PSSDK driver to the user application.
//---------------------------------------------------------------------------
procedure THNPacket.SetIncPacketSize(IncPacketSize : DWORD);
begin
PktSetIncPacketSize(hPkt,IncPacketSize)
end;
//---------------------------------------------------------------------------
// v2.2 - Property - PacketData - Returns the pointer to the packet data.
//---------------------------------------------------------------------------
function THNPacket.GetPacketData(): Pointer;
begin
Result := PktGetPacketData(hPkt);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - Get_Id - Returns the packet number.
//---------------------------------------------------------------------------
function THNPacket.Get_Id(HiValue: PUINT): UINT;
begin
Result := PktGetId(hPkt,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// v2.3 - Method - Set_Id - Sets the packet number.
//---------------------------------------------------------------------------
function THNPacket.Set_Id(LowPart : DWORD; HiPart : DWORD): DWORD;
begin
Result := PktSetId(hPkt,LowPart,HiPart);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - Get_TimeStamp - Returns the time of the packet receiving.
//---------------------------------------------------------------------------
function THNPacket.Get_TimeStamp(HiValue: PUINT): UINT;
begin
Result := PktGetTimeStamp(hPkt,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// v2.3 - Method - Set_TimeStamp - Sets the time of the packet receiving.
//---------------------------------------------------------------------------
function THNPacket.Set_TimeStamp(LowPart : DWORD; HiPart : DWORD): DWORD;
begin
Result := PktSetTimeStamp(hPkt,LowPart,HiPart);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - CopyToPacket - Copies current packet to another one.
//---------------------------------------------------------------------------
function THNPacket.CopyToPacket(hPacket: Pointer): DWORD;
begin
Result := PktCopyPacketToPacket(hPacket,hPkt);
end;
//---------------------------------------------------------------------------
// v2.2 - Method - CopyFromPacket - Copies arbitrary packet to the current one.
//---------------------------------------------------------------------------
function THNPacket.CopyFromPacket(hPacket: Pointer): DWORD;
begin
Result := PktCopyPacketToPacket(hPkt,hPacket);
end;
//---------------------------------------------------------------------------
// Method - InetCheckSum - Counts the IP packets checksum.
//---------------------------------------------------------------------------
function THNPacket.InetCheckSum(pData: Pointer; Length: DWORD): WORD;
begin
Result := PktInetCheckSum(pData,Length);
end;
//---------------------------------------------------------------------------
// Method - TransportCheckSum - Counts the TCP and UDP packets checksums.
//---------------------------------------------------------------------------
function THNPacket.TransportCheckSum(pPacket: Pointer; PacketLen: DWORD; Proto: DWORD; SrcIP : DWORD; DstIP : DWORD): WORD;
begin
Result := PktTransportCheckSum(pPacket,PacketLen,Proto,SrcIP,DstIP);
end;
//---------------------------------------------------------------------------
// Method - IPGenerate - Creates an IP packet.
//---------------------------------------------------------------------------
function THNPacket.IPGenerate(pIPPacket: Pointer; PacketLen : DWORD; Proto : DWORD; SrcIP : DWORD; DstIP : DWORD): DWORD;
begin
Result := PktIPGenerate(pIPPacket,PacketLen,Proto,SrcIP,DstIP);
end;
//---------------------------------------------------------------------------
// Method - UDPGenerate - Creates a UDP packet.
//---------------------------------------------------------------------------
function THNPacket.UDPGenerate(pUDPPacket: Pointer; PacketLen : DWORD; SrcPort : WORD; DstPort : WORD): DWORD;
begin
Result := PktUDPGenerate(pUDPPacket,PacketLen,SrcPort,DstPort);
end;
//---------------------------------------------------------------------------
// Method - TCPGenerate - Creates a TCP packet.
//---------------------------------------------------------------------------
function THNPacket.TCPGenerate(pTCPPacket: Pointer; SrcPort: WORD; DstPort: WORD; Seq: DWORD; Ack: DWORD; Win: WORD): DWORD;
begin
Result := PktTCPGenerate(pTCPPacket,SrcPort,DstPort,Seq,Ack,Win);
end;
//---------------------------------------------------------------------------
// Add in 3.2 - Property - Mark - Return value of the packet mark, which was set for this packet by BPF filter.
//---------------------------------------------------------------------------
function THNPacket.GetMark: DWORD;
begin
Result := PktGetMark(hPkt);
end;
//---------------------------------------------------------------------------
// Add in 3.2 - Property - Mark - Set mark for a packet.
//---------------------------------------------------------------------------
procedure THNPacket.SetMark(Value: DWORD);
begin
PktSetMark(hPkt,Value);
end;
end.