From 3bbada69aa5b7c4d568774676de96ae1f62ede6c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 21 Jan 2017 03:32:50 -0700 Subject: [PATCH] example of cli usage --- pure-parser-cli.js | 15 +++++++++++++-- pure-parser.js | 7 +++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pure-parser-cli.js b/pure-parser-cli.js index f380e60..880488e 100644 --- a/pure-parser-cli.js +++ b/pure-parser-cli.js @@ -6,8 +6,8 @@ // pass a terminal arg var filename = process.argv[2]; if (!filename) { - console.error("Usage: node aj-listener.js [count]"); - console.error("Example: node aj-listener.js _service 0"); + console.error("Usage: node pure-parser-cli.js "); + console.error("Example: node pure-parser-cli.js ./samples/services-0.mdns.bin"); process.exit(1); } @@ -17,6 +17,17 @@ var fs = PromiseA.promisifyAll(require('fs')); var pdns = require('./pure-parser'); fs.readFileAsync(filename, null).then(function (nb) { + // + // current reference impl + // + //console.log(require('native-dns-packet').parse(nb)); + + + // + // other reference impl + // + console.log(require('dns-js').DNSPacket.parse(nb)); + // nb is a Uint8Array (ArrayBufferView) for nb.buffer // nb.buffer is the actual ArrayBuffer pdns.unpack(nb.buffer); diff --git a/pure-parser.js b/pure-parser.js index bb1185d..b89e54f 100644 --- a/pure-parser.js +++ b/pure-parser.js @@ -179,8 +179,11 @@ pdns.unpack = function (ab) { total += 2; // TODO actually parse rdata - q.rdata = new Uint8Array(ab).slice(ab.byteLength - total, ab.byteLength + -total + q.rdlength); - q.rdata = Array.prototype.slice(q.data); + console.log(ab.byteLength, ab.byteLength - total, ab.byteLength + -total + q.rdlength); + q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength); + console.log('q.rdata', q.rdata.byteLength); + console.log(q.rdata); + q.rdata = Array.prototype.slice.apply(q.data); console.log('total', total); total += q.rdlength;