I am trying to decode DNS packets in C #, and although this does not really matter, I use SharpPcap .
Everything works well, but it seems that the QR and RCODE fields are returning incorrect values. I compare my results with the results of Wireshark.
QR is always 1 (reply), even if the message is a request. Another strange thing that happens is that the return code is 0 when the message is a request and 1 when the message is a response.
One of the sites I used to determine the DNS header was this . Is something missing here? The code I use to decode the packet is: (the data is a byte array that contains the payload data)
The getBit method is here:
public static bool getBit(byte b, int index) { //Logical AND with number to find if bit is 0 or 1 //Shift by index to represent value in binary (2^index) bool bit = (b & (1 << index)) != 0; return (bit); }
source share