Packet Sniffer SDK DLL Edition

HNUserFilter :: Methods :: BpfCompileBPFAsmFromFile

 Previous Next

Compiles the BPF filtering program written in BPF assembler from a specified file.

Syntax:

DWORD __stdcall BpfCompileBPFAsmFromFile(HANDLE hFtr, LPCTSTR FileName);

Parameters:

hFtr

[in] HNUserFilter object handle.

FileName

[in] BPF assembler source text file name.

Return values:

HNERR_OKNo errors.
HNERR_LOAD_FILE_ERRORFile opening error;
HNERR_ERRORErrors occured during the compilation. To track errors use OnBPFAsmError handler.

Description:

This function compiles the program written in BPF assembler to BPF filter. The definitions of the constants previously loaded by BpfCompileBPFDefinesFromFile and BpfCompileBPFDefinesFromStr functions may be used in the program.

Below there is an example of a file of a program in BPF assembler for IP traffic filtering.

#define IP_PROTO   0x800  
     ld   P[12:2]            // A = WORD offset 12 (protocol in Ethernet header)
     jeq  IP_PROTO, 0, Exit  // If A <> 0x800 (IP) - exit
     ret  -1                 // Exit, it is IP packet - return TRUE
Exit:
     ret  0                  // Exit, it is not IP packet - return FALSE

Requirements:

Unicode

Implemented as BpfCompileBPFAsmFromFileW (Unicode) and BpfCompileBPFAsmFromFileA (ANSI).

See also:HNUserFilter, OnBPFAsmError, BPF instructions, BPF Assembler