@@ -21,6 +21,69 @@ and vice versa,
2121but their counterparts for binary formats
2222are sorely missing from the package ` encoding/binary ` .
2323
24+ ### Message Formats
25+ Messages are the lifeblood of network applications.
26+ The following specifications
27+ quoted from [ Section 3.1] ( https://datatracker.ietf.org/doc/html/rfc791#section-3.1 )
28+ of RFC 791 Internet Protocol and
29+ [ Section 3.1] ( https://datatracker.ietf.org/doc/html/rfc793#section-3.1 )
30+ of RFC 793 Transmission Control Protocol
31+ describe the anatomy of TCP/IP headers
32+ at the beginning of every internet datagram (more fondly known as a "packet").
33+
34+ ```
35+ A summary of the contents of the internet header follows:
36+
37+
38+ 0 1 2 3
39+ 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
40+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41+ |Version| IHL |Type of Service| Total Length |
42+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43+ | Identification |Flags| Fragment Offset |
44+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45+ | Time to Live | Protocol | Header Checksum |
46+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47+ | Source Address |
48+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49+ | Destination Address |
50+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51+ | Options | Padding |
52+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53+
54+ Example Internet Datagram Header
55+
56+ Figure 4.
57+
58+ Note that each tick mark represents one bit position.
59+ ```
60+
61+ ```
62+ ```
63+ 0 1 2 3
64+ 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
65+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66+ | Source Port | Destination Port |
67+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68+ | Sequence Number |
69+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70+ | Acknowledgment Number |
71+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72+ | Data | | U| A| P| R| S| F| |
73+ | Offset| Reserved | R| C| S| S| Y| I| Window |
74+ | | | G| K| H| T| N| N| |
75+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76+ | Checksum | Urgent Pointer |
77+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78+ | Options | Padding |
79+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80+ | data |
81+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82+ TCP Header Format
83+ Note that one tick mark represents one bit position.
84+ Figure 3.
85+ ```
86+
2487## Working with Binary Formats in Go
2588Message and file formats specify how bits are arranged to encode information.
2689Control over individual bits or groups smaller than a byte is often required
@@ -109,7 +172,7 @@ type RFC791InternetHeaderFormatWithoutOptions struct {
109172}
110173```
111174
112- #### Example
175+ ### Example
113176It is highly unlikely that a developer
114177would ever need to implement the Internet Protocol
115178(since in Go, the package [ ` net ` ] ( https://pkg.go.dev/net )
@@ -210,31 +273,13 @@ in [Section 3.1](https://datatracker.ietf.org/doc/html/rfc791#section-3.1)
210273of RFC 791 defining the Internet Protocol.
211274
212275```
213- A summary of the contents of the internet header follows:
214-
215-
216276 0 1 2 3
217277 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
218278 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219279 |Version| IHL |Type of Service| Total Length |
220280 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221- | Identification |Flags| Fragment Offset |
222- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223- | Time to Live | Protocol | Header Checksum |
224- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225- | Source Address |
226- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
227- | Destination Address |
228- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229- | Options | Padding |
230- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231-
232- Example Internet Datagram Header
233-
234- Figure 4.
235-
236- Note that each tick mark represents one bit position.
237-
281+ ```
282+ ```
238283 Version: 4 bits
239284
240285 The Version field indicates the format of the internet header. This
0 commit comments