Visual RFC.
ALL RFCs / RFC 7766
Read the RFC ↗
RFC 7766 / DNS OVER TCP

Find message boundaries in a byte stream

02

TCP delivers an ordered stream of bytes, not DNS-sized packets. A two-byte length prefix tells the receiver where each DNS message ends.

RFC 7766 · § 8EXAMPLE
4 / 4
Find message boundaries in a byte streamActual teaching query A is 32 bytes and query B is 29. Framed stream lengths are 34 and 31 bytes. Views show both prefixes 00 20 and 00 1d, then the first prefix byte only, then a complete prefix and 10 of 32 message bytes, then two messages delivered separately after all 65 bytes arrive. TCP read boundaries differ from DNS message boundaries; no incomplete frame is delivered or connection closed solely for a short read.Ordered stream · schematic byte widthsAccumulated stream: 65 bytesA: 2 + 32 bytes · B: 2 + 29 bytes32 / 32 message bytesFirst message completeDelivered DNS messages: 2Buffered stream bytes: 0Delivery lengths: 32, then 29
04
Finish one message and keep parsing the next.

A later read completes the first query and contains the whole second frame. Deliver the two messages separately, in stream order, with no leftover bytes.

Source for this drawing: RFC 7766 · Read RFC section 8 ↗

Protocol participantThreat or exceptionProtocol controlSimplified drawings · precise section references
New to this? Start hereA quick picture + helpful background

A message needs an address.

Think of a packet as a small addressed envelope. Devices pass it onward; transport protocols decide what delivery promises an application gets.

Helpful first, if these ideas are unfamiliar

These pictures are analogies to help you learn. The linked RFC explains the actual rules.

Related RFCs and changes

“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.

KEY POINT

Count message bytes, not TCP reads.

  • The two-octet length prefix counts the DNS message only, excluding the prefix itself (RFC 1035 §4.2.2). Octet means eight-bit byte.
  • Clients and servers SHOULD pass the length prefix and its message to TCP together, for example in one write. This does not guarantee one network segment or one read.
  • Servers MUST NOT close merely because the first read lacks a complete DNS message. Buffer incomplete bytes and apply appropriate timeouts; multiple complete messages can share a read.
DETAILS

The drawing uses real fictional query encodings: picnic.example. IN A has 32 message bytes; tea.example. IN AAAA has 29. IN is the Internet class; A requests an IPv4 address and AAAA an IPv6 address. Byte counts include the 12-byte header and question fields. Schematic widths are not packet proportions. This is DNS framing, not TLS records. The teaching decoder is bounded test code, not a production DNS parser.

Read the RFC section ↗

All chapters in RFC 7766

Drawing view

Scroll the drawing to see every part. Playback controls stay above it.

RFC 9700 / CHAPTERS

Chapters

For full details, tables, algorithms, and exceptions, read the original RFC.

RFC status and corrections ↗