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

# pcap\_setdirection(3pcap)

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 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)
