Skip to content

NXDOMAIN response flag for empty answer #5

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion convenient.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ function final_response(res, value) {

res.authoritative = !! soa_record

// Empty replies need to get the NXDOMAIN flag set
if(typeof value == 'undefined') {
res.not_found = true
}

// Add convenience for typical name resolution.
if(questions.length == 1 && question.kind() == 'IN A') {
else if(questions.length == 1 && question.kind() == 'IN A') {
// If the value given is an IP address, make that the answer.
if(typeof value == 'string' && answers.length == 0)
res.answer.push({'class':'IN', 'type':'A', 'name':question.name, 'data':value})
Expand Down
3 changes: 2 additions & 1 deletion encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ State.prototype.message = function(msg) {
byte |= msg.recursion_available ? 0x80 : 0x00
byte |= msg.authenticated ? 0x20 : 0x00
byte |= msg.checking_disabled ? 0x10 : 0x00
byte |= msg.not_found ? 0x03 : 0x00
byte |= (msg.responseCode & 0x0f)

self.header.writeUInt8(byte, 3)
Expand Down Expand Up @@ -211,7 +212,7 @@ State.prototype.encode = function(full_domain, position_offset, option) {
, bytes

var i = 0
var max_iterations = 40 // Enough for 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
var max_iterations = 80 // Enough for 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa

while(++i < max_iterations) {
if(domain == '') {
Expand Down
1 change: 1 addition & 0 deletions message.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function DNSMessage (body) {
this.recursion_available = null
this.authenticated = null
this.checking_disabled = null
this.not_found = null

if(Buffer.isBuffer(body))
this.parse(body)
Expand Down