---
name: "pcap_setfilter"
section: "3pcap"
platform: "macos"
package: "libpcap"
version: "146"
release: "macOS 26.5"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/pcap_setfilter/3pcap"
---

# pcap\_setfilter(3pcap)

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**(3PCAP).

## RETURN VALUE

**pcap\_setfilter**() returns **0** on success and **PCAP\_ERROR** on failure. If **PCAP\_ERROR** is returned, **pcap\_geterr**(3PCAP) or **pcap\_perror**(3PCAP) may be called with *p* as an argument to fetch or display the error text.

## SEE ALSO

**pcap**(3PCAP)
