Network Packet Analyzer

Every header field decoded, every checksum checked.

  • pcap and pcapng
  • Checksums verified
  • Flows and streams
Three flat cardboard parcels stacked on a wooden desk, the top one opened to show a smaller labelled box inside.

The guide

A packet capture is a stack of envelopes, and every one of them states its own size

Reading a capture byte by byte: why each header carries its own length, how the Internet checksum and its pseudo-header work, and what encryption leaves visible.

  • 0xA1B2C3D4 pcap magic number for microsecond timestamps
  • 96 bits IPv4 pseudo-header added to the TCP checksum
  • 14-bit offset a DNS compression pointer, counted from the message start
  • 2^14 + 256 bytes largest TLS 1.3 ciphertext record
Read the full guide Fold the guide 7 min · 20 sources

A packet capture is less mysterious than its reputation. It is a diary kept beside a network interface: for each frame that went past, a few bytes of bookkeeping and then the frame itself, exactly as it crossed the wire, or as much of it as the capture agreed to keep. Nothing in the file explains the frame. Every bit of meaning comes from reading the bytes in order, by the rules of each protocol in turn.

What a capture file actually holds

The classic pcap format opens with a 24-byte file header. Its first four bytes are a magic number, 0xA1B2C3D4 when timestamps are in microseconds or 0xA1B23C4D when they are in nanoseconds, written in the byte order of the machine that made the file. A reader that finds those bytes backwards knows it must swap every number that follows. The header also carries the snapshot length, the most bytes kept from any packet, and a link type that says what the first byte of each packet is.

Each packet then gets a 16-byte record: seconds since 1970, a fraction of a second, the captured length and the original length. Those last two differ whenever the snapshot length cut a packet short, and the difference matters later. A checksum cannot be verified over bytes that were never saved, so an honest decoder says “not checked” rather than “wrong”.

The newer pcapng format, written up by the same IETF working group, replaces the single header with blocks. Each block starts with a type and a total length and repeats the length at its end, so a reader can skip any block it does not understand and even walk the file backwards. A section header block sets the byte order with its own magic number, 0x1A2B3C4D. Interface description blocks give each capture interface a link type and, through an option called if_tsresol, a timestamp resolution. Packets arrive in enhanced packet blocks that name their interface, so one file can mix an Ethernet port with a raw IP tunnel.

Layers that each carry a length

Open the example capture in the tool above and choose packet 4. It is 113 bytes long and holds five headers nested like parcels: Ethernet, an 802.1Q VLAN tag, IPv4, UDP and a DNS message. The 3D view stacks them with the outermost at the bottom. What matters is not that there are five. It is that each one tells you where the next begins.

Ethernet II is the simplest case: six bytes of destination address, six of source, then a two-byte field. If that field is 1536 (0x0600) or more, it is an EtherType naming the next protocol; values of 1500 and below are an older 802.3 length instead. An 802.1Q tag slips four bytes in before the EtherType: a tag identifier of 0x8100, then three bits of priority, one drop-eligible bit and a 12-bit VLAN number. IANA keeps the registry of EtherType values, which is how 0x0800 comes to mean IPv4 and 0x86DD IPv6.

IPv4 states its header length in 32-bit words, at least five of them, and its total length in bytes. Any space between 20 bytes and the stated header length holds options, each either a single octet or a type, a length and data. IPv6 fixes its own header at 40 bytes and moves the optional parts into a chain of extension headers, each naming the one after it. TCP has a data offset that works like the IPv4 header length. UDP states the length of the whole datagram.

These self-descriptions are why a decoder must be suspicious. A length field is a claim, and the bytes may not back it up. A capture cut short, a damaged file or a deliberately hostile one can say a header is 60 bytes long when 14 remain. Every length should be checked against the bytes actually present before it is used, and a layer that does not fit should end with a finding instead of a crash. Ethernet frames shorter than the minimum are padded, too, so bytes after an IP datagram are a trailer, not data.

The checksum and the pseudo-header

The Internet checksum is old and deliberately cheap. RFC 1071 describes it: add the data as 16-bit words in ones’ complement arithmetic, folding any carry out of the top back into the bottom, then complement the result. A receiver adds everything, the checksum included, and expects all ones. It catches most accidental damage. It catches none of the deliberate kind.

Here is the arithmetic on a real header, the IPv4 header of packet 3 in the example. Its ten words are 4500 003d 1c01 4000 4011 9aa3 c000 020a c000 0201, where 9aa3 is the checksum. With the checksum field set to zero the other nine words add up to 0x2655A. Folding the carry gives 0x655A plus 0x2, which is 0x655C, and its complement is 0x9AA3, exactly the value in the packet. Add all ten words as received and the sum folds to 0xFFFF, the mark of a correct header. In the tool, that field lights up bytes 28 and 29, after 14 bytes of Ethernet and 4 of VLAN tag.

IPv4’s own checksum covers only its header. TCP and UDP checksums cover their header and data plus a pseudo-header borrowed from IP. For IPv4 it is 96 bits: the source and destination addresses, a zero byte, the protocol number and the transport length. For IPv6 it grows to 320 bits, and ICMPv6 uses it as well. The purpose is to catch a segment delivered to the wrong address, which a sum over the segment alone could never notice. Leave the pseudo-header out and a perfectly good segment fails the check.

Not every wrong checksum means a damaged packet. Many network stacks hand checksum work to the network adapter, so a capture taken on the sending machine can show outbound segments whose checksum the adapter had not yet filled in. UDP over IPv4 has a legitimate zero as well: RFC 768 reserves an all-zero checksum to mean the sender computed none, and sends a computed zero as all ones. Over IPv6 a zero UDP checksum is not allowed outside tunnel ports. A decoder has to know which zero it is looking at, and the example’s packet 17 carries a checksum that is simply wrong.

Reading a hex dump by hand

Before captures were passed around as files, they were passed around as text. A hex dump puts a byte offset in the left column, usually 16 bytes per row in the middle, and often an ASCII rendering on the right; the hexdump utility prints a lone asterisk where it skipped repeated rows. Reading one is mostly a matter of discarding what is not data. An offset column counts the bytes from zero, so each row holds exactly the bytes up to the next offset, and the ASCII side can be ignored. A token with an odd number of hex digits should be refused, with its line and column, because guessing which nibble went missing would invent a byte.

Pasted bytes carry no link type. Bytes starting 45 could open an IPv4 header or an Ethernet frame whose destination happens to begin with 45, so any reading starts with a guess and should admit it.

Sequence numbers, names and flows

TCP numbers bytes, not packets. Each direction starts from its own initial sequence number, and the SYN and FIN flags each consume one number. Subtracting the first number seen makes a conversation readable: the request in the example starts at relative byte 1 and is 41 bytes long, so the server acknowledges 42. The window scale and timestamp options of RFC 7323 and the selective acknowledgement blocks of RFC 2018 ride in the options area that the data offset sizes, and each option states its own length too.

Following a flow means grouping packets by protocol, both addresses and both ports, in either direction. Once the bytes of each direction are tracked, a segment whose every byte was already seen is a retransmission. One that fills a hole left earlier arrived out of order. One that starts beyond everything seen so far leaves a gap the capture never recorded. In the example the server’s 52-byte reply appears twice, and the second copy is marked resent.

DNS shows the same thrift. A name is a series of labels, each at most 63 octets, ending in a zero byte. To save space, a later name can end in a two-byte pointer whose top two bits are set and whose 14-bit offset points back into the message. In the example reply, the second answer’s name is a pointer to a name that is itself a label followed by another pointer. A careless decoder can be sent round in circles by two pointers aimed at each other, so a careful one counts its jumps, remembers where it has been, and reports a loop.

What a capture cannot tell you

A capture records what one interface saw, and nothing more. It cannot show packets that took another path, or whether an application ever read what arrived. A web page cannot capture traffic at all, so this one reads files and pasted bytes only.

Encryption ends the story early. TLS 1.3 wraps everything in records with a one-byte content type, a legacy version and a length, and a ciphertext record may carry at most 2^14 + 256 bytes. A capture shows those record boundaries and sizes, the addresses and ports, and the timing. It cannot show what was said. Anything claiming to read an encrypted conversation from the capture alone either holds the keys or is guessing.

That limit is also the best argument for reading captures carefully. When the content is sealed, the envelopes are all there is, and the envelopes are precise. Every header states its own length, every checksum can be recomputed, every sequence number adds up. Read byte by byte, they are an exact account of what crossed the wire, and an honest one about what did not.

Sources

Every source consulted for this guide. Links checked October 30, 2026.

  1. PCAP Capture File Format IETF opsawg, Internet-Draft draft-ietf-opsawg-pcap-09
  2. PCAP Now Generic (pcapng) Capture File Format IETF opsawg, Internet-Draft draft-ietf-opsawg-pcapng-06
  3. Link-Layer Types for PCAP-related Capture File Formats IETF opsawg, Internet-Draft draft-ietf-opsawg-pcaplinktype-18
  4. RFC 791: Internet Protocol RFC Editor (IETF)
  5. RFC 8200: Internet Protocol, Version 6 (IPv6) Specification RFC Editor (IETF)
  6. RFC 9293: Transmission Control Protocol (TCP) RFC Editor (IETF)
  7. RFC 768: User Datagram Protocol RFC Editor (IETF)
  8. RFC 1071: Computing the Internet checksum RFC Editor (IETF)
  9. RFC 1035: Domain names - implementation and specification RFC Editor (IETF)
  10. RFC 7323: TCP Extensions for High Performance RFC Editor (IETF)
  11. RFC 2018: TCP Selective Acknowledgment Options RFC Editor (IETF)
  12. RFC 4443: Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification RFC Editor (IETF)
  13. RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3 RFC Editor (IETF)
  14. IEEE 802 Numbers IANA
  15. Protocol Numbers IANA
  16. Ethernet frame Wikipedia (CC BY-SA)
  17. IEEE 802.1Q Wikipedia (CC BY-SA)
  18. EtherType Wikipedia (CC BY-SA)
  19. Hex dump Wikipedia (CC BY-SA)
  20. Transmission Control Protocol Wikipedia (CC BY-SA)