pcap
termKept 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
- The Tcpdump Group, pcap-savefile(5), libpcap savefile format, updated 21 January 2025 (read 2026-11-12): the 24-octet per-file header (magic number, version 2.4, two reserved fields once documented as time zone offset and accuracy of timestamps, snapshot length, link-layer type with FCS length bits); the byte-swapped and nanosecond magic numbers; the 16-octet per-packet header (seconds, microseconds or nanoseconds, captured length, un-truncated length); the advice to read savefiles with libpcap
- The Tcpdump Group, Link-layer header types (read 2026-11-12): LINKTYPE_NULL 0, LINKTYPE_ETHERNET 1, LINKTYPE_RAW 101, LINKTYPE_IEEE802_11 105, LINKTYPE_LINUX_SLL 113, LINKTYPE_IEEE802_11_RADIOTAP 127, LINKTYPE_LINUX_SLL2 276; values 147 to 162 reserved for private use; LINKTYPE and DLT values can differ
- The Tcpdump Group, tcpdump(1), updated 10 September 2026 (read 2026-11-12): -w writes raw packets to a file, -r reads pcap or pcapng files, -C and -G rotate savefiles; the default snapshot length of 262144 bytes, which -s 0 also selects; truncated packets shown as [|proto]; reading a saved packet file needs no special privileges
- IETF, Internet-Draft draft-ietf-opsawg-pcap-09, PCAP Capture File Format, G. Harris and M. Richardson, 19 September 2026, intended status Historic (read 2026-11-12): tcpdump developed in the late 1980s by Van Jacobson, Steve McCanne and others at Lawrence Berkeley National Laboratory; version 2 of the format, which will not change again; the limitations (no concatenation, a single link type); 32-bit unsigned seconds; no padding of packet records; the .pcap extension; readers must validate headers; the application/pcap media type
- IETF, Internet-Draft draft-ietf-opsawg-pcapng-06, PCAP Now Generic (pcapng) Capture File Format, M. Tüxen, F. Risso, G. Harris and M. Richardson, 19 September 2026, intended status Informational (read 2026-11-12): the Section Header Block with the byte-order magic 0x1A2B3C4D; Interface Description, Enhanced Packet, Simple Packet, Name Resolution and Interface Statistics blocks; the if_tsresol option, microseconds when absent; comments
- The Tcpdump Group, home page of tcpdump and libpcap (read 2026-11-12): latest releases tcpdump 4.99.7 (2026-09-21), libpcap 1.10.7 (2026-09-05), which fixes seven vulnerabilities, and libpcap 1.11.0 (2026-09-13) in testing, the result of nearly six years of development
- Steven McCanne and Van Jacobson, The BSD Packet Filter: A New Architecture for User-level Packet Capture, Lawrence Berkeley Laboratory, 19 December 1992 (read 2026-11-12): the kernel packet filter behind tcpdump
- The Tcpdump Group, pcap(3PCAP) (read 2026-11-12): savefiles; the snapshot length, of which 65535 should be sufficient on most if not all networks
- The Tcpdump Group, pcap_open_offline(3PCAP) (read 2026-11-12): opens a savefile in the pcap format or in the pcapng format, although not all pcapng files can be read
- Wireshark User's Guide, Open Capture Files, input file formats (read 2026-11-12): pcap is the default format of libpcap, used by tcpdump, Snort, Nmap, Ntop and many other tools; pcapng is its flexible, extensible successor, saved by default by Wireshark 1.8 and later
- Scapy documentation, scapy.utils (read 2026-11-12): rdpcap reads a pcap or pcapng file and returns a packet list
- IANA, media type registration application/vnd.tcpdump.pcap, last updated 30 March 2011 (read 2026-11-12): captures may reveal the private matters of network users; headers and timing remain subject to traffic analysis even when content is encrypted; captures should be encrypted when transmitted; bugs in reading programs could be exploited
- Nmap Project, Npcap home page (read 2026-11-12): the packet capture library for Windows implementing the Pcap API; began in 2013 as improvements to the now discontinued WinPcap