Packet Sniffer SDK VCL Edition

HNFileAdapter :: Methods :: CreateFile

 Previous Next

Creates a CAP file.

Syntax:

function CreateFile(FileName: String): DWORD;

Parameters:

FileName

[in] A path to a file.

Return values:

HNERR_OKCAP file opening has been completed successfully.
HNERR_INCOMPATIBLE_MODEIncompatible mode of HNFileAdapter. Occurs when HNFileAdapter.AutoMode was set, but HNQueue object was not predetermined (see HNFileAdapter.Queue).
HNERR_BAD_MEDIUM_TYPEImpossible adapter type is set for format of packets to be dumped to the CAP file.
HNERR_MEM_ALLOC_ERRORThe memory for the traffic processing is not allocated. This can happen either because of the insufficient operating system resources or in case of HNQueue component using (see HNQueue.AllocItems).
HNERR_UNKNOWN_FILE_FORMATUnknown CAP file format is set (see HNFileAdapter.CapFormat).
HNERR_OPEN_FILECAP file opening error.
HNERR_ADAPTER_THREAD_ERRPacket Sniffer SDK internal thread creation error.

Description:

Use CreateFile to create a new CAP file. If the function succeeds, you can begin to dump network traffic to the CAP file using HNFileAdapter.SyncSend and HNFileAdapter.SyncSendEx functions.

When HNFileAdapter object works in AutoMode using of HNFileAdapter.SyncSend and HNFileAdapter.SyncSendEx functions is impossible.

If HNFileAdapter.Queue property was set before the network adapter opening, and HNFileAdapter object Automode was set (see HNFileAdapter.AutoMode), then the traffic will be processed in the HNFileAdapter internal thread context together with HNQueue component. In this mode you also may use HNFileAdapter.SizeLimit property to set limitation for CAP file size.

On executing HNFileAdapter.CreateFile function HNFileAdapter component attempts to close the CAP file which was opened earlier. So, one instance of HNFileAdapter object can open only one CAP file.

If you need to open/create several CAP files simultaneously, you may create several HNFileAdapter objects with appropriate settings.

To read from existing CAP file please use HNFileAdapter.OpenFile function.

Example of dumping packets to a CAP file in HNFileAdpater AutoMode:

// OnFileClose event handler
procedure TForm1.HNFileAdapter1FileClose(Sender: TObject; ThParam: Pointer; Result: DWORD)
begin
    if Result = HNERR_FILE_SIZE_LIMIT then
    begin
      ...
    end;
end;
...
// Create HNAdapter object
HNAdapter1 := HNAdapter.Create(); 
// create HNQueue object
HNQueue1 := HNQueue.Create(); 
// Create HNFileAdapter object
HNFileAdapter1 = HNFileAdapter.Create(); 
...
// Set HNQueue object for HNAdapter and HNFileAdapter
HNAdapter1.ReceiveQueue := HNQueue1.Handle;
HNFileAdapter1.Queue := HNQueue1.Handle;

// HNFileAdapter additional settings
HNFileAdapter1.AutoMode := TRUE;
HNFileAdapter1.SizeLimit := 1000000;
HNFileAdapter1.OnFileClose := TForm1.HNFileAdapter1FileClose;

// Create CAP file
Res := HNFileAdapter1.CreateFile("packets.cap");
...
// Start queue internal thread
Res := HNQueue1.Start(hQue);
...
// Open network adapter
Res := HNAdapter.OpenAdapter(hAdp);
...
See also:HNFileAdapter, HNQueue, HNFileAdapter.Queue, HNFileAdapter.AutoMode, HNFileAdapter.SyncSend, HNFileAdapter.SyncSendEx, HNFileAdapter.OpenFile