Ipv4 Header in Computer Networks - 2
Ipv4 Header in Computer Networks - 2
Introduction
The IPv4 header is a fixed-size, 20-byte (160-bit) data structure that is appended to the
beginning of every IPv4 packet. This header contains essential information that routers and
networking devices use to route, forward, and deliver data packets from the source to the
destination. The IPv4 header is divided into several fields, each serving a specific purpose in
the packet delivery process.
The IPv4 header consists of 12 fields, which are organized in the following manner:
ADVERTISEMENT
1. Version (4 bits): This field specifies the version of the IP protocol being used, which
is IPv4 in this case.
Very Heavy Trucks Transport Indian Food From Town Properly, Having Sweet Dishes
Vikas Har Taraf Tufan Failata, Fauji Tatha Police Hume Suraksha Deti
2. Header Length (4 bits): The header length field indicates the length of the IPv4
header in 32-bit words. Since the header is a fixed size of 20 bytes, the value of this
field is typically 5.
3. Type of Service (8 bits): This field is used to define the quality of service (QoS) for
the packet, including priorities and other parameters for routing and processing.
4. Total Length (16 bits): The total length field specifies the length of the entire IPv4
packet, including both the header and the data, in bytes.
5. Identification (16 bits): The identification field is used for packet fragmentation and
reassembly. It helps in grouping fragments of a larger packet together.
6. Flags (3 bits): These bits are used for controlling and identifying packet
fragmentation. The flags include the "Don't Fragment" (DF) and "More Fragments"
(MF) flags.
7. Fragment Offset (13 bits): The fragment offset field specifies the position of the
fragment within the original packet. It is used to reassemble fragmented packets
correctly.
8. Time to Live (TTL) (8 bits): The TTL field represents the maximum number of hops
(routers or network segments) that the packet can traverse before it is discarded. Each
router decrements this value by one.
9. Protocol (8 bits): This field indicates the type of protocol used in the data portion of
the packet, such as TCP, UDP, ICMP, or others.
10. Header Checksum (16 bits): The header checksum field is used to verify the
integrity of the IPv4 header during transmission. Routers and devices recalculate this
checksum to check for errors. Error checking for header only
11. Source IP Address (32 bits): This field contains the IP address of the sender or
source of the packet.
12. Destination IP Address (32 bits): This field holds the IP address of the recipient or
destination of the packet.
Version and Header Length: These fields identify the version of the IP protocol and
the length of the header, respectively.
Type of Service: The Type of Service field is used to classify packets based on their
requirements, allowing for differentiated handling of various types of traffic.
Total Length: This field specifies the overall length of the packet, ensuring that
routers and devices can process it correctly.
Identification, Flags, and Fragment Offset: These fields facilitate packet
fragmentation and reassembly, crucial for handling large packets that cannot be
transmitted in one piece.
TTL: The Time to Live field prevents packets from circulating endlessly in the
network by specifying a maximum number of hops they can take.
Protocol: The Protocol field indicates the transport layer protocol used in the packet,
enabling routers to forward the packet to the appropriate service.
Header Checksum: This checksum verifies the integrity of the header, reducing the
chances of forwarding corrupted packets.
Source and Destination IP Addresses: These fields specify the source and
destination of the packet, allowing routers to make routing decisions based on the
destination address.
Conclusion
The IPv4 header is a critical component of computer networks, serving as a roadmap for data
packets as they traverse the internet and other interconnected networks. Its structured fields
contain essential information that routers and networking devices rely on for routing,
forwarding, and delivering packets accurately and efficiently.
In UDP, the header size is 8 bytes, and the packet size is upto 65,535 bytes. But this packet
size is not possible as the data needs to be encapsulated in the IP datagram, and an IP packet,
the header size can be 20 bytes; therefore, the maximum of UDP would be 65,535 minus 20.
The size of the data that the UDP packet can carry would be 65,535 minus 28 as 8 bytes for
the header of the UDP packet and 20 bytes for IP header.
Source port number: It is 16-bit information that identifies which port is going t
send the packet.
Destination port number: It identifies which port is going to accept the information.
It is 16-bit information which is used to identify application-level service on the
destination machine.
Length: It is 16-bit field that specifies the entire length of the UDP packet that
includes the header also. The minimum value would be 8-byte as the size of the
header is 8 bytes.
Checksum: It is a 16-bits field, and it is an optional field. This checksum field checks
whether the information is accurate or not as there is the possibility that the
information can be corrupted while transmission. It is an optional field, which means
that it depends upon the application, whether it wants to write the checksum or not. If
it does not want to write the checksum, then all the 16 bits are zero; otherwise, it
if unused: all 16 bits are set to 0.
writes the checksum. In UDP, the checksum field is applied to the entire packet, i.e.,
header as well as data part whereas, in IP, the checksum field is applied to only the
header field.
The header of a TCP segment can range from 20-60 bytes. 40 bytes are for options. If there
are no options, a header is 20 bytes else it can be of upmost 60 bytes.
Header fields:
Sequence Number –
A 32-bit field that holds the sequence number, i.e, the byte number of the first byte
that is sent in that particular segment. It is used to reassemble the message at the
receiving end of the segments that are received out of order.
Control flags –
These are 6 1-bit control bits that control connection establishment, connection
termination, connection abortion, flow control, mode of transfer etc. Their function
is:
o URG: Urgent pointer is valid
Urgent Aunty o ACK: Acknowledgement number is valid( used in case of cumulative
acknowledgement)
Pushes Red o PSH: Request for push
Scooters Fast o RST: Reset the connection
o SYN: Synchronize sequence numbers
o FIN: Terminate the connection
Window size –
This field tells the window size of the sending TCP in bytes. Size of sender’s window for flow control
Checksum –
This field holds the checksum for error control. It is mandatory in TCP as opposed to
UDP.
Urgent pointer –
This field (valid only if the URG control flag is set) is used to point to data that is
urgently required that needs to reach the receiving process at the earliest. The value of
this field is added to the sequence number to get the byte number of the last urgent
byte.
The Transmission Control Protocol (TCP) checksum is a method used to detect errors in TCP
packets. The checksum is calculated by taking the binary value of all the fields in the TCP
header and the data, treating them as a large integer, and then performing a bit-wise ones
complement on that integer.
To calculate the TCP checksum, the following steps are performed −
Here is an example of how the TCP checksum might be calculated for a packet −
Suppose the source IP address is 192.168.0.1, the destination IP address is 192.168.0.2, the
reserved field is 0, the protocol field is 6 for TCP, the TCP length is 40 bytes, and the TCP
data is "Hello, World!".
It's important to note that the checksum is calculated over the TCP segment, and the
checksum field is computed before the segment is sent, and verified after the segment is
received. The receiver computes the checksum again and compares it to the checksum field.
If the computed and received checksum values match, it is assumed that the segment was
received without error; otherwise, the segment is discarded.
This is a basic overview of how the TCP checksum is calculated. It is an important technique
to make sure the data integrity while sending over the network, which is critical in
maintaining secure and reliable communication.
TCP Header
The Transmission Control Protocol (TCP) header is a set of fields that are included at the
beginning of a TCP segment. The header contains information that is used to control the
establishment, maintenance, and termination of a TCP connection. The TCP header is
typically 20 bytes in length, but it can be up to 60 bytes if options are included.
Source Port − 16-bit field that identifies the port on the source host where the
segment originated.
Destination Port − 16-bit field that identifies the port on the destination host where
the segment is being sent.
Sequence Number − 32-bit field that identifies the byte number of the first data byte
in the current segment.
Acknowledgment Number − 32-bit field that acknowledges receipt of all bytes up to
the value in this field.
Data Offset − 4-bit field that indicates the number of 32-bit words in the TCP header.
Reserved − 6-bit field that is reserved for future use.
Flags − 6-bit field that contains various control flags, including the URG, ACK, PSH,
RST, SYN, and FIN flags.
Window − 16-bit field that indicates the size of the receive window.
Checksum − 16-bit field that is used to detect errors in the TCP segment.
Urgent Pointer − 16-bit field that, if the URG flag is set, indicates the byte number
of the last byte of urgent data in the current segment.
The combination of the source IP address, source port, destination IP address, and destination
port forms a unique identifier for each TCP connection, known as a socket. The sequence and
acknowledgement numbers, along with the window and flags fields, are used to control the
flow of data during a TCP connection.
TCP uses the fields in the header to provide a reliable, connection-oriented communication
service. It guarantees that data sent is received and that it is received in the correct order. This
is why TCP is commonly used in applications that require reliable data transfer, such as file
transfers and email.
Examples
The TCP checksum is calculated by taking the binary value of all the fields in the TCP header
and the data, treating them as a large integer, and then performing a bit-wise ones
complement on that integer. Here are a couple of examples of how the TCP checksum might
be calculated −
Example 1
Suppose the source IP address is 192.168.1.1, the destination IP address is 192.168.1.2, the
reserved field is 0, the protocol field is 6 for TCP, the TCP length is 40 bytes, and the TCP
data is "Hello, World!".
Example 2
Suppose the source IP address is 172.16.1.1, the destination IP address is 172.16.1.2, the
reserved field is 0, the protocol field is 6 for TCP, the TCP length is 100 bytes and the TCP
data is "TCP checksum calculation example."