diff --git a/README.md b/README.md index 89d77a9..a7f8da7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Fast, lightweight, **pure JavaScript** (ES5.1) implementation for DNS / mDNS. Works great in **Web Browsers** and in node.js! -Details error checking makes it great for +Detailed error checking makes it great for * capture * packing (JSON to DNS) @@ -82,6 +82,10 @@ Parsing a saved packet node bin/dns-parse.js samples/a-0.mdns.bin ``` +You can also parse a saved packet from the `native-dns-packet` directory. +these test packets have the binary for each record type and what it's parsed output +should be. + **Library** * `packet = dnsjs.unpack(arrayBuffer)` diff --git a/dns.rdata.parse.js b/dns.rdata.parse.js index d360974..979d480 100644 --- a/dns.rdata.parse.js +++ b/dns.rdata.parse.js @@ -9,7 +9,7 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) { // packet is given for convenience var parser; - record.className = classes[record.class]; + if (!record.className) { throw new Error("Support for DNS Class " + record.class.toString(16) + "(" + record.class + ")" + " is not implemented yet. Open an issue if you actually need support" @@ -17,7 +17,7 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) { ); } - record.typeName = types[record.type]; + if (!record.typeName) { throw new Error("Support for DNS Type " + record.type.toString(16) + "(" + record.type + ")" + " is not implemented yet. Open an issue if you actually need support" diff --git a/dns.type.ptr.js b/dns.type.ptr.js new file mode 100644 index 0000000..e69de29 diff --git a/dns.type.soa.js b/dns.type.soa.js new file mode 100644 index 0000000..0f5dcc4 --- /dev/null +++ b/dns.type.soa.js @@ -0,0 +1,11 @@ +(function (exports) { +'use strict'; + + + +exports.DNS_TYPE_A = function (rdata) { + var ui8 = new Uint8Array(rdata); + +}; + +}('undefined' !== typeof window ? window : exports)); diff --git a/native-dns-packet b/native-dns-packet new file mode 160000 index 0000000..296bfe5 --- /dev/null +++ b/native-dns-packet @@ -0,0 +1 @@ +Subproject commit 296bfe5337b57e93a605838a4da48924e8d46e4b diff --git a/pure-parser.js b/pure-parser.js index a4eaadb..8aac46c 100644 --- a/pure-parser.js +++ b/pure-parser.js @@ -2,6 +2,9 @@ var pdns = module.exports; +var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES; +var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES; + // Order http://www.zytrax.com/books/dns/ch15/ pdns.unpackHeader = function (i) { @@ -30,12 +33,15 @@ pdns.unpackQname = function (ui8, ptr, q) { return pdns._unpackQname(ui8, ptr, q || { name: '' , type: 0 + , typeName: '' , class: 0 + , className: '' , byteLength: 0 , labels: [] , cpcount: 0 }); }; + pdns._unpackQname = function (ui8, ptr, q) { if (q.cpcount > 25) { throw new Error("compression pointer loop detected (over 25 pointers seems like a loop)"); @@ -132,6 +138,10 @@ pdns.unpack = function (ab) { //console.log(q); total += q.byteLength; + + + + if (ab.byteLength - total < 4) { // console.error(str.join('')); throw new Error( @@ -145,6 +155,10 @@ pdns.unpack = function (ab) { q.class = dv.getUint16(total); total += 2; q.byteLength = total - ototal; + + q.className = classes[q.class]; + q.typeName = types[q.type]; + return q; } @@ -154,7 +168,8 @@ pdns.unpack = function (ab) { //console.log('unpackAnswer QNAME:'); //console.log(q); total += q.byteLength; - + q.className = classes[q.class]; + q.typeName = types[q.type]; if (ab.byteLength - total < 10) { // console.error(str.join('')); @@ -173,6 +188,10 @@ pdns.unpack = function (ab) { q.rdlength = dv.getUint16(total); total += 2; + q.className = classes[q.class]; + q.typeName = types[q.type]; + + // TODO actually parse RDATA q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength); console.log('q.rdata', q.rdata.byteLength, 'bytes:');