pcap

term

networkingsecurity

Kept in this browser · My desk

The classic capture file format of libpcap and tcpdump: a 24-byte file header, then a record header and the bytes of each packet.

The header starts with the magic number 0xa1b2c3d4 in the writer's byte order (0xa1b23c4d when timestamps are in nanoseconds), then version 2.4, the snapshot length and the link-layer type, 1 for Ethernet. libpcap's pcap-savefile(5) manual advises reading savefiles with libpcap rather than one's own code. Scapy's rdpcap reads pcap and the newer pcapng format; reading a saved file needs no special privileges, while capturing from an interface may.

The word pcap is used for three things: the programming interface of the libpcap library (and of Npcap, which implements the same interface on Windows), the file format that library reads and writes, and loosely any packet capture. The format is as plain as a format can be: one file header, then packet records one after another until the file ends. There is no index, no trailer and no count of packets, so a file cut short by a full disk is still readable up to the last complete record. It is not pcapng, a different format with a different first four bytes, and it is not whatever a given analyser writes into a file ending in .cap, an extension the format's own description says is used for a plethora of formats.

The format was never designed as a standard. In the late 1980s Van Jacobson, Steve McCanne and others in the Network Research Group at Lawrence Berkeley National Laboratory wrote tcpdump to capture and dissect network traces, and the code that captured packets and read and wrote trace files was later moved into a library, libpcap; McCanne and Jacobson's paper on the kernel filter underneath, BPF (the BSD Packet Filter), is dated 19 December 1992. Both programs are maintained by The Tcpdump Group, whose site listed, as read on 12 November 2026, tcpdump 4.99.7 and libpcap 1.10.7 as stable and libpcap 1.11.0, the product of nearly six years of work, in testing. The format is only now being written down by the IETF (Internet Engineering Task Force): the Internet-Draft PCAP Capture File Format, by Guy Harris and Michael Richardson, revision 09 of 19 September 2026, is headed for publication as a Historic document. It calls what it describes version 2 of the pcap format, notes that pcapng has existed for some time as its replacement, and says that the version numbers, 2 and 4, will not change again.

The file header is 24 octets. Four hold the magic number, two the major version and two the minor version. Two 4-octet fields follow that older software documented as the time zone offset and the accuracy of timestamps; writers should now fill them with zero and readers must ignore them. Then come the snapshot length and a 4-octet field whose low 16 bits are the link-layer type and whose top bits can say how many octets of FCS (frame check sequence) follow each packet. Every multi-octet field is written in the byte order of the machine that wrote the file, and the magic number is how a reader finds out which: the first four bytes are a1 b2 c3 d4 from a big-endian writer and d4 c3 b2 a1 from a little-endian one. A second magic number, 0xa1b23c4d, marks a file whose timestamps carry nanoseconds instead of microseconds, giving four possible openings in all.

Each packet record is a 16-octet header followed immediately by the packet's bytes, with no padding. The header holds the timestamp as two 32-bit values, seconds since 1 January 1970 00:00:00 UTC (Coordinated Universal Time) and the fraction of that second, then the captured length and the original length. The two lengths differ when the capture was limited by the snapshot length: only the first bytes of each packet up to that limit are stored, and the original length records what was on the wire. tcpdump's default snapshot length is 262144 bytes, which is also what -s 0 selects, and the libpcap manual notes that 65535 is enough on most networks; a smaller value saves disk and processing at the price of discarding data from the protocols above the transport layer. The seconds field is unsigned, so it runs out on 7 February 2106, and the manual is careful to call the timestamp the approximate time the packet was captured.

The link-layer type tells a reader how to interpret the first bytes of every packet. The registry kept by The Tcpdump Group lists, among many others, 1 for Ethernet, 0 for the BSD loopback encapsulation, 101 for raw IPv4 or IPv6 with no link header, 105 for IEEE 802.11 and 127 for 802.11 preceded by a radiotap header, and 113 and 276 for the two versions of the Linux cooked capture encapsulation; values 147 to 162 are reserved for private use. A file has exactly one such value. That is the format's main structural limit, and the draft names it together with two others: a file can hold only one link type, which usually means one interface, since most link types have no way to say which interface a packet came from; and because the header is unlike the records, two files cannot simply be concatenated, nor one split, without writing a new header.

Those limits are what pcapng removes. A pcapng file is a sequence of blocks: a mandatory Section Header Block, which carries its own byte-order magic 0x1A2B3C4D, then Interface Description Blocks, Enhanced Packet Blocks that refer to an interface, and optional blocks for name resolution and interface statistics, with room for comments and a timestamp resolution set per interface (microseconds when not stated). Its first four bytes, 0a 0d 0d 0a, match none of the pcap magic numbers, so one reader can tell the formats apart. Wireshark has saved pcapng by default since version 1.8 and still reads and writes pcap; tcpdump reads both; libpcap's own function for opening a file accepts pcapng with the warning that not all pcapng files can be read; Scapy's rdpcap reads both. In practice pcap remains the format that every one of these tools accepts.

On the command line the format is two options: tcpdump -w writes raw packets to a file instead of printing them, and -r reads a file back, with -C rotating the output by size and -G by time. Output is buffered, so a file being written may lag the wire. Capturing from an interface may need special privileges and reading a saved file needs none, which is the reason to capture on the device and analyse elsewhere. The recommended extension is .pcap; the media type application/vnd.tcpdump.pcap has been registered with IANA (Internet Assigned Numbers Authority) since 2011, and the draft asks for application/pcap.

Three things go wrong with capture files. The first is truncation: a capture taken with a short snapshot length has lost for good whatever lay beyond the limit, so application data cannot be rebuilt from it, and the place to check is the snapshot length in the header and the two lengths in each record. The second is trust in the file. The draft requires a reader to validate the file header and every record header, because a file from outside may be intentionally malformed, and libpcap 1.10.7 of September 2026 was itself a release that fixed seven vulnerabilities; the manual's advice to read savefiles through libpcap instead of private parsing code has that in its favour too. The third is what the file contains. The media type registration puts it plainly: captured packets may reveal the private matters of network users, who may not know a capture took place, and even when content is encrypted the headers and timing remain open to traffic analysis; it strongly recommends encrypting a capture before sending it by email or the web.

Also known as: pcap file, .pcap, libpcap savefile, capture file

Sources

← Back to P Back to the glossary