Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate IP-header length?

I want to calculate IP-header length with following statement:

Header Length is a four-bit field that tells, as the name implies, the length of the IP header in 32-bit words

Now I'm getting difficulties in calculating IP header length (minimum and maximum), with four-bit field.

like image 782
Amit Singh Tomar Avatar asked Jul 26 '12 11:07

Amit Singh Tomar


1 Answers

  • The minimum length of an IPv4 header of a valid datagram is 20 bytes, when the value reads 5 and there are no options
  • Since the field is 4 bits wide, the maximum value it can store is 15, thus the maximum length of the header is 60 bytes.

Internet Header Length is the length of the internet header in 32 bit words, and thus points to the beginning of the data. Note that the minimum value for a correct header is 5.

Which means whatever value is stored in the IHL, it should be multiplied with 32 to get the total number of bits, or with 4 to get the total number of bytes.

like image 156
cnicutar Avatar answered Oct 12 '22 04:10

cnicutar