0

in Ipv4 packet

there are both IHL and Total Length i understand that there is a need to know the size of the data, but why would I want to count the header length in two places instead of having HIL and Data length?

i read rfc791

Total Length: 16 bits

Total Length is the length of the datagram, measured in octets, including internet header and data. This field allows the length of a datagram to be up to 65,535 octets. Such long datagrams are impractical for most hosts and networks. All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams.

The number 576 is selected to allow a reasonable sized data block to be transmitted in addition to the required header information. For example, this size allows a data block of 512 octets plus 64 header octets to fit in a datagram. The maximal internet header is 60 octets, and a typical internet header is 20 octets, allowing a margin for headers of higher level protocols.

but they didn't mention why it contains the header length

  • Does it matter though? There is a need to know the size of the data, yes, but there is also a need to know the size of the whole packet as well. If you had a "Data length" field instead, then the total length would have to be derived, and it's a single arithmetic operation either way so does it make a difference? – u1686_grawity Mar 19 '24 at 09:06
  • it reduces the maximum size of the payload, and there is probably a reason why it was designed this way – joe joe Mar 19 '24 at 12:04

1 Answers1

0

From Wikipedia Internet Protocol version 4 :

Internet Header Length (IHL)

The IPv4 header is variable in size due to the optional 14th field (options). The IHL field contains the size of the IPv4 header; it has 4 bits that specify the number of 32-bit words in the header. The minimum value for this field is 5,[32] which indicates a length of 5 × 32 bits = 160 bits = 20 bytes. As a 4-bit field, the maximum value is 15; this means that the maximum size of the IPv4 header is 15 × 32 bits = 480 bits = 60 bytes.

Total Length

This 16-bit field defines the entire packet size in bytes, including header and data. The minimum size is 20 bytes (header without data) and the maximum is 65,535 bytes. All hosts are required to be able to reassemble datagrams of size up to 576 bytes, but most modern hosts handle much larger packets. Links may impose further restrictions on the packet size, in which case datagrams must be fragmented. Fragmentation in IPv4 is performed in either the sending host or in routers. Reassembly is performed at the receiving host.

The difference is that the IHL indicates whether the Options field exists or not, and what is its size, since it's of a variable length.

The Total Length is required for indicating the size of the the data (packet payload) without the header, and for the simple sending and receiving of the message. Together with the IHL, it allows the message to be parsed.

harrymc
  • 480,290
  • but if all the added information I get from the total length is the size of the data why can't it have IHL and data length, why is the header size counted in both places, this way it reduces the max size of the data in the packet by the size of the header. – joe joe Mar 19 '24 at 10:31
  • The header size is only required when one needs to understand the contents of the package. See the layers architecture in the Internet protocol suite. While a message is being passed around the lower layers, its header is not parsed and the only data that matters is the total length. The header information is only meaningful for the higher layers. – harrymc Mar 19 '24 at 10:41
  • for this, the header needs to at least be partially parsed, meaning it needs to know the location of the total length in the header. why can't it also know the location of the header length and add them together? this way the protocol would support bigger messages – joe joe Mar 19 '24 at 11:06
  • Then a lower layer would do the work of a higher one. For the lower layers the data is just a string of bytes, there is no format or meaning. – harrymc Mar 19 '24 at 11:10
  • but currently, it still does if it needs to know the total size of the packet it needs to know how to get it from the higher layer – joe joe Mar 19 '24 at 11:32
  • The higher layer gets it from the lower one. – harrymc Mar 19 '24 at 12:11
  • I suggest to have a look at the article What Are the 5 Layer Protocols in TCP/IP? – harrymc Mar 19 '24 at 13:59