refactor as part of #8 compat with native-dns-packet / dns-js
This commit is contained in:
parent
0c2184ae00
commit
d3fce04a34
|
@ -14,7 +14,7 @@ if (!filename) {
|
|||
|
||||
var PromiseA = require('bluebird');
|
||||
var fs = PromiseA.promisifyAll(require('fs'));
|
||||
var pdns = require('../');
|
||||
var dnsjs = require('../').DNSPacket;
|
||||
|
||||
fs.readFileAsync(filename, null).then(function (nb) {
|
||||
//
|
||||
|
@ -30,23 +30,8 @@ fs.readFileAsync(filename, null).then(function (nb) {
|
|||
|
||||
// nb is a Uint8Array (ArrayBufferView) for nb.buffer
|
||||
// nb.buffer is the actual ArrayBuffer
|
||||
var packet = pdns.unpack(nb.buffer);
|
||||
|
||||
function tryParseRdata(record) {
|
||||
record.data = null;
|
||||
record.error = null;
|
||||
|
||||
try {
|
||||
record.data = pdns.unpackRdata(nb.buffer, packet, record);
|
||||
} catch (e) {
|
||||
console.error('[Error] unpackRdata: ' + e.message);
|
||||
record.error = e;
|
||||
}
|
||||
}
|
||||
|
||||
packet.answers.forEach(tryParseRdata);
|
||||
packet.authority.forEach(tryParseRdata);
|
||||
packet.additional.forEach(tryParseRdata);
|
||||
var packet = dnsjs.parse(nb.buffer);
|
||||
|
||||
console.log('[packet]', nb.byteLength, 'bytes:');
|
||||
console.log(JSON.stringify(packet, null, 2));
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
;(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;
|
||||
}
|
||||
}
|
||||
|
||||
packet.answers.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));
|
|
@ -0,0 +1,10 @@
|
|||
(function (exports) {
|
||||
'use strict';
|
||||
|
||||
exports.DNS_PACKER = {
|
||||
pack: function () {
|
||||
throw new Error("DNS Packer Not Implemented");
|
||||
}
|
||||
};
|
||||
|
||||
}('undefined' !== typeof window ? window : exports));
|
|
@ -1,7 +1,7 @@
|
|||
;(function (exports) {
|
||||
'use strict';
|
||||
|
||||
var pdns = module.exports;
|
||||
var pdns = module.exports.DNS_PARSER = {};
|
||||
|
||||
var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
|
||||
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
|
||||
|
@ -211,4 +211,5 @@ pdns.unpack = function (ab) {
|
|||
return header;
|
||||
};
|
||||
pdns.unpackRdata = require('./dns.rdata.parse.js').DNS_RDATA_PARSE;
|
||||
|
||||
}('undefined' !== typeof window ? window : exports));
|
|
@ -1,15 +1,15 @@
|
|||
{
|
||||
"name": "dns-testing",
|
||||
"name": "dns-lint",
|
||||
"version": "1.0.0",
|
||||
"description": "testing dns",
|
||||
"main": "pure-parser.js",
|
||||
"main": "dns.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.daplie.com:Daplie/DNS_test.git"
|
||||
"url": "git@git.daplie.com:Daplie/dns-lint.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
"license": "(MIT or Apache2)"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue