|
|
@ -1,3 +1,4 @@ |
|
|
|
#!/usr/bin/env node
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
// EXAMPLE:
|
|
|
@ -12,20 +13,12 @@ if (!filename || /(-h)|(--help)/.test(process.argv.join(' '))) { |
|
|
|
console.error(""); |
|
|
|
console.error("Accepts a DNS packet (binary or json), converts it, and then converts it back to verify the function of the parser and packer"); |
|
|
|
console.error(""); |
|
|
|
console.error("Usage: node bin/dns-test.js <path/to/sample.json|.bin>"); |
|
|
|
console.error("Example: node bin/dns-test.js ./samples/services-0.mdns.json"); |
|
|
|
console.error("Usage: node bin/dns-test.js <path/to/sample.json|.bin> <path/to/sample.bin|.json>"); |
|
|
|
console.error("Example: node bin/dns-test.js ./samples/services-0.mdns.json ./samples/services-0.mdns.bin"); |
|
|
|
process.exit(1); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!outname) { |
|
|
|
console.warn(''); |
|
|
|
console.warn( |
|
|
|
"Usage: node bin/dns-pack.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '') + ".bin'" |
|
|
|
); |
|
|
|
console.warn(''); |
|
|
|
} |
|
|
|
|
|
|
|
var PromiseA = require('bluebird'); |
|
|
|
var fs = PromiseA.promisifyAll(require('fs')); |
|
|
|
var dnsjs = require('../').DNSPacket; |
|
|
@ -51,6 +44,17 @@ function testJsonAsync(nb) { |
|
|
|
} |
|
|
|
|
|
|
|
console.log("[OK] JSON -> binary -> JSON"); |
|
|
|
|
|
|
|
if (!outname) { |
|
|
|
console.warn(''); |
|
|
|
console.warn( |
|
|
|
"Usage: node bin/dns-test.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '.bin') + "'" |
|
|
|
); |
|
|
|
console.warn(''); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
fs.writeFileSync(path.basename(filename).replace(path.extname(filename), '.bin'), packet, null); |
|
|
|
} |
|
|
|
|
|
|
|
function testBinAsync(nb) { |
|
|
@ -88,6 +92,17 @@ function testBinAsync(nb) { |
|
|
|
|
|
|
|
console.log("[OK] binary -> JSON -> binary -> JSON"); |
|
|
|
console.log("(compression pointer support needs to be improved in order to support direct bin -> JSON -> bin testing)"); |
|
|
|
|
|
|
|
if (!outname) { |
|
|
|
console.warn(''); |
|
|
|
console.warn( |
|
|
|
"Usage: node bin/dns-test.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '.json') + "'" |
|
|
|
); |
|
|
|
console.warn(''); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
fs.writeFileSync(path.basename(filename).replace(path.extname(filename), '.json'), JSON.stringify(json, null, 2), null); |
|
|
|
} |
|
|
|
|
|
|
|
if ('json' === extname) { |
|
|
|