2017-01-30 23:30:08 +00:00
|
|
|
;(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Value: IP Address
|
|
|
|
// Meaning:Use: 16 octets represting the IP address
|
|
|
|
|
|
|
|
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
|
|
|
|
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
|
|
|
|
|
|
|
|
exports.DNSPacket = {
|
|
|
|
parse: function (nb) {
|
|
|
|
// backwards compat with node buffer
|
|
|
|
var ab = nb.buffer || nb;
|
|
|
|
var packet = Parser.unpack(ab);
|
|
|
|
|
|
|
|
function tryParseRdata(record) {
|
|
|
|
record.data = null;
|
|
|
|
record.error = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
record.data = Parser.unpackRdata(ab, packet, record);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('[Error] unpackRdata: ' + e.message);
|
|
|
|
record.error = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
, write: function (json) {
|
|
|
|
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));
|