From faddeb3b8817d728da92ac16ee656cf5a8f73e84 Mon Sep 17 00:00:00 2001 From: Daplie Date: Wed, 1 Feb 2017 18:28:43 -0700 Subject: [PATCH] started working on the mx record type. Parses but does not have periods in exchange address. --- dns.js | 2 +- dns.parser.js | 8 +++---- dns.type.mx.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/dns.js b/dns.js index 87553b7..6cd213e 100644 --- a/dns.js +++ b/dns.js @@ -25,7 +25,7 @@ exports.DNSPacket = { } } - packet.answers.forEach(tryParseRdata); + packet.answer.forEach(tryParseRdata); packet.authority.forEach(tryParseRdata); packet.additional.forEach(tryParseRdata); diff --git a/dns.parser.js b/dns.parser.js index 9ffee1d..eb83fcb 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -171,19 +171,19 @@ pdns.unpack = function (ab) { header.id = id; console.log('qdcount', qdcount); - header.questions = []; + header.question = []; for (i = 0; i < qdcount; i += 1) { rec = unpackQuestion(ab, dv, ui8, total); total += rec.byteLength; - header.questions.push(rec); + header.question.push(rec); } console.log('ancount', ancount); - header.answers = []; + header.answer = []; for (i = 0; i < ancount; i += 1) { rec = unpackAnswer(ab, dv, ui8, total); total += rec.byteLength; - header.answers.push(rec); + header.answer.push(rec); } console.log('nscount', nscount); diff --git a/dns.type.mx.js b/dns.type.mx.js index 8e32d43..d98771e 100644 --- a/dns.type.mx.js +++ b/dns.type.mx.js @@ -10,9 +10,65 @@ // Meaning/Use: The name host name that provides the service. // May be a label, pointer or any combination +// ab is arrayBuffer, packet is Object, Record is Object +var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; +exports.DNS_TYPE_MX = function (ab, packet, record) { -exports.DNS_TYPE_MX = function (rdata) { - + + var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength) + var dv = new DataView(rdataAb); + var data = ''; + + var s = { + priority: '' + , exchange: '' + + }; + var temp = '' + var stuff = ''; + console.log("dataview length: " + dv.byteLength); + for (var i = 0; i < dv.byteLength; i += 1) { + + + console.log(dv.getUint8(i, false.toString(16))); + //Priority is the first two bytes + if (i < 2){ + + s.priority += dv.getUint8(i, false).toString(10); + + // take off an padded zeros + if (s.priority.substr(0, 1) === '0') { + + s.priority = s.priority.slice(1, s.priority.length); + + } + + } else { + + data = dv.getUint8(i, false); + temp = String.fromCharCode(data); + console.log("data at index " + i + ":" + temp); + + temp = temp.match(/^[a-zA-Z0-9._-]+$/); + if (temp === null){ + + }else{ + + s.exchange += temp; + } + + + + + } + + + + } + + // s.exchange = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).labels; + + return s; };