---
name: "pcap_set_datalink"
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_set_datalink"
---

# pcap\_set\_datalink(3)

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**(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), [**pcap\_datalink\_name\_to\_val**(3)](/pcap_datalink_name_to_val/3.md)
