Skip to content

Instantly share code, notes, and snippets.

@barryirwin
Last active January 13, 2023 10:19
Show Gist options
  • Save barryirwin/5b0121f30db93eff4c4769a5299f75e0 to your computer and use it in GitHub Desktop.
Save barryirwin/5b0121f30db93eff4c4769a5299f75e0 to your computer and use it in GitHub Desktop.
Packet structures fotr IPv4 / TCP/ UDP and ICMP for use in LaTeX documents. These depend on the bytefield package
%% These require the use of the bytefield package
Snippets are suitabel for inclusion in tha figure environment
%%IPv4 after Postel 1981 & Stevens 1993
\centering
\begin{bytefield}{32}
\bitheader{0,3,4,7,8,15,16,23,24,31} \\
\bitbox{4}{\tiny{Version}} & \bitbox{4}{\tiny{Header length}} & \bitbox{8}{TOS} & \bitbox{16}{Total Length} \\
\bitbox{16}{Identification} &\bitbox{1}{\tiny 0} &\bitbox{1}{\tiny D\\F}
&\bitbox{1}{\tiny M\\F} & \bitbox{13}{Fragment Offset} \\
\bitbox{8}{TTL} & \bitbox{8}{Protocol} & \bitbox{16}{Header Checksum} \\
\bitbox{32}{Source Address} \\
\bitbox{32}{Destination Address} \\
\bitbox{32}{Options} \\
\wordbox[lrt]{1}{Payload} \\
\skippedwords \\
\wordbox[lrb]{1}{} \\
\end{bytefield}
%%% TCP
\centering
\begin{bytefield}{32}
\bitheader{0,7,8,15,16,23,24,31} \\
\bitbox{16}{Source Port} & \bitbox{16}{Destination Port} \\
\bitbox{32}{Sequence Number} \\
\bitbox{32}{Acknowledgment Number} \\
\bitbox{4}{Offset} & \bitbox{6}{Reserved}
&\bitbox{1}{\tiny U\\R\\G} &\bitbox{1}{\tiny A\\C\\K}
&\bitbox{1}{\tiny P\\S\\H} &\bitbox{1}{\tiny R\\S\\T}
&\bitbox{1}{\tiny S\\Y\\N} & \bitbox{1}{\tiny F\\I\\N}
& \bitbox{16}{Window} \\
\bitbox{16}{Checksum} & \bitbox{16}{Urgent Pointer} \\
\bitbox{32}{Options} \\
\wordbox[lrt]{1}{Payload} \\
\skippedwords \\
\wordbox[lrb]{1}{} \\ \end{bytefield}
%% UDP
centering
\begin{bytefield}{32}
\bitheader{0,7,8,15,16,23,24,31} \\
\bitbox{16}{Source Port} & \bitbox{16}{Destination Port} \\
\bitbox{16}{Length} & \bitbox{16}{Checksum} \\
\wordbox[lrt]{1}{Payload} \\
\skippedwords \\
\wordbox[lrb]{1}{} \\ \end{bytefield}
%% ICMP
\centering
\begin{bytefield}{32} \bitheader{0,7,8,15,16,23,24,31} \\
\bitbox{8}{Type} &\bitbox{8}{Code} \bitbox{16}{Checksum} \\
\bitbox{16}{ID} & \bitbox{16}{Sequence} \\
\wordbox[lrt]{1}{Optional Payload} \\
\skippedwords \\
\wordbox[lrb]{1}{} \\ \end{bytefield}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment