diff --git a/dns.parser.js b/dns.parser.js index 61014c0..d65eee7 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -32,6 +32,42 @@ pdns.unpackHeader = function (i) { pdns._unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; +pdns.unpackOpt = function (ab, rec) { + var dv; + + // https://tools.ietf.org/html/rfc6891#section-6 + console.log('OPT is not yet supported'); + if ('undefined' !== typeof packet.edns_version) { + console.warn("More that one OPT, should respond with FORMERR, but not implmentede"); + } + if (packet.name) { + console.warn("name '" + packet.name + "' should not exist for type OPT 0x29 41"); + } + packet.payload = rec.class; + // TODO index into the correct place in the ArrayBuffer + dv = new DataView(new ArrayBuffer(4)); + // rec.ttl is actually 1 (extended_rcode), 1 (edns_version), 2:1 (DO), 2:7 (Z) + dv.setUint32(0, packet.ttl); + // is xrcode this edns_options? + packet.xrcode = '0x' + dv.getUint8(0, false).toString(16); + if ('0x0' === packet.xrcode) { + // use 4-bit rcode instead of 12-bit rcode + } + else { + // shift xrcode up by 4 bits (8 bits + 4 trailing 0s) + // OR with existing rcode (now 12-bits total) + console.warn('extended_rcode not supported yet'); + } + packet.edns_version = dv.getUint8(1, false); + packet.do = dv.getUint8(2, false) & 0x8000; // 1000 0000 + packet.z = dv.getUint16(2, false) & 0x7FFF; // 0111 1111 + /* +"edns_options": [], +"payload": 4096, +"edns_version": 0, +"do": 0 + */ +}; pdns.unpack = function (ab) { if (ab.buffer) { ab = ab.buffer; @@ -175,7 +211,6 @@ pdns.unpack = function (ab) { packet.header.id = id; - console.log('qdcount', packet.qdcount); packet.question = []; for (i = 0; i < packet.qdcount; i += 1) { rec = unpackQuestion(ab, dv, ui8, total); @@ -183,7 +218,6 @@ pdns.unpack = function (ab) { packet.question.push(rec); } - console.log('ancount', packet.ancount); packet.answer = []; for (i = 0; i < packet.ancount; i += 1) { rec = unpackAnswer(ab, dv, ui8, total); @@ -191,7 +225,6 @@ pdns.unpack = function (ab) { packet.answer.push(rec); } - console.log('nscount', packet.nscount); packet.authority = []; for (i = 0; i < packet.nscount; i += 1) { rec = unpackAnswer(ab, dv, ui8, total); @@ -199,11 +232,15 @@ pdns.unpack = function (ab) { packet.authority.push(rec); } - console.log('arcount', packet.arcount); packet.additional = []; for (i = 0; i < packet.arcount; i += 1) { rec = unpackAnswer(ab, dv, ui8, total); total += rec.byteLength; + if (0x29 === rec.type) { + // OPT 41 (0x29) + pdns.unpackOpt(ab, rec); + continue; + } packet.additional.push(rec); } diff --git a/dns.type.txt.js b/dns.type.txt.js index bbf3c16..b8a0e9d 100644 --- a/dns.type.txt.js +++ b/dns.type.txt.js @@ -1,7 +1,7 @@ (function (exports) { 'use strict'; -// Used to provide the ability to associate some arbitrary and unformatted text +// Used to provide the ability to associate some arbitrary and unformatted text // with a host or other name, such as a human readable information about a server // network, data center, and other accounting information. @@ -9,26 +9,10 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js' exports.DNS_TYPE_TXT = function (ab, packet, record) { + var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }); + record.data = [ labels.name ]; - var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength); - console.log(rdataAb); - var dv = new DataView(rdataAb); - // var d = ''; - // var string = ''; - // for (var i = 0; i < dv.byteLength; i+= 1){ - - // d = dv.getUint8(i, false); - // string = String.fromCharCode(d); - // console.log("data at: " + i + " is: " + string); - - - - // - record.data = [ unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name ]; - - var l = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }); - - console.log("labels: " + JSON.stringify(l)); return record; }; + }('undefined' !== typeof window ? window : exports)); diff --git a/dns.types.js b/dns.types.js index 1e807c2..3a690cc 100644 --- a/dns.types.js +++ b/dns.types.js @@ -11,6 +11,7 @@ var types = exports.DNS_TYPES = { , TXT: 0x10 // 16 , AAAA: 0x1c // 28 , SRV: 0x21 // 33 +, OPT: 0x29 // 41 , ANY: 0xff // 255 }; // and in reverse @@ -18,4 +19,4 @@ Object.keys(types).forEach(function (key) { types[types[key]] = key; }); -}('undefined' !== typeof window ? window : exports)); \ No newline at end of file +}('undefined' !== typeof window ? window : exports)); diff --git a/test/parser.js b/test/parser.js index ea3bdcb..e6eb043 100644 --- a/test/parser.js +++ b/test/parser.js @@ -78,12 +78,12 @@ try { deepLike(expected, result); } catch(e) { + console.log(''); console.log('[RESULT]'); console.log(JSON.stringify(result, null, 2)); console.error('[FAIL]', name); console.error(e.stack); console.log(''); } - console.log(''); }); }());