friendev EtherDune TCP/IP library
Public Attributes | List of all members
IPHeader Union Reference

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...
 

Detailed Description

IP header.

Definition at line 296 of file inet.h.

Member Data Documentation

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.

Definition at line 319 of file inet.h.

IPAddress IPHeader::destinationIP

Destination address.

This field is the IPv4 address of the receiver of the packet. As with the source address, this may be changed in transit by a network address translation device.

Definition at line 321 of file inet.h.

uint8_t IPHeader::DSCP

Differentiated Services Code Point.

Definition at line 308 of file inet.h.

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.

Definition at line 307 of file inet.h.

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.

Definition at line 315 of file inet.h.

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).

Definition at line 314 of file inet.h.

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.

Definition at line 311 of file inet.h.

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.

Definition at line 302 of file inet.h.

uint8_t IPHeader::protocol

Protocol.

This field defines the protocol used in the data portion of the IP datagram. The Internet Assigned Numbers Authority maintains a list of IP protocol numbers which was originally defined in RFC 790.

Definition at line 318 of file inet.h.

uint8_t IPHeader::raw[20]

byte-wise access to all fields

Definition at line 323 of file inet.h.

IPAddress IPHeader::sourceIP

Source address.

This field is the IPv4 address of the sender of the packet. Note that this address may be changed in transit by a network address translation device.

Definition at line 320 of file inet.h.

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.

Definition at line 310 of file inet.h.

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.

Definition at line 317 of file inet.h.

uint8_t IPHeader::version

Protocol version.

The first header field in an IP packet is the four-bit version field. For IPv4, this has a value of 4 (hence the name IPv4).

Definition at line 303 of file inet.h.


The documentation for this union was generated from the following file: