---
name: "pcap_setdirection"
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_setdirection"
---

# pcap\_setdirection(3)

set the direction for which packets will be captured

## NAME

pcap\_setdirection - set the direction for which packets will be captured

## SYNOPSIS

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

**int pcap\_setdirection(pcap\_t \*p, pcap\_direction\_t d);**

## DESCRIPTION

**pcap\_setdirection**() is used to specify a direction that packets will be captured. *d* is one of the constants **PCAP\_D\_IN**, **PCAP\_D\_OUT** or **PCAP\_D\_INOUT**. **PCAP\_D\_IN** will only capture packets received by the device, **PCAP\_D\_OUT** will only capture packets sent by the device and **PCAP\_D\_INOUT** will capture packets received by or sent by the device. **PCAP\_D\_INOUT** is the default setting if this function is not called.

**pcap\_setdirection**() isn't necessarily fully supported on all platforms; some platforms might return an error for all values, and some other platforms might not support **PCAP\_D\_OUT**.

This operation is not supported if a \`\`savefile'' is being read.

## RETURN VALUE

**pcap\_setdirection**() 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)
