Packet Sniffer SDK DLL Edition

HNFileAdapter :: Methods :: FAdpOpenFile

 Previous Next

Opens the CAP file.

Syntax:

DWORD __stdcall FAdpOpenFile(HANDLE hFAdp, LPCTSTR FileName);

Parameters:

hFAdp

[in] HNFileAdapter object handle.

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 [Get/Set]), but HNQueue object was not predetermined (see HNFileAdapter.Queue [Get/Set]).
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 QueAllocItems).
HNERR_OPEN_FILECAP file opening error.
HNERR_READ_FILEFile reading error.
HNERR_BAD_FILE_FORMATUnknown CAP file format.
HNERR_FORMAT_VERThis version of CAP file is not supported.
HNERR_BAD_MEDIUM_TYPEThe adapter type, in format of which packets was dumped to CAP file, is not supported.
HNERR_ADAPTER_THREAD_ERRPacket Sniffer SDK internal thread creating error.
HNERR_INVALID_HANDLEhFAdp parameter is not the HNFileAdapter object handle.

Description:

Use FAdpOpenFile to open an existing CAP file. If the function succeeds, you can begin to dump network traffic to this CAP file using FAdpGetNextPacket function.

When HNFileAdapter object works in AutoMode using of FAdpGetNextPacket function is impossible.

If HNFileAdapter.Queue property [Get/Set] was set before the network adapter opening, and HNFileAdapter object Automode was set (see HNFileAdapter.AutoMode [Get/ Set]), then the traffic will be processed in the HNFileAdapter internal thread context together with HNQueue component.

Also you may gather traffic statistics and filter CAP file content if you're using BPF filter (see. HNFileAdapter.UserFilter [Get/Set], FAdpGetRecvCount, FAdpGetAcceptCount, FAdpGetRejectCount, FAdpGetProcessCount).

On executing FAdpOpenFile 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 create a new CAP file please use FAdpCreateFile function.

Example of using HNFileAdpater object AutoMode for reading packets from the first CAP file and dumping packets to the second CAP file:

// OnFileClose event handler
void __stdcall OnFileClose(DWORD_PTR Param, DWORD_PTR ThParam, DWORD Result)
{
    if (Result == HNERR_FILE_SIZE_LIMIT)
    {
      ...
    }
}
...
// Create the first HNFileAdapter object
HANDLE hFAdp1 = FAdpCreate(); 
// Create the second HNFileAdapter object
HANDLE hFÀdp2 = FAdpCreate(); 
// Create HNQueue object
HANDLE hQue = QueCreate(); 
...
// Set HNQueue object to HNFileAdapter objects
FAdpSetQueue(hFAdp1, hQue);
FAdpSetQueue(hFAdp2, hQue);

// HNFileAdapter additional settings
FAdpSetAutoMode(hFAdp1, TRUE);
FAdpSetAutoMode(hFAdp2, TRUE);

FAdpSetSizeLimit(hFAdp1, 1000000);
FAdpSetOnFileClose(hFAdp1, OnFileClose, 0);

// Create CAP file
DWORD Res = FAdpCreateFile(hFAdp1, "packets2.cap");
...
// Start internal queue thread
Res = QueStart(hQue);
...
// Open CAP file
Res = FAdpOpenFile(hFAdp2, "packets1.cap");
...

Requirements:

Unicode

Implemented as FAdpOpenFileW (Unicode) and FAdpOpenFileA (ANSI).

See also:HNFileAdapter, HNQueue, FAdpGetQueue, FAdpSetQueue, FAdpGetAutoMode, FAdpSetAutoMode, FAdpGetUserFilter, FAdpSetUserFilter, FAdpGetRecvCount, FAdpGetAcceptCount, FAdpGetRejectCount, FAdpGetProcessCount FAdpCreateFile