2017-01-30 23:30:08 +00:00
|
|
|
;(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
|
|
|
|
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
|
2017-02-23 23:35:19 +00:00
|
|
|
//var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
|
|
|
|
//var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
|
2017-05-23 21:58:32 +00:00
|
|
|
var logged = {};
|
|
|
|
|
2017-01-30 23:30:08 +00:00
|
|
|
exports.DNSPacket = {
|
|
|
|
parse: function (nb) {
|
|
|
|
// backwards compat with node buffer
|
2017-02-24 01:09:21 +00:00
|
|
|
var ab = nb;
|
|
|
|
if (nb.buffer) {
|
|
|
|
// TODO pass byteOffsets to unpacker
|
|
|
|
ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
|
|
|
|
}
|
2017-01-30 23:30:08 +00:00
|
|
|
var packet = Parser.unpack(ab);
|
|
|
|
|
|
|
|
function tryParseRdata(record) {
|
2017-02-23 23:35:19 +00:00
|
|
|
|
2017-01-30 23:30:08 +00:00
|
|
|
try {
|
2017-02-03 01:39:32 +00:00
|
|
|
|
|
|
|
record = Parser.unpackRdata(ab, packet, record);
|
2017-01-30 23:30:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
record.error = e;
|
2017-05-23 21:58:32 +00:00
|
|
|
if (!/^support for dns/i.test(e.message)) {
|
|
|
|
console.error('[Error] unpackRdata: ' + e.message);
|
|
|
|
}
|
|
|
|
else if (!logged[e.message]) {
|
|
|
|
console.error('[Error] unpackRdata: ' + e.message);
|
|
|
|
logged[e.message] = true;
|
|
|
|
}
|
2017-01-30 23:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 01:28:43 +00:00
|
|
|
packet.answer.forEach(tryParseRdata);
|
2017-01-30 23:30:08 +00:00
|
|
|
packet.authority.forEach(tryParseRdata);
|
|
|
|
packet.additional.forEach(tryParseRdata);
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
}
|
2017-02-23 23:35:19 +00:00
|
|
|
// Backwards compat
|
2017-01-30 23:30:08 +00:00
|
|
|
, write: function (json) {
|
2017-02-23 23:35:19 +00:00
|
|
|
return Buffer.from(Packer.pack(json));
|
|
|
|
}
|
|
|
|
, pack: function (json) {
|
2017-01-30 23:30:08 +00:00
|
|
|
return Packer.pack(json);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if ('undefined' !== typeof module) {
|
|
|
|
// backwards compat node dns.js
|
|
|
|
exports.Parser = exports.DNS_PARSER;
|
|
|
|
exports.Packer = exports.DNS_PACKER;
|
|
|
|
}
|
|
|
|
|
|
|
|
}('undefined' !== typeof window ? window : exports));
|