pcap_setfilter Subroutine

Purpose

Loads a filter program into a packet capture device.

Library

pcap Library (libpcap.a)

Syntax

#include <pcap.h>

int pcap_setfilter(pcap_t * p, struct bpf_program * fp);

Description

The pcap_setfilter subroutine is used to load a filter program into the packet capture device. This causes the capture of the packets defined by the filter to begin.

Parameters

Item Description
fp Points to a filter program as returned from the pcap_compile subroutine.
p Points to a packet capture descriptor returned from the pcap_open_offline or the pcap_open_live subroutine.

Return Values

Upon successful completion, the pcap_setfilter subroutine returns 0. If the pcap_setfilter subroutine is unsuccessful, -1 is returned. In this case, the pcap_geterr subroutine can be used to get the error text, and the pcap_perror subroutine can be used to display the text.