TCP header (Bytefield)

The TCP header is the standard example for byte field diagrams, and it exercises most of what Bytefield can do.


#What this example shows

  • Column headers, which number the bytes across the top.

  • Boxes spanning several bytes.

  • Per-field colour, defined once and reused.


#A worked example

Open it, edit it, or copy the source below.

TCP header (Bytefield)

The source, which you can paste into a new diagram and edit:

(defattrs :head {:fill "#e6eeff"})
(defattrs :flags {:fill "#fff4e0"})

(draw-column-headers)

(draw-box "Source port" {:span 2 :attrs :head})
(draw-box "Destination port" {:span 2 :attrs :head})
(draw-box "Sequence number" {:span 4})
(draw-box "Acknowledgement number" {:span 4})
(draw-box "Offset / reserved / flags" {:span 2 :attrs :flags})
(draw-box "Window" {:span 2})
(draw-box "Checksum" {:span 2})
(draw-box "Urgent pointer" {:span 2})
(draw-gap "Options (variable, 0 to 40 bytes)")
(draw-bottom)

#Making it your own

  • Bytefield counts bytes; PacketDiag counts bits. Pick the one that matches your spec.

  • draw-gap is how variable-length regions are drawn honestly.

  • State the endianness in the surrounding text.



The offsets are computed, not drawn.