dns-suite.js/dns.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

;(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);
var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
exports.DNSPacket = {
parse: function (nb) {
// backwards compat with node buffer
var ab = nb.buffer || nb;
var packet = Parser.unpack(ab);
function tryParseRdata(record) {
try {
record = Parser.unpackRdata(ab, packet, record);
} catch (e) {
console.error('[Error] unpackRdata: ' + e.message);
record.error = e;
}
}
packet.answer.forEach(tryParseRdata);
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));