dns-packet
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -9,2 +9,3 @@ var packet = require('./') | ||
id: 1, | ||
flags: packet.RECURSION_DESIRED, | ||
questions: [{ | ||
@@ -11,0 +12,0 @@ type: 'A', |
16
index.js
@@ -104,4 +104,7 @@ var types = require('./types') | ||
var flags = (h.flags || 0) & 32767 | ||
var type = h.type === 'response' ? RESPONSE_FLAG : QUERY_FLAG | ||
buf.writeUInt16BE(h.id || 0, offset) | ||
buf.writeUInt16BE(h.type === 'response' ? RESPONSE_FLAG : QUERY_FLAG, offset + 2) | ||
buf.writeUInt16BE(flags | type, offset + 2) | ||
buf.writeUInt16BE(h.questions.length, offset + 4) | ||
@@ -120,6 +123,8 @@ buf.writeUInt16BE(h.answers.length, offset + 6) | ||
if (buf.length < 12) throw new Error('Header must be 12 bytes') | ||
var flags = buf.readUInt16BE(offset + 2) | ||
return { | ||
id: buf.readUInt16BE(offset), | ||
type: buf.readUInt16BE(offset + 2) & RESPONSE_FLAG ? 'response' : 'query', | ||
type: flags & RESPONSE_FLAG ? 'response' : 'query', | ||
flags: flags & 32767, | ||
questions: new Array(buf.readUInt16BE(offset + 4)), | ||
@@ -508,2 +513,9 @@ answers: new Array(buf.readUInt16BE(offset + 6)), | ||
exports.AUTHORITATIVE_ANSWER = 1 << 10 | ||
exports.TRUNCATED_RESPONSE = 1 << 9 | ||
exports.RECURSION_DESIRED = 1 << 8 | ||
exports.RECURSION_AVAILABLE = 1 << 7 | ||
exports.AUTHENTIC_DATA = 1 << 5 | ||
exports.CHECKING_DISABLED = 1 << 4 | ||
exports.encode = function (result, buf, offset) { | ||
@@ -510,0 +522,0 @@ if (!buf) buf = Buffer(exports.encodingLength(result)) |
{ | ||
"name": "dns-packet", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "An abstract-encoding compliant module for encoding / decoding DNS packets", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -23,2 +23,3 @@ # dns-packet | ||
id: 1, | ||
flags: packet.RECURSION_DESIRED, | ||
questions: [{ | ||
@@ -59,2 +60,3 @@ type: 'A', | ||
id: optionalIdNumber, | ||
flags: optionalBitFlags, | ||
questions: [...], | ||
@@ -67,2 +69,25 @@ answers: [...], | ||
The bit flags available are | ||
``` js | ||
packet.RECURSION_DESIRED | ||
packet.RECURSION_AVAILABLE | ||
packet.TRUNCATED_RESPONSE | ||
packet.AUTHORITATIVE_ANSWER | ||
packet.AUTHENTIC_DATA | ||
packet.CHECKING_DISABLED | ||
``` | ||
To use more than one flag bitwise-or them together | ||
``` js | ||
var flags = packet.RECURSION_DESIRED | packet.RECURSION_AVAILABLE | ||
``` | ||
And to check for a flag use bitwise-and | ||
``` js | ||
var isRecursive = message.flags & packet.RECURSION_DESIRED | ||
``` | ||
A question looks like this | ||
@@ -69,0 +94,0 @@ |
@@ -100,2 +100,3 @@ var tape = require('tape') | ||
type: 'response', | ||
flags: packet.TRUNCATED_RESPONSE, | ||
answers: [{ | ||
@@ -122,2 +123,3 @@ type: 'A', | ||
id: 100, | ||
flags: 0, | ||
additionals: [{ | ||
@@ -124,0 +126,0 @@ type: 'AAAA', |
25454
713
198