blob: 3abf9768ba342f58e9aca9bd95a7affde8830049 [file] [log] [blame] [edit]
https://en.wikipedia.org/wiki/Internet_Protocol_version_4
IPv4 header format
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet | 0 | 1 | 2 | 3 |
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| 0 | 0 | Version [4] | IHL [>=5] | DSCP | ECN | Total length [>=20, >=4*IHL] |
+---------+-------+-------------------+-------------------+-----------------------------+---------+----+----+----+----------------------------------------------------------------+
| 4 | 32 | Identification | 0 | DF | MF | Fragment offset |
+---------+-------+---------------------------------------+---------------------------------------+----+----+----+----------------------------------------------------------------+
| 8 | 64 | Time to Live | Protocol | Header checksum |
+---------+-------+---------------------------------------+---------------------------------------+-------------------------------------------------------------------------------+
| 12 | 96 | Source address |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 16 | 128 | Destination address |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 20 | 160 | Options (if IHL > 5) |
| .. | ... | |
| 56 | 448 | |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
https://en.wikipedia.org/wiki/IPv6_packet
Fixed header format
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet | 0 | 1 | 2 | 3 |
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| 0 | 0 | Version [6] | Traffic class (DSCP 6 + ECN 2 bits) | Flow label |
+---------+-------+-------------------+---------------------------------------+-------------------+---------------------------------------+---------------------------------------+
| 4 | 32 | Payload length | Next header | Hop limit |
+---------+-------+-------------------------------------------------------------------------------+---------------------------------------+---------------------------------------+
| 8 | 64 | Source Address |
| 12 | 96 | |
| 16 | 128 | |
| 20 | 160 | |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 24 | 192 | Destination address |
| 28 | 224 | |
| 32 | 256 | |
| 36 | 288 | |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
https://en.wikipedia.org/wiki/ICMPv6
ICMPv6 header (4 bytes): u8 type, u8 code, u16 checksum
(4 bytes in) Message body... (but note in practice it's actually 4 bytes reserved, then 'real' message body at 8 bytes in)
https://en.wikipedia.org/wiki/Transmission_Control_Protocol
TCP segment header
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet | 0 | 1 | 2 | 3 |
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| 0 | 0 | Source port | Destination port |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
| 4 | 32 | Sequence number |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 8 | 64 | Acknowledgment number (if ACK set) |
+---------+-------+-------------------+-------------------+----+----+----+----+----+----+----+----+-------------------------------------------------------------------------------+
| 12 | 96 | Data Offset | Reserved (zero) | CWR| ECE| URG| ACK| PSH| RST| SYN| FIN| Window size |
+---------+-------+-------------------+-------------------+----+----+----+----+----+----+----+----+-------------------------------------------------------------------------------+
| 16 | 128 | Checksum | Urgent pointer (if URG set) |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
| 20 | 160 | Options (if data offset > 5. Padded at the end with "0" bits if necessary.) |
| .. | ... | |
| 56 | 448 | |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
https://en.wikipedia.org/wiki/User_Datagram_Protocol
UDP datagram header (8 bytes): be16 source port, destination port, length, checksum
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet | 0 | 1 | 2 | 3 |
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| 0 | 0 | Source port | Destination port |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
| 4 | 32 | Length | Checksum |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+