friendev EtherDune TCP/IP library
|
IP header. More...
#include <inet.h>
Public Attributes | |
struct { | |
struct { | |
uint8_t IHL: 4 | |
Internet Header Length. More... | |
uint8_t version: 4 | |
Protocol version. More... | |
} | |
struct { | |
uint8_t ECN: 2 | |
Explicit Congestion Notification. More... | |
uint8_t DSCP: 6 | |
Differentiated Services Code Point. More... | |
} | |
nint16_t totalLength | |
This 16-bit field defines the entire packet (fragment) size, including header and data, in bytes. More... | |
nint16_t identification | |
Identification. More... | |
struct { | |
uint16_t fragmentOffset: 13 | |
Fragment Offset. More... | |
uint16_t flags: 3 | |
Flags. More... | |
} | |
uint8_t TTL | |
Time To Live. More... | |
uint8_t protocol | |
Protocol. More... | |
nint16_t checksum | |
Header Checksum. More... | |
IPAddress sourceIP | |
Source address. More... | |
IPAddress destinationIP | |
Destination address. More... | |
}; | |
uint8_t | raw [20] |
byte-wise access to all fields More... | |
struct { ... } |
nint16_t IPHeader::checksum |
Header Checksum.
The 16-bit checksum field is used for error-checking of the header. When a packet arrives at a router, the router calculates the checksum of the header and compares it to the checksum field. If the values do not match, the router discards the packet. Errors in the data field must be handled by the encapsulated protocol. Both UDP and TCP have checksum fields. When a packet arrives at a router, the router decreases the TTL field. Consequently, the router must calculate a new checksum. RFC 1071 defines the checksum calculation.
IPAddress IPHeader::destinationIP |
uint8_t IPHeader::ECN |
Explicit Congestion Notification.
This field is defined in RFC 3168 and allows end-to-end notification of network congestion without dropping packets. ECN is an optional feature that is only used when both endpoints support it and are willing to use it. It is only effective when supported by the underlying network.
uint16_t IPHeader::flags |
Flags.
A three-bit field follows and is used to control or identify fragments. They are (in order, from high order to low order): bit 0: Reserved; must be zero.[note 1] bit 1: Don't Fragment (DF) bit 2 : More Fragments(MF) If the DF flag is set, and fragmentation is required to route the packet, then the packet is dropped.This can be used when sending packets to a host that does not have sufficient resources to handle fragmentation.It can also be used for Path MTU Discovery, either automatically by the host IP software, or manually using diagnostic tools such as ping or traceroute.For unfragmented packets, the MF flag is cleared.For fragmented packets, all fragments except the last have the MF flag set.The last fragment has a non - zero Fragment Offset field, differentiating it from an unfragmented packet.
uint16_t IPHeader::fragmentOffset |
Fragment Offset.
The fragment offset field, measured in units of eight-byte blocks (64 bits), is 13 bits long and specifies the offset of a particular fragment relative to the beginning of the original unfragmented IP datagram. The first fragment has an offset of zero. This allows a maximum offset of (213 – 1) × 8 = 65,528 bytes, which would exceed the maximum IP packet length of 65,535 bytes with the header length included (65,528 + 20 = 65,548 bytes).
nint16_t IPHeader::identification |
Identification.
This field is an identification field and is primarily used for uniquely identifying the group of fragments of a single IP datagram.Some experimental work has suggested using the ID field for other purposes, such as for adding packet - tracing information to help trace datagrams with spoofed source addresses, [13] but RFC 6864 now prohibits any such use.
uint8_t IPHeader::IHL |
Internet Header Length.
The second field (4 bits) is the Internet Header Length (IHL), which is the number of 32-bit words in the header. Since an IPv4 header may contain a variable number of options, this field specifies the size of the header (this also coincides with the offset to the data). The minimum value for this field is 5 (RFC 791), which is a length of 5×32 = 160 bits = 20 bytes. Being a 4-bit value, the maximum length is 15 words (15×32 bits) or 480 bits = 60 bytes.
uint8_t IPHeader::protocol |
IPAddress IPHeader::sourceIP |
nint16_t IPHeader::totalLength |
This 16-bit field defines the entire packet (fragment) size, including header and data, in bytes.
The minimum-length packet is 20 bytes (20-byte header + 0 bytes data) and the maximum is 65,535 bytes — the maximum value of a 16-bit word. All hosts are required to be able to reassemble datagrams of size up to 576 bytes, but most modern hosts handle much larger packets. Sometimes subnetworks impose further restrictions on the packet size, in which case datagrams must be fragmented. Fragmentation is handled in either the host or router in IPv4.
uint8_t IPHeader::TTL |
Time To Live.
An eight-bit time to live field helps prevent datagrams from persisting (e.g. going in circles) on an internet. This field limits a datagram's lifetime. It is specified in seconds, but time intervals less than 1 second are rounded up to 1. In practice, the field has become a hop count—when the datagram arrives at a router, the router decrements the TTL field by one. When the TTL field hits zero, the router discards the packet and typically sends an ICMP Time Exceeded message to the sender. The program traceroute uses these ICMP Time Exceeded messages to print the routers used by packets to go from the source to the destination.
uint8_t IPHeader::version |