Reputation: 8610
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.
Upvotes: 5
Views: 33086
Reputation: 659
The Internet Header Length (IHL) field is the number of 32-bit words(=4 bytes) in the IPv4 header, including any options. Because this is also a 4-bit field, the IPv4 header is limited to a maximum of fifteen 32-bit words(=60 bytes)
So if the value of IHL is 0101(5), then the IP-header's length is 5*4(bytes) = 20(bytes)
Upvotes: 0
Reputation: 689
minimum value of header length is 20 Bytes but we don't have sufficient bits to represent 20 so we use scaling technique, i.e. 0101 (5) will represent 4 X 5 = 20 Bytes, here scaling factor is 4.
maximum value possible with 4 bits is 15.
So maximum header length possible is 4 X 15 = 60 Bytes.
Header Length | Header Length Field
20 -----> 5
24 -----> 6
28 -----> 7
.
.
.
60 -----> 15
if header length is 22 Bytes then we use padding to make it a multiple of 4 i.e. 24 Bytes
Upvotes: 5
Reputation: 125
@Amit>Value in the HL filed is = the number of 4 bytes in the total IP header length.Means if the header length field is say 40,then calculate how many 4 bytes in 40?its 40/4= 10.So value in the HL field is 10
Minimum HL is 20 byte .ie no of 4bytes in 20 = 20/4=5.So minimum value in HL field is 5.
HL is a 4 bit field.so the maximum vale that can be accomadated in that field is 15(1111) or you can calculate using the formulae 2^4-1=15.So max no: of 4 bytes can be 15.Hence the Max header length=15*4=60bytes.
Hope now things are clear.
Upvotes: 1
Reputation: 182619
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.
Upvotes: 12