libpcap Documentation
repository·master·Indexed 25 days ago
https://github.com/the-tcpdump-group/libpcapA portable, system-independent library for user-level packet capture and low-level network monitoring. It provides a unified API that abstracts OS-specific packet capture interfaces and supports filtering via the BSD Packet Filter (BPF) architecture. The library includes platform-specific implementation details and build requirements for Linux, AIX, Haiku, HP-UX, and GNU/Hurd, as well as specialized support for Endace DAG passive network monitoring cards.
What's inside libpcap
- libpcap is a system-independent interface for user-level packet capture. It provides a portable framework for low-level network monitoring, enabling applications to perform network statistics collection, security monitoring, and network debugging. It abstracts various system-dependent packet capture modules into a single, consistent API.
Limitations of libpcap on GNU/Hurd
masterWhen using libpcap on the GNU/Hurd platform, be aware of the following functional limitations:
- Loopback Interface: Packet capture on the loopback network interface is not supported.
- BPF Filtering: BPF works in the kernel only if the filter length is $\le$ 31 BPF instructions and does not use
BPF_MODorBPF_XORinstructions. - Timestamping: Packet timestamping always occurs in userland.
- Wireless: Wireless monitor mode is not supported.
- Capture Scope: Packet capture only sees packets received on the interface.
- Unsupported/Ineffective APIs:
pcap_set_buffer_sizehas no effect.pcap_setdirectionis not supported.pcap_set_promischas no effect.
Understand BPF filtering and platform support
masterlibpcap supports filtering via the BSD Packet Filter (BPF) architecture.
- In-kernel filtering: libpcap utilizes in-kernel filtering only when the underlying interface supports BPF programs (e.g., BPF packet capture interface, Linux packet socket, and GNU/Hurd interface).
- User-space filtering: On other platforms, libpcap reads every packet into user-space and evaluates it using the filter program, which incurs higher overhead.
- Standard BPF Support: NetBSD, FreeBSD, OpenBSD, DragonFly BSD, macOS, QNX, and Solaris 11.
- Linux Support: libpcap supports many memory-mapped receive mechanisms but does not currently support eBPF mechanisms. Refer to
doc/README.linuxfor Linux-specific details.
Build environment requirements for Debian GNU/Hurd 12
masterTo compile libpcap on Debian GNU/Hurd 12, the following toolchain versions are verified to work:
- Lexer/Parser:
flex 2.6.4andGNU Bison 3.8.2 - Build System:
CMake 3.25.1 - Compilers:
GCC 12.2.0andClang 14.0.6
These tests were performed using the Debian GNU/Hurd 12 system from the 2023-06-08 snapshot.
- Lexer/Parser:
Build libpcap with Endace DAG support
masterTo use libpcap with Endace DAG passive network monitoring cards on a Linux host, follow these steps:
- Install DAG software: Install and build a recent version of the DAG software distribution from Endace.
- Configure libpcap:
- If DAG is installed in a standard location, the
./configurescript will detect it automatically. - If DAG is in a custom location, use the
--with-dag=DIRflag, whereDIRis the root of the DAG software distribution.
- If DAG is installed in a standard location, the
- Select Capture Type:
- Hybrid (Default): Building without specific flags includes support for both standard Linux devices (network interfaces, USB, etc.) and DAG cards.
- DAG-only: To build libpcap with only DAG support, use
--with-pcap=dagduring configuration.
CMake builds also support DAG via the
INSTALL.mdconfiguration options.Compile libpcap on Solaris and related OSes
masterWhen compiling libpcap on Solaris or illumos-based systems, avoid using the native
lexandyaccimplementations as they are unsuitable. Instead, useflexandGNU Bison.m4is supported on both Solaris and illumos.General requirements:
- Use
flexandGNU Bisoninstead oflexandyacc. Autoconfis compatible across all these platforms.
- Use
Enable experimental DAG transmit support
masterBy default, libpcap's support for Endace DAG transmit (
pcap_injectandpcap_sendpacket) is disabled. To enable this experimental feature, you must explicitly configure it during the build process.Requirements for successful transmission:
- Packets must be Ethernet frames without FCS (the standard libpcap format).
- The DAG card's transmitting port must be configured to add a 32-bit FCS to outgoing frames (the usual default).
pcap_activate()automatically detects the card's FCS configuration and adjusts the frame composition accordingly.
Note: Transmit support is tested on DAG 7.5G2 and DAG 9.2X2; it does not support vDAG devices.
Prerequisites for building libpcap on Windows
masterTo build libpcap on Windows, you must provide a driver and library interface, as Windows lacks a native network traffic capture mechanism. You must choose between Npcap (recommended) or WinPcap (legacy/older Windows versions).
Setup Steps:
- Download SDK: Download the Npcap or WinPcap SDK.
- Extract SDK: Create a folder on your
C:drive (e.g.,C:\npcap-sdk) and extract the SDK contents there. - WinPcap Specifics: If using WinPcap, place the
WpdPackfolder from the Developer's Kit on yourC:drive (e.g.,C:\WpdPack).
Clone the libpcap repository
masterYou can access the source code via Anonymous Git at the following URL:
git clone https://github.com/the-tcpdump-group/libpcap.gitBuild libpcap from source
masterTo build libpcap from the source distribution, you must first generate the configuration files using the
autogen.shscript. This script builds theconfigurescript andconfig.h.in.Note that the repository contains various platform-specific documentation files (e.g.,
doc/README.linux,doc/README.macos,doc/README.windows.md) which provide specific instructions for different operating systems.Install required build tools via Chocolatey
masterlibpcap requires Visual Studio 2015 or later and CMake. You can use the Chocolatey package manager to install several required tools.
Install Chocolatey GUI:
choco install -y chocolateyguiInstall CMake:
choco install -y cmakechoco install -y chocolateygui choco install -y cmakeFind platform-specific installation notes
masterlibpcap provides specialized documentation for various operating systems and hardware devices. If you are using a specific platform, refer to the corresponding README file in the
doc/directory:- AIX:
doc/README.aix - Endace DAG devices:
doc/README.dag.md - Haiku:
doc/README.haiku.md - HP-UX:
doc/README.hpux - GNU/Hurd:
doc/README.hurd.md - Linux:
doc/README.linux - macOS:
doc/README.macos - QNX:
doc/README.qnx.md - Myricom SNF devices:
doc/README.snf.md - Solaris:
doc/README.solaris.md - Windows (with Npcap):
doc/README.windows.md
- AIX: