PCAP_LIST_DATALINKS(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

πŸ’… NAME πŸ’…

Bestie, welcome to the PCAP_LIST_DATALINKS page from the 3PCAP manual β€” yes, that 3PCAP. It's all about pcap_list_datalinks and pcap_free_datalinks: get a list of link-layer header types supported by a capture device, and free that list. Slay.

✨ SYNOPSIS ✨

#include <pcap/pcap.h>

int pcap_list_datalinks(pcap_t *p, int **dlt_buf);
void pcap_free_datalinks(int *dlt_list);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so pcap_list_datalinks() is the main character here: it gets you a list of the supported link-layer header types of the interface associated with the pcap descriptor. It allocates an array to hold the list and sets *dlt_buf to point to that array. Cute, right? But the caller is responsible for freeing the array with pcap_free_datalinks(), which frees the list of link-layer header types pointed to by dlt_list. Don't leave it hanging, bestie β€” that's your cleanup moment.

🚨 Hard no: 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, activate first, then ask for the list. Periodt.

🌸 RETURN VALUE 🌸

On success, pcap_list_datalinks() returns the number of link-layer header types in the array. If you call it on a capture handle that has been created but not activated, it returns PCAP_ERROR_NOT_ACTIVATED; on other errors, it returns PCAP_ERROR. And if PCAP_ERROR comes back, you may call pcap_geterr(3PCAP) or pcap_perror(3PCAP) with p as an argument to fetch or display the error text. Diagnostics unlocked.

πŸ‘‘ SEE ALSO πŸ‘‘

Go read these, iykyk πŸ’œ


xoxo, your 25 July 2018 bestie from the PCAP_LIST_DATALINKS(3PCAP) page πŸ’–βœ¨

πŸ“¦ where this page comes from