Search code examples
hexbyteresponseoffsetnameservers

hex offset sector


I'm getting a response from a nameserver which is longer then 512 bytes. in that response are some offsets. an offset from the beginning of the response is going fine, but when i get above 512 bytes the offset changes and it doesn't work anymore.

c0 0c = byte 12 from the start(works like a charm)

i have an offset:c1 f0 which means(in my knowledge so far)

c1 = 1 x 512 = 512
f0 = 240

c1 f0= byte 240 from byte 512 == byte 752

my offset should point to the beginning of a name, which should be located at byte 752 but at byte 752 the name isn't located.

Question
how does the offset work after 512 bytes?


Solution

  • It is a relative reference. In order to indicate that it is a relative reference, the first 2 bits are "reserved". You can reference a maximum of 14 bits: 2 bytes with the highest 2 bits are reserved. C0 01 is the reference offset 1. It does therefore not always have to be C0. it can also be C1, C2, C3, C4, CF etc. In practice this will be fairly rare unless you have a very complex long running queries which is the case. I have a query of 3000+ bytes:)

    C1 = 11000001
    strip 2 highest bits : 000001
    number = 1

    offset of C1 F0 is 1 x 256 + 240 = 496
    offset of C9 9F is 9 x 256 + 159 = 2463

    in one byte there are 256 combinations, not 512 which is used :S
    The max of C0 is C0 FF which is 255. after that C1 00 starts

    Credits of this explanation go to http://www.helpmij.nl/forum/member.php/215405-wampier