---
name: "pcap_set_datalink"
section: "3pcap"
platform: "linux"
package: "libpcap"
version: "1.11.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/pcap_set_datalink/3pcap"
---

# pcap\_set\_datalink(3pcap)

set the link-layer header type to be used by a capture device

## NAME

pcap\_set\_datalink - set the link-layer header type to be used by a capture device

## SYNOPSIS

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

**int pcap\_set\_datalink(pcap\_t \*p, int dlt);**

## DESCRIPTION

**pcap\_set\_datalink**() is used to set the current link-layer header type of the pcap descriptor to the type specified by *dlt*.

## RETURN VALUE

**pcap\_set\_datalink**() 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) or **pcap\_perror**(3PCAP) may be called with *p* as an argument to fetch or display the error text.

## SEE ALSO

**pcap**(3PCAP), **pcap\_datalink**(3PCAP), **pcap\_list\_datalinks**(3PCAP), **pcap\_datalink\_name\_to\_val**(3PCAP)
