From 05beaa480b3c4121afc8a0bef15a70c40d8718be Mon Sep 17 00:00:00 2001 From: Daplie Date: Wed, 8 Mar 2017 18:59:33 -0700 Subject: [PATCH] added PTR record packer --- packer/type.ns.js | 1 - packer/type.ptr.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packer/type.ptr.js diff --git a/packer/type.ns.js b/packer/type.ns.js index 6c68dcf..20a0ee1 100644 --- a/packer/type.ns.js +++ b/packer/type.ns.js @@ -16,7 +16,6 @@ exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) { // RDATA // a sequence of labels - record.data.split('.').forEach(function(label) { nsLen += 1 + label.length; diff --git a/packer/type.ptr.js b/packer/type.ptr.js new file mode 100644 index 0000000..51db54c --- /dev/null +++ b/packer/type.ptr.js @@ -0,0 +1,37 @@ +(function (exports) { +'use strict'; + +// The host name that represents the supplied UP address +// May be a label, pointer or any combination + +exports.DNS_PACKER_TYPE_PTR = function (ab, dv, total, record) { + if (!record.data) { + throw new Error("no data for PTR record"); + } + + var ptrLen = 0; + var rdLenIndex = total; + total += 2; + + // RDATA + // a sequence of labels + record.data.split('.').forEach(function (label){ + console.log("the labels are: " + label); + ptrLen += 1 + label.length; + + dv.setUint8(total, label.length, false); + total += 1; + + label.split('').forEach(function (ch){ + dv.setUint8(total, ch.charCodeAt(0), false); + total += 1; + }); + }); + + // RDLENGTH + dv.setUint16(rdLenIndex, record.data.length + 1, false); + + return total; +}; + +}('undefined' !== typeof window ? window : exports));