From 64a2b4ac1d9c66eecb047291ce6722eb0c2698fb Mon Sep 17 00:00:00 2001 From: Supereg Date: Tue, 5 May 2020 06:09:30 +0200 Subject: [PATCH] Include the raw record data in the decoded record object --- index.js | 4 ++++ test.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/index.js b/index.js index c56756b..da00428 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,8 @@ const NOT_FLUSH_MASK = ~FLUSH_MASK const QU_MASK = 1 << 15 const NOT_QU_MASK = ~QU_MASK +exports.classes = classes +exports.types = types const name = exports.txt = exports.name = {} name.encode = function (str, buf, offset) { @@ -1374,6 +1376,8 @@ answer.decode = function (buf, offset) { const enc = renc(a.type) a.data = enc.decode(buf, offset + 8) offset += 8 + enc.decode.bytes + + a.rawData = buf.slice(offset - enc.decode.bytes, offset) // we need the raw buffer for simultaneous probe tiebreaking } answer.decode.bytes = offset - oldOffset diff --git a/test.js b/test.js index cfec42a..51cf720 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,7 @@ 'use strict' const tape = require('tape') +const ip = require('ip') const packet = require('./') const rcodes = require('./rcodes') const opcodes = require('./opcodes') @@ -546,6 +547,28 @@ tape('unpack', function (t) { t.end() }) +tape('rawRecordData', function (t) { + const encoded = packet.encode({ + type: 'response', + answers: [{ + name: 'hello.a.com', + type: 'A', + class: 'IN', + data: '127.0.0.1' + }] + }) + + const aData = Buffer.allocUnsafe(6) + aData.writeUInt16BE(4, 0) + ip.toBuffer('127.0.0.1', aData, 2) + + const decoded = packet.decode(encoded) + const rawData = decoded.answers[0].rawData + + t.ok(aData.toString('hex') === rawData.toString('hex')) + t.end() +}) + tape('optioncodes', function (t) { const opts = [ [0, 'OPTION_0'],