wire / wire-format / ipv4-header

IPv4 header

The IPv4 datagram header is at least 20 bytes: version/IHL, DSCP/ECN, total length, identification/flags/fragment-offset for fragmentation, TTL, protocol, header checksum, and the 32-bit source and destination addresses, followed by optional options. The IHL field gives the header length in 32-bit words.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: IP header · Internet Protocol v4 header

wire format

spec: RFC 791

Minimum 20-byte header. Carries addressing, fragmentation, a TTL hop limit, a protocol selector pointing at the next header (6 = TCP, 17 = UDP, 1 = ICMP), and a header-only checksum.

fieldsizemeaning
Version4 bitsIP version, 4 for IPv4.
IHL4 bitsInternet Header Length in 32-bit words (5 = 20 bytes minimum, up to 15 = 60 bytes).
DSCP6 bitsDifferentiated Services Code Point (QoS class); originally the Type of Service field.
ECN2 bitsExplicit Congestion Notification.
Total Length16 bitsEntire datagram size (header + data) in bytes, up to 65535.
Identification16 bitsFragment group id, used to reassemble fragments of one datagram.
Flags3 bitsBit 0 reserved (0), DF (Don't Fragment), MF (More Fragments).
Fragment Offset13 bitsPosition of this fragment in the original datagram, in 8-byte units.
Time to Live (TTL)8 bitsHop limit; decremented by each router, datagram dropped at 0.
Protocol8 bitsNext-layer protocol (per IANA): 1 ICMP, 6 TCP, 17 UDP, 41 IPv6-in-IPv4.
Header Checksum16 bitsOnes-complement checksum over the header only; recomputed at each hop (TTL changes).
Source Address32 bitsSender IPv4 address.
Destination Address32 bitsReceiver IPv4 address.
OptionsvariableOptional (record route, timestamp, etc.), padded to a 32-bit boundary; present only when IHL > 5.

example:

45 00 00 3C ...

First byte 0x45 = version 4, IHL 5 (20-byte header, no options). 0x00 = DSCP/ECN 0. 0x003C = total length 60 bytes.

see: wire-format/tcp-header · wire-format/udp-header


provenance

see also

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/ipv4-header or /wire-format/ipv4-header.json