Internet Protocol Version 4
Internet Protocol Version 4
Internet IPv4 short for Internet Protocol Version 4 is the fourth version of the Internet Protocol (IP).
IP is responsible to deliver data packets from the source host to the destination host.
This delivery is solely based on the IP Addresses in the packet headers.
IPv4 is the first major version of IP.
IPv4 is a connectionless protocol for use on packet-switched networks.
IPv4 Header-
The following diagram represents the IPv4 header-
1. Version-
Version is a 4 bit field that indicates the IP version used.
The most popularly used IP versions are version-4 (IPv4) and version-6 (IPv6).
Only IPv4 uses the above header.
So, this field always contains the decimal value 4.
2. Header Length-
Header length is a 4 bit field that contains the length of the IP header.
It helps in knowing from where the actual data begins.
Minimum And Maximum Header Length- The length of IP header always lies in the range-
[20 bytes , 60 bytes]
The initial 5 rows of the IP header are always used.
So, minimum length of IP header = 5 x 4 bytes = 20 bytes.
The size of the 6th row representing the Options field vary.
The size of Options field can go up to 40 bytes.
So, maximum length of IP header = 20 bytes + 40 bytes = 60 bytes.
Concept of Scaling Factor-
Header length is a 4 bit field.
So, the range of decimal values that can be represented is [0, 15].
But the range of header length is [20, 60].
So, to represent the header length, we use a scaling factor of 4.
Examples-
If header length field contains decimal value 5 (represented as 0101), then-
Header length = 5 x 4 = 20 bytes
If header length field contains decimal value 10 (represented as 1010), then-
Header length = 10 x 4 = 40 bytes
If header length field contains decimal value 15 (represented as 1111), then-
Header length = 15 x 4 = 60 bytes
3. Type Of Service-
Type of service is a 8 bit field that is used for Quality of Service (QoS).
The datagram is marked for giving a certain treatment using this field.
4. Total Length-
Total length is a 16 bit field that contains the total length of the datagram (in bytes).
Total length = Header length + Payload length
Minimum total length of datagram = 20 bytes (20 bytes header + 0 bytes data)
Maximum total length of datagram = Maximum value of 16 bit word = 65535 bytes
5. Identification-
Identification is a 16 bit field.
It is used for the identification of the fragments of an original IP datagram.
When an IP datagram is fragmented,
Each fragmented datagram is assigned the same identification number.
This number is useful during the re assembly of fragmented datagrams.
It helps to identify to which IP datagram, the fragmented datagram belongs to.
6. DF Bit-
DF bit stands for Do Not Fragment bit.
Its value may be 0 or 1.
When DF bit is set to 0,
It grants the permission to the intermediate devices to fragment the datagram if required.
When DF bit is set to 1,
It indicates the intermediate devices not to fragment the IP datagram at any cost.
If network requires the datagram to be fragmented to travel further but settings does not allow its
fragmentation, then it is discarded.
An error message is sent to the sender saying that the datagram has been discarded due to its settings.
7. MF Bit-
MF bit stands for More Fragments bit.
Its value may be 0 or 1.
When MF bit is set to 0,
It indicates to the receiver that the current datagram is either the last fragment in the set or that it is the
only fragment.
When MF bit is set to 1,
8. Fragment Offset-
Fragment Offset is a 13 bit field.
It indicates the position of a fragmented datagram in the original unfragmented IP datagram.
The first fragmented datagram has a fragment offset of zero.
Fragment offset for a given fragmented datagram
= Number of data bytes ahead of it in the original unfragmented datagram
Concept Of Scaling Factor-
We use a scaling factor of 8 for the fragment offset.
Fragment offset field value = Fragment Offset / 8
Datagram takes a hop to the destination.
If the value of TTL becomes zero before reaching the destination, then datagram is discarded.
NOTES
It is important to note-
Both intermediate devices having network layer and destination decrements the TTL value by 1.
If the value of TTL is found to be zero at any intermediate device, then the datagram is discarded.
So, at any intermediate device, the value of TTL must be greater than zero to proceed further.
If the value of TTL becomes zero at the destination, then the datagram is accepted.
So, at the destination, the value of TTL may be greater than or equal to zero.