From 2f87cd379763be2859664cf36302197dd1727b84 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 1 Feb 2017 21:41:33 -0700 Subject: [PATCH 1/2] cleanup --- dns.parser.js | 16 ++++++++-------- dns.type.mx.js | 21 ++++++--------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/dns.parser.js b/dns.parser.js index eb83fcb..5a27dcf 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -72,14 +72,14 @@ pdns.unpack = function (ab) { function unpackQuestion(ab, dv, ui8, total) { var ototal = total; var q = pdns._unpackLabels(ui8, total, { - name: '' - , type: 0 - , typeName: '' - , class: 0 - , className: '' - , byteLength: 0 - , labels: [] - , cpcount: 0 + name: '' // ex: daplie.com + , type: 0 // ex: 1 + , typeName: '' // ex: A + , class: 0 // ex: 1 + , className: '' // ex: IN + , byteLength: 0 // the total byte length (including pointers, but not their labels) + , labels: [] // an array of the labels individually + , cpcount: 0 // the number of compression pointers traversed }); //console.log('unpackQuestion QNAME:'); //console.log(q); diff --git a/dns.type.mx.js b/dns.type.mx.js index a508b4d..ebb5505 100644 --- a/dns.type.mx.js +++ b/dns.type.mx.js @@ -1,8 +1,6 @@ (function (exports) { 'use strict'; -// TODO. Not yet implemented - // Value: Preference // Meaning/Use: Unsigned 16-bit integer //------------------------------------- @@ -14,20 +12,13 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; exports.DNS_TYPE_MX = function (ab, packet, record) { + var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength); + var dv = new DataView(rdataAb); - var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength) - var dv = new DataView(rdataAb); - - var s = { - priority: dv.getUint16(0, false) - , exchange: unpackLabels(new Uint8Array(ab), record.rdstart+2, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name - - }; - - - - return s; - + return { + priority: dv.getUint16(0, false) + , exchange: unpackLabels(new Uint8Array(ab), record.rdstart+2, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name + }; }; From fb55be240d54d7b517824fa783955a4d34992417 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 1 Feb 2017 21:57:40 -0700 Subject: [PATCH 2/2] started browser code --- browser.js | 17 +++++++++++++++++ demo.html | 35 +++++++++++++++++++++++++++++------ dns.pack.js | 2 +- dns.parser.js | 2 +- 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 browser.js diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..cb691ac --- /dev/null +++ b/browser.js @@ -0,0 +1,17 @@ +;(function () { +'use strict'; + +var dnsjs = window.DNSPacket; +// I got the test data by running this in the node console: +// JSON.stringify(fs.readFileSync('./test/fixtures/www.google.com.a.bin', null)) +var arr = [ + 191,164,129,128,0,1,0,5,0,0,0,0,3,119,119,119,6,103,111,111,103,108,101,3,99 + ,111,109,0,0,1,0,1,192,12,0,1,0,1,0,0,0,29,0,4,74,125,239,112,192,12,0,1,0,1,0 + ,0,0,29,0,4,74,125,239,116,192,12,0,1,0,1,0,0,0,29,0,4,74,125,239,113,192,12,0 + ,1,0,1,0,0,0,29,0,4,74,125,239,115,192,12,0,1,0,1,0,0,0,29,0,4,74,125,239,114 +]; +var ab = Uint8Array.from(arr).buffer; +var result = dnsjs.parse(ab); +console.log(result); + +}()); diff --git a/demo.html b/demo.html index f86b3e3..e094fc2 100644 --- a/demo.html +++ b/demo.html @@ -1,7 +1,30 @@ - \ No newline at end of file + This demo is meant to have 3 feilds that accept base-64, hex and array values the user + can copy in, and a button that will call the dns parser to parse the input and display + the output in a seperate field. + + --> + + + + + + + + + + + + + + + + + + + + diff --git a/dns.pack.js b/dns.pack.js index 79e1f2f..a3df535 100644 --- a/dns.pack.js +++ b/dns.pack.js @@ -1,7 +1,7 @@ (function (exports) { 'use strict'; -var pdns = module.exports.DNS_PACK = function () { +var pdns = exports.DNS_PACK = function () { }; diff --git a/dns.parser.js b/dns.parser.js index 5a27dcf..6e1fde4 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -1,7 +1,7 @@ ;(function (exports) { 'use strict'; -var pdns = module.exports.DNS_PARSER = {}; +var pdns = exports.DNS_PARSER = {}; var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES; var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;