[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

pcap_compile Subroutine


Compiles a filter expression into a filter program.


pcap Library (libpcap.a)


#include <pcap.h>

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


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.


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.

Related Information

The pcap_geterr (pcap_geterr Subroutine) subroutine, pcap_lookupnet (pcap_lookupnet Subroutine) subroutine, pcap_open_live (pcap_open_live Subroutine) subroutine, pcap_open_offline (pcap_open_offline Subroutine) subroutine, pcap_perror (pcap_perror Subroutine) subroutine, pcap_setfilter (pcap_setfilter Subroutine) subroutine.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]