1. Introduction
Internet Protocol (IP) is the communications protocol in the network layer. Its main operation is routing. It forwards packets originating at a host to their destination, one router at a time.
In short, the transport layer breaks up data streams into IP packets. Then, IP routers forward these packets through the Internet. Next, the network layer reassembles all the packets at the destination into the original stream. Finally, the transport layer takes and processes the data.
Different computer networks make the Internet as we know it interconnected through routers. These devices must break the IP packets into smaller parts to support variable bit rate data streams. This technique is called fragmentation.
In this tutorial, we’ll discuss the IPv4 datagram in detail.
2. IPv4 Datagram
IPv4 was developed in 1981, and it’s still widely used. It uses 32-bit address space.
An IPv4 packet is called a datagram. It contains a header and a data part.
The IPv4 header contains a 20-byte fixed mandatory part, followed by optional fields. Hence, the minimum size of an IPv4 header is 20 bytes.
The optional part contains options and padding. It can grow up to 40 bytes in size. So, the maximum header size is 60 bytes.
A datagram can carry up to 65,535 bytes of data (), at least 20 bytes of it being the header. Hence, the maximum amount of data it carries is 65,515 bytes.
The header part contains 14 fields. The first 13 are mandatory. The last one is the optional field called options. First, let’s look at the individual header fields.
2.1. Version
IP version field, set to 4 for IPv4.
2.2. Internet Header Length
IHL is the number of 32-bit words making up the header field. As the first 20 bytes are mandatory, the minimum number is 5, and the maximum is 15.
2.3. Differentiated Services Code Point (DSCP)
It specifies the type of service for differentiated services, such as voice-over IP.
2.4. Explicit Congestion Notification (ECN)
ECN carries a network congestion notification without dropping packets or wasting bandwidth when supported.
2.5. Total Length
It represents the total size of the datagram, including the header and the data segment.
2.6. Identification
This field uniquely identifies the group of fragments of a single IP datagram.
2.7. Flags
Different combinations of the flags control the fragmentation and indicate fragmented datagrams.
For example, if the don’t fragment flag (bit 1) is set to 1, and the destination host can’t assemble the fragmented packets, it will drop them.
2.8. Fragment Offset
It contains the offset of a fragmented packet.
2.9. Time to Live (TTL)
The number of hops a packet lives. Each router decrements the TTL field and discards the packet when it reaches 0. This way, looping packets are eliminated.
2.10. Protocol
It’s the protocol for the data part.
2.11. Header Checksum
It’s a checksum for error detection, covering only the header field. Each router checks this value and discards the packet if an error is detected.
Uncorrupted packets return 0 when summing the whole header, including the checksum itself.
2.12. Source Address
Source host IPv4 address.
2.13. Destination Address
Destination host IPv4 address.
2.14. Options
Additional options are stored in this field when present.
3. Conclusion
In this article, we’ve learned about the most widely used network communications protocol. Then we investigated the structure of a datagram.