PCAP\_SETDIRECTION(3PCAP) PCAP\_SETDIRECTION(3PCAP)

# [NAME](#NAME)

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

# [SYNOPSIS](#SYNOPSIS)

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

```
int pcap_setdirection(pcap_t *p, pcap_direction_t d);
```

# [DESCRIPTION](#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](#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**(3PCAP)](/man/os/libpcap/pcap_geterr.3PCAP) or [**pcap\_perror**(3PCAP)](/man/os/libpcap/pcap_perror.3PCAP) may be called with *p* as an argument to fetch or display the error text.

# [SEE ALSO](#SEE_ALSO)

[**pcap**(3PCAP)](/man/os/libpcap/pcap.3PCAP)

5 March 2022

---

Document: pcap_setdirection(3pcap) from libpcap 1.11.0-r0 (Chainguard OS)
Source: https://github.com/the-tcpdump-group/libpcap.git
