example of cli usage

This commit is contained in:
AJ ONeal 2017-01-21 03:32:50 -07:00
parent 6b45a4711f
commit 3bbada69aa
2 changed files with 18 additions and 4 deletions

View File

@ -6,8 +6,8 @@
// pass a terminal arg // pass a terminal arg
var filename = process.argv[2]; var filename = process.argv[2];
if (!filename) { if (!filename) {
console.error("Usage: node aj-listener.js <type> [count]"); console.error("Usage: node pure-parser-cli.js <path/to/sample.bin>");
console.error("Example: node aj-listener.js _service 0"); console.error("Example: node pure-parser-cli.js ./samples/services-0.mdns.bin");
process.exit(1); process.exit(1);
} }
@ -17,6 +17,17 @@ var fs = PromiseA.promisifyAll(require('fs'));
var pdns = require('./pure-parser'); var pdns = require('./pure-parser');
fs.readFileAsync(filename, null).then(function (nb) { 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 is a Uint8Array (ArrayBufferView) for nb.buffer
// nb.buffer is the actual ArrayBuffer // nb.buffer is the actual ArrayBuffer
pdns.unpack(nb.buffer); pdns.unpack(nb.buffer);

View File

@ -179,8 +179,11 @@ pdns.unpack = function (ab) {
total += 2; total += 2;
// TODO actually parse rdata // TODO actually parse rdata
q.rdata = new Uint8Array(ab).slice(ab.byteLength - total, ab.byteLength + -total + q.rdlength); console.log(ab.byteLength, ab.byteLength - total, ab.byteLength + -total + q.rdlength);
q.rdata = Array.prototype.slice(q.data); 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); console.log('total', total);
total += q.rdlength; total += q.rdlength;