Packet Sniffer SDK VCL Edition

HNFileAdapter :: Methods :: Get_NextPacket

 Previous Next

Retrieve next packet from CAP file opened for reading.

Syntax:

function Get_NextPacket(hPkt: Pointer) : DWORD;

Parameters:

hPkt

[in, out] The handle of the HNPacket object.

Return values:

HNERR_OKCAP file opening has been completed successfully.
HNERR_ADAPTER_NOT_OPENEDCAP file has not been opened, see the HNFileAdapter.OpenFile function.
HNERR_ADDR_ERRhPkt has the wrong value (a memory write error).
HNERR_INCOMPATIBLE_MODEIncompatible mode of HNFileAdapter. Occurs when HNFileAdapter.AutoMode was set, or if the CAP file was opened for data writing (see HNFileAdapter.CreateFile function).
HNERR_READ_FILEFile read error.
HNERR_BAD_PACKET_LENHNPacket.IncPacketSize property for hPkt parameter is set incorrectly.
HNERR_EOFEnd of CAP file.

Description:

Use this function to get access to the packets stored in a CAP file. This function may be called only after successfull call of the HNFileAdapter.OpenFile function.

If you already read packets from certain file, and need to read the first packet, please use HNFileAdapter.RewindFile.

Example of reading packets from CAP file using Get_NextPacket function:

// Create HNPacket object
HNPacket1 := HNPacket.Create(); 
HNPacket1.Handle := HNPacket1.AllocatePacket(1514);

// Open CAP file
Res = HNFileAdapter1.OpenFile("packets.cap");
...
repeat 
      
   // Read packet from file
   Res = HNFileAdapter1.Get_NextPacket(hPkt);
   
   // Getting access to the HNPacket properties and functions
   ... 
 
until Res = HNERR_OK;
See also:HNFileAdapter, HNFileAdapter.OpenFile, HNFileAdapter.RewindFile, HNPacket, HNPacket.IncPacketSize