---
name: "pcap_setfilter"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/pcap_setfilter"
---

# pcap\_setfilter(3)

set the filter

## NAME

pcap\_setfilter - set the filter

## SYNOPSIS

```
#include <pcap/pcap.h>
```

**int pcap\_setfilter(pcap\_t \*p, struct bpf\_program \*fp);**

## DESCRIPTION

**pcap\_setfilter**() is used to specify a filter program. *fp* is a pointer to a *bpf\_program* struct, usually the result of a call to [**pcap\_compile**(3)](/pcap_compile/3.md).

## RETURN VALUE

**pcap\_setfilter**() returns **0** on success, **PCAP\_ERROR\_NOT\_ACTIVATED** if called on a capture handle that has been created but not activated, or **PCAP\_ERROR** on other errors.  If **PCAP\_ERROR** is returned, [**pcap\_geterr**(3)](/pcap_geterr/3.md) or [**pcap\_perror**(3)](/pcap_perror/3.md) may be called with *p* as an argument to fetch or display the error text.

## SEE ALSO

[**pcap**(3)](/pcap/3.md)
