275 words
1 minute
Generate ASCII Network Diagrams with protocol

Protocol#

I’ve recently found a cool little command line utility called protocol written by Luis MartinGarcia. The protocol program is used to generate network protocol diagrams using ASCII art. The ASCII art style is the same style that is used in the IETF RFC documents. Here’s an example of the tcp packet structure.

Terminal window
>> protocol tcp
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Offset| Res. | Flags | Window |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The protocol application can be used to generate your own diagrams as well. Simple usage is just to specify the field name and the field width in bits. The fields are separated by commas and the bit segment is specified by a : after the field name. Here’s an example of creating a custom diagram.

Terminal window
protocol "field 1:8,field 2:24, field 3: 32"
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| field 1 | field 2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| field 3 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Conclusion#

The protocol application is really neat program to generate ASCII art representations of packet structures. This can be quite useful for debugging byte packing and unpacket when you have a nice visual packet field representation.

Generate ASCII Network Diagrams with protocol
https://jonathanhamberg.com/posts/2020-12-10-protocol-network-diagram/
Author
Jonathan Hamberg
Published at
2020-12-10
License
CC BY-NC-SA 4.0