This commit is contained in:
AJ ONeal 2017-01-21 15:11:39 -07:00
parent f3a3c477a5
commit 607296c8bb
4 changed files with 43 additions and 17 deletions

View File

@ -17,10 +17,36 @@ Details error checking makes it great for
Similar API to `dns.js` and `native-dns-packet`. Similar API to `dns.js` and `native-dns-packet`.
```json
{ "id": 54231
, "qr": 0
, "opcode": 0
, "aa": 0
, "tc": 0
, "rd": 1
, "ra": 0
, "res1": 0
, "res2": 0
, "res3": 0
, "rcode": 0
, "questions": [
{ "name": "bowie._sftp-ssh._tcp.local"
, "type": 1
, "class": 1
, "byteLength": 32
}
]
, "answers": []
, "authority": []
, "additional": []
, "byteLength": 44
}
```
Install Install
------- -------
``` ```bash
npm install git+https://git@git.daplie.com:Daplie/dns-lint npm install git+https://git@git.daplie.com:Daplie/dns-lint
``` ```
@ -31,26 +57,26 @@ Usage
You can work directly from `node_modules/dns-lint`: You can work directly from `node_modules/dns-lint`:
``` ```bash
pushd node_modules/dns-lint/ pushd node_modules/dns-lint/
``` ```
Capture mDNS broadcast packets Capture mDNS broadcast packets
``` ```bash
# example # example
# node bin/mdns-capture.js <file-prefix> # node bin/mdns-capture.js <file-prefix>
node bin/mdns-capture.js mdns-test node bin/mdns-capture.js mdns-test
``` ```
``` ```bash
# in another terminal # in another terminal
dig @224.0.0.251 -p 5353 -t PTR _services._dns-sd._udp.local dig @224.0.0.251 -p 5353 -t PTR _services._dns-sd._udp.local
``` ```
Parsing a saved packet Parsing a saved packet
``` ```bash
# example # example
# node bin/dns-parse.js </path/to/packet.dns.bin> # node bin/dns-parse.js </path/to/packet.dns.bin>
node bin/dns-parse.js samples/a-0.mdns.bin node bin/dns-parse.js samples/a-0.mdns.bin
@ -63,7 +89,7 @@ node bin/dns-parse.js samples/a-0.mdns.bin
* `packet.answers[0].data = dnsjs.unpackRdatas(arrayBuffer, packet, packet.answers[0])` * `packet.answers[0].data = dnsjs.unpackRdatas(arrayBuffer, packet, packet.answers[0])`
node.js: node.js:
``` ```js
var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin'); var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
var arrayBuffer = nodeBuffer.buffer; var arrayBuffer = nodeBuffer.buffer;
@ -74,7 +100,7 @@ console.log(packet);
``` ```
Browser: Browser:
``` ```js
var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer; var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer;
var packet = pdns.unpack(arrayBuffer); var packet = pdns.unpack(arrayBuffer);

View File

@ -14,7 +14,7 @@ if (!filename) {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var fs = PromiseA.promisifyAll(require('fs')); var fs = PromiseA.promisifyAll(require('fs'));
var pdns = require('./pure-parser'); var pdns = require('../');
fs.readFileAsync(filename, null).then(function (nb) { fs.readFileAsync(filename, null).then(function (nb) {
// //
@ -48,5 +48,5 @@ fs.readFileAsync(filename, null).then(function (nb) {
packet.additional.forEach(tryParseRdata); packet.additional.forEach(tryParseRdata);
console.log('[packet]', nb.byteLength, 'bytes:'); console.log('[packet]', nb.byteLength, 'bytes:');
console.log(packet); console.log(JSON.stringify(packet, null, 2));
}); });

View File

@ -2,7 +2,7 @@
"name": "dns-testing", "name": "dns-testing",
"version": "1.0.0", "version": "1.0.0",
"description": "testing dns", "description": "testing dns",
"main": "dns_test.js", "main": "pure-parser.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },

View File

@ -128,7 +128,7 @@ pdns.unpack = function (ab) {
total += 2; total += 2;
q.class = dv.getUint16(total); q.class = dv.getUint16(total);
total += 2; total += 2;
q.qtotal = total - ototal; q.byteLength = total - ototal;
return q; return q;
} }
@ -167,7 +167,7 @@ pdns.unpack = function (ab) {
total += q.rdlength; total += q.rdlength;
console.log('total', total); console.log('total', total);
q.qtotal = total - ototal; q.byteLength = total - ototal;
return q; return q;
} }
@ -177,7 +177,7 @@ pdns.unpack = function (ab) {
header.questions = []; header.questions = [];
for (i = 0; i < qdcount; i += 1) { for (i = 0; i < qdcount; i += 1) {
rec = unpackQuestion(ab, dv, total); rec = unpackQuestion(ab, dv, total);
total += rec.qtotal; total += rec.byteLength;
header.questions.push(rec); header.questions.push(rec);
} }
@ -185,7 +185,7 @@ pdns.unpack = function (ab) {
header.answers = []; header.answers = [];
for (i = 0; i < ancount; i += 1) { for (i = 0; i < ancount; i += 1) {
rec = unpackAnswer(ab, dv, total); rec = unpackAnswer(ab, dv, total);
total += rec.qtotal; total += rec.byteLength;
header.answers.push(rec); header.answers.push(rec);
} }
@ -193,7 +193,7 @@ pdns.unpack = function (ab) {
header.authority = []; header.authority = [];
for (i = 0; i < nscount; i += 1) { for (i = 0; i < nscount; i += 1) {
rec = unpackAnswer(ab, dv, total); rec = unpackAnswer(ab, dv, total);
total += rec.qtotal; total += rec.byteLength;
header.authority.push(rec); header.authority.push(rec);
} }
@ -201,7 +201,7 @@ pdns.unpack = function (ab) {
header.additional = []; header.additional = [];
for (i = 0; i < arcount; i += 1) { for (i = 0; i < arcount; i += 1) {
rec = unpackAnswer(ab, dv, total); rec = unpackAnswer(ab, dv, total);
total += rec.qtotal; total += rec.byteLength;
header.additional.push(rec); header.additional.push(rec);
} }
@ -210,7 +210,7 @@ pdns.unpack = function (ab) {
"Parsed " + total + " bytes, but packet is " + ab.byteLength + " bytes." "Parsed " + total + " bytes, but packet is " + ab.byteLength + " bytes."
); );
} }
header.total = total; header.byteLength = total;
return header; return header;
}; };
pdns.unpackRdata = require('./dns.rdata.parse.js').DNS_RDATA_PARSE; pdns.unpackRdata = require('./dns.rdata.parse.js').DNS_RDATA_PARSE;