PCAP_DATALINK(3PCAP)

πŸ“¦
version 1.10.7 Β· 2 versions
  • 1.10.7 Β· alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 1.11.0 Β· arch rolling
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

Okay so this is a page from the PCAP manual, section 3PCAP, and it's literally about one tiny function that answers one huge question: what kind of packets are we even looking at?? πŸŽ€


πŸ¦‹ NAME

pcap_datalink β€” get the link-layer header type. That's it. That's the whole vibe. πŸ‘‘


✨ SYNOPSIS

#include <pcap/pcap.h>

int pcap_datalink(pcap_t *p);

🌸 DESCRIPTION

pcap_datalink() returns the link-layer header type for the live capture or the "savefile" that you specified with p. Simple queen behavior, ngl. πŸ’–

⚠️ But listen β€” it must not be called on a pcap descriptor created by pcap_create(3PCAP) that has not yet been activated by pcap_activate(3PCAP). Like, do not come for her before she's ready, okay?? 😭

The link https://www.tcpdump.org/linktypes.html lists the values pcap_datalink() can return and describes the packet formats that correspond to those values. Go read it, it's giving reference material and it ate. πŸ”₯

Do NOT assume that the packets for a given capture or "savefile" will have any given link-layer header type, such as DLT_EN10MB for Ethernet. Lowkey this is the part everyone gets wrong so pay attention bestie πŸ™ˆ β€” for example, the "any" device on Linux will have a link-layer header type of DLT_LINUX_SLL or DLT_LINUX_SLL2 even if all devices on the system at the time the "any" device is opened have some other data link type, such as DLT_EN10MB for Ethernet. Yeah. She's not like the other devices. πŸ’€


🌈 RETURN VALUE

  • On success, pcap_datalink() returns the link-layer header type. Slay, we love a successful return. ⭐
  • If you called it on a capture handle that has been created but not activated, you get PCAP_ERROR_NOT_ACTIVATED. The audacity, honestly. 🫠

πŸ’œ SEE ALSO


That's the whole page, bestie β€” no notes, no cap. 🧚 This was the PCAP_DATALINK(3PCAP) page, dated 7 April 2014, and it's iconic, periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from