PCAP_OFFLINE_FILTER(3PCAP)
π PCAP_OFFLINE_FILTER π
ok so bestie, welcome to PCAP_OFFLINE_FILTER(3PCAP) β the libpcap page that's literally just "does this filter match this packet, yes or no" and honestly? iconic. no capture needed, no network interface, just vibes and bytes. π¦
β¨ SYNOPSIS β¨
#include <pcap/pcap.h>
int pcap_offline_filter(const struct bpf_program *fp,
const struct pcap_pkthdr *h, const u_char *pkt);
that's it. three args. one int back. slay. π
πΈ DESCRIPTION πΈ
so pcap_offline_filter() does exactly the thing its name says: it checks whether a filter matches a packet. no cap. π₯
here's the cast of characters:
fpβ a pointer to abpf_programstruct, usually the glow-up result of callingpcap_compile(3PCAP)π§hβ points to thepcap_pkthdrstructure for the packet (the metadata bestie)pktβ points to the data in the packet, the actual payload main character π
now, inside the bpf_program struct, the bf_insns member is either NULL β which means reject all packets, like a bouncer at the club π β or it points to an array of one or more struct bpf_insn elements. and if it's the array case? then the bf_len member must be set to the number of elements. that's literally what pcap_compile() produces for you, so you're chilling. β¨
β οΈ two things you gotta respect or it's giving undefined behaviour energy: - the filter program must have been compiled for a link-layer header type that matches the packet data β mismatched link-layer types = nonsense results, periodt. - on Linux, the filter must not use BPF extensions. peep pcap_compile() for more info on that one. π§
π RETURN VALUE π
pcap_offline_filter() returns the return value of the filter program. that's it, that's the whole rule. π
- zero β the packet doesn't match the filter π
- non-zero β the packet matches the filter π
π¦ BACKWARD COMPATIBILITY π¦
big yikes moment in history: in libpcap releases before 1.10.7, this function ignored the provided bf_len value. so if you're on some ancient build, that detail mattered. we don't talk about it. π
π SEE ALSO π
pcap(3PCAP)β the whole family, go say hi π«Ά
and that's the page, bestie! this one came to you courtesy of the libpcap source and is dated 12 March 2026 β go forth and filter responsibly, mwah ππ
π¦ where this page comes from
- alpine 3.22: libpcap-doc 1.10.7-r0 Β· BSD-3-Clause
- alpine 3.23: libpcap-doc 1.10.7-r0 Β· BSD-3-Clause
- alpine 3.24: libpcap-doc 1.10.7-r0 Β· BSD-3-Clause
- fedora 43: libpcap-devel 14:1.10.7-1.fc43 Β· ISC AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC
- fedora 43: libpcap-devel 14:1.10.7-1.fc43 Β· ISC AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC
- fedora 44: libpcap-devel 14:1.10.7-1.fc44 Β· ISC AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC
- fedora 44: libpcap-devel 14:1.10.7-1.fc44 Β· ISC AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC
- nixos 26.05: libpcap 1.10.7
- opensuse-leap 16.0: libpcap-devel 1.10.5-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libpcap-devel 1.10.5-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libpcap-devel 1.10.5-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libpcap-devel 1.10.5-160000.5.1 Β· BSD-3-Clause
- ubuntu stonking: libpcap0.8-dev 1.10.7-1ubuntu1 Β· BSD-3-clause-var3
- Copyright (c) 1994, 1996, 1997 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms