pcap_compile Subroutine

Purpose

Compiles a filter expression into a filter program.

Library

pcap Library (libpcap.a)

Syntax

#include <pcap.h>

int pcap_compile(pcap_t * p, struct bpf_ program *fp, char * str,
int
  optimize, bpf_u_int32  netmask);

Description

The pcap_compile subroutine is used to compile the string str into a filter program. This filter program will then be used to filter, or select, the desired packets.

Parameters

Item Description
netmask Specifies the netmask of the network device. The netmask can be obtained from the pcap_lookupnet subroutine.
optimize Controls whether optimization on the resulting code is performed.
p Points to a packet capture descriptor returned from the pcap_open_offline or the pcap_open_live subroutine.
program Points to a bpf_program struct which will be filled in by the pcap_compile subroutine if the subroutine is successful.
str Contains the filter expression.

Return Values

Upon successful completion, the pcap_compile subroutine returns 0, and the program parameter will hold the filter program. If pcap_compile subroutine is unsuccessful, -1 is returned.