Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer with NXDomain #61

Open
ndmgrphc opened this issue Sep 25, 2020 · 2 comments
Open

Answer with NXDomain #61

ndmgrphc opened this issue Sep 25, 2020 · 2 comments

Comments

@ndmgrphc
Copy link

This is a wonderful library. I am curious how to structure query responses in cases where you want to authoritatively answer that this domain cannot be found.

I found the following article: Know thy DNS: Understanding the four most common DNS response codes

Unless I missed something, would it be worthwhile to document how to formulate (and return) the NXDOMAIN response?

@nhnt11
Copy link

nhnt11 commented Jan 22, 2021

+1. It seems it trivially works to set the last two bits of the flags bitfield in the param object passed to encode. (the last 4 bits are the rcode, and NXDOMAIN is 0x03). So e.g.:

let NXDOMAIN_RCODE = 0x03;
dnsPacket.encode({
  type: "response",
  id,
  flags: dnsPacket.RECURSION_DESIRED | NXDOMAIN_RCODE,
  questions,
  answers,
});

(see

const flags = (h.flags || 0) & 32767
)

@jphgoo049
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants