Re: IHL vs shift 6 vs accurate location in upper layers
Andy Furniss <[email protected]>
| Newsgroups | org.kernel.vger.lartc |
|---|---|
| Message-ID | <[email protected]> |
jsl6uy js16uy wrote: > Hello all hope all is well > > I looked around and have tried to get this sorted on multiple > occasions, but just can't get it > how does dividing by 64/2^6, ~ shift 6, ultimately get you to > something like the proper location for a src port in layer 4? > I get, after reading again and again and looking at ip packet header > diagrams, offset at 0 and the mask used to extract the IHL from the > 16bit word. > But then comes 'ol shift 6 ... right-shifting by 6 eliminates the > offset of the field and at the same time converts the value into byte > unit ....and I am lost again > IHL # 32 bit words I guess dividing by 64 bits will get you bytes > multiples 8 and then I have nothing > > googling around verified binary math and this is dividing by 64, but > that's where it ends, anything else is people just using it. I figure > I must be missing the deal. > Would like to understand it to fully use If you read the first 16 bits and mask to leave just IHL then you get (assuming normal IHL = 5) 0000 0101 0000 0000 this is not 5 (101 in binary) to get 5 you would need to right shift by 8 = 0000 0000 0000 0101. Your examples want IHL in bytes (octets) and since IHL is in units of 32 bits you need to multiply by 4 to get bytes. left shift by 2 is x4 so instead of right shift 8, right shift 6 gives the IHL x4 = bytes 0000 0000 0001 0100 = 20. Either way you know the header length and for tcp or udp the next 16 bits will be the source port.