fix: flush and class (#28)

This commit is contained in:
Richard Schneider 2018-02-05 07:59:47 +13:00 committed by silverwind
parent 84589e7026
commit 600d4acd90
2 changed files with 14 additions and 3 deletions

View File

@ -680,11 +680,11 @@ answer.decode = function (buf, offset) {
a.name = name.decode(buf, offset) a.name = name.decode(buf, offset)
offset += name.decode.bytes offset += name.decode.bytes
a.type = types.toString(buf.readUInt16BE(offset)) a.type = types.toString(buf.readUInt16BE(offset))
a.class = classes.toString(buf.readUInt16BE(offset + 2)) const klass = buf.readUInt16BE(offset + 2)
a.ttl = buf.readUInt32BE(offset + 4) a.ttl = buf.readUInt32BE(offset + 4)
a.flush = !!(a.class & FLUSH_MASK) a.class = classes.toString(klass & NOT_FLUSH_MASK)
if (a.flush) a.class &= NOT_FLUSH_MASK a.flush = !!(klass & FLUSH_MASK)
const enc = renc(a.type) const enc = renc(a.type)
a.data = enc.decode(buf, offset + 8) a.data = enc.decode(buf, offset + 8)

11
test.js
View File

@ -153,6 +153,17 @@ tape('query', function (t) {
}) })
tape('response', function (t) { tape('response', function (t) {
testEncoder(t, packet, {
type: 'response',
answers: [{
type: 'A',
class: 'IN',
flush: true,
name: 'hello.a.com',
data: '127.0.0.1'
}]
})
testEncoder(t, packet, { testEncoder(t, packet, {
type: 'response', type: 'response',
flags: packet.TRUNCATED_RESPONSE, flags: packet.TRUNCATED_RESPONSE,