started working on the mx record type. Parses but does not have periods in exchange address.

This commit is contained in:
Daplie 2017-02-01 18:28:43 -07:00
parent d87c3019fa
commit faddeb3b88
3 changed files with 63 additions and 7 deletions

2
dns.js
View File

@ -25,7 +25,7 @@ exports.DNSPacket = {
} }
} }
packet.answers.forEach(tryParseRdata); packet.answer.forEach(tryParseRdata);
packet.authority.forEach(tryParseRdata); packet.authority.forEach(tryParseRdata);
packet.additional.forEach(tryParseRdata); packet.additional.forEach(tryParseRdata);

View File

@ -171,19 +171,19 @@ pdns.unpack = function (ab) {
header.id = id; header.id = id;
console.log('qdcount', qdcount); console.log('qdcount', qdcount);
header.questions = []; header.question = [];
for (i = 0; i < qdcount; i += 1) { for (i = 0; i < qdcount; i += 1) {
rec = unpackQuestion(ab, dv, ui8, total); rec = unpackQuestion(ab, dv, ui8, total);
total += rec.byteLength; total += rec.byteLength;
header.questions.push(rec); header.question.push(rec);
} }
console.log('ancount', ancount); console.log('ancount', ancount);
header.answers = []; header.answer = [];
for (i = 0; i < ancount; i += 1) { for (i = 0; i < ancount; i += 1) {
rec = unpackAnswer(ab, dv, ui8, total); rec = unpackAnswer(ab, dv, ui8, total);
total += rec.byteLength; total += rec.byteLength;
header.answers.push(rec); header.answer.push(rec);
} }
console.log('nscount', nscount); console.log('nscount', nscount);

View File

@ -10,9 +10,65 @@
// Meaning/Use: The name host name that provides the service. // Meaning/Use: The name host name that provides the service.
// May be a label, pointer or any combination // 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;
}; };