Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Include the raw record data in the decoded record object
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed May 5, 2020
1 parent 4664846 commit 64a2b4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 64a2b4a

Please sign in to comment.