mafintosh / dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets
MIT License
201 stars 70 forks source link

How to encode/change rcode in a packet? #97

Open maxpain opened 6 months ago

jphgoo049 commented 4 months ago

I'm struggling with the same issue. Doesn't seem to be supported currently, even though it's present in the decoded packet object.

jphgoo049 commented 4 months ago

I've tested it and you just need to use bitwise operations to assign the flags according to the spec: https://www.rfc-editor.org/rfc/rfc1035.html#section-4.1.1

For example, setting flags: 1 << 12 changes the opcode to STATUS and flags: 3 changes the rcode to NXDOMAIN. You can combine multiple settings using bitwise or (|) e.g. flags: (1 << 12) | 3.