An IP datagram is a packet of data made up of two parts; the header and the payload. The payload is the data being sent, and usually used by a higher level application. The header is the IP information used by the IP. You can think of IP similar to a letter. A letter comes with two parts, the actual letter meant to be read by the recipient, and the envelope, which directs the post office on where to send the letter. The header is like the envelope.
Like a letter, the post office uses the information on the envelope to see where a letter is coming from and where it is going. You can also judge to see if the letter has been torn or damaged by looking at the envelope. If there are water stains and damage to the envelope, then the letter is probably damaged, and might need to even be re-written. The envelope will also give you hints as to what kind of letter you are getting. Is it a formal looking envelope from a business or a hand written letter from a friend?
An IP header contains similar information. It includes the source and destination addresses, error checking along with other information which helps deliver data across a network.
An IPv4 header has a larger number of fields than the more modern IPv6 headers. It begins with a version number. For an IPv4 packet, this will be the number 4. This field tells the IP protocol what version of the IP protocol is being used on this particular piece of data.
Next comes the Internet Header Length (IHL), which is 4 bits long and specifies the header length. The header length can range from 160 to 480 bits and is always a multiple of 32 bits. IPv4 needs to specify the header length due to the different options which can be added to the header.
Next comes the Type of Service or Differentiated Services Code Point (DSCP) field. This field is largely used for quality of service features such as determining the priority of a packet. For example, a voice over IP packet may be given higher priority over an HTTP packet.
Total Length is a 16-bit field used to define the length of the whole packet, including the header and the payload. This can range from 20 bytes of 65,535 bytes.
Identification contains a 16-bit value common to all fragments of a message. This is used to reassemble fragmented messages.
Flags specify whether a packet has been or is allowed to be fragmented.
Fragment Offset specifies where in a fragmented message this particular fragment occurred.
Time To Live specifies how many hops the packet can cross before being dropped. This prevents a packet from being sent back and forth forever.
Protocol identifies which higher-layer protocol is being carried in the data. Possibilities include TCP, UDP and ICMP.
The Header Checksum is a basic method of error detection. It is used to see if the header data was corrupted during transmission of the packet.
The Source Address and the Destination Address specify the originating and destination IP addresses for the packet.
Options is a rarely used field of several types of additional options.
Padding is used to make sure that the total header size is a multiple of 32 bits. Following all this comes the actual data inside the packet.
Like IPv4, IPv6 headers start with the Version number. The value 6 identifies the packet as an IPv6 packet.
This is followed by the Traffic Class. The Traffic Class specifies the priority of the packet by assigning a certain class to that packet. For example, a voice packet is probably going to have a higher priority than a data packet due to lag on voice communication being more noticeable.
This is followed by a Flow Label. Packets which belong to the same Flow Label should be routed through the same path. Packets with different Flow Labels can be routed to the same destination using different paths.
The Payload Length specifies the size of the post-header data.
The Next Header identifies the type of header immediately following the IPv6 header, for example a TCP or UDP header.
Hop Limit replaces the IPv4 Time to Live data. This specifies how many hops the packet can take before being dropped.
Source Address and Destination Address specify what IP address the packet originated from and what IP address it is being sent to.
Test your knowledge of IP header fields and the header order.