diff --git a/dns.type.mx.js b/dns.type.mx.js index d98771e..13a05cd 100644 --- a/dns.type.mx.js +++ b/dns.type.mx.js @@ -20,8 +20,8 @@ exports.DNS_TYPE_MX = function (ab, packet, record) { var data = ''; var s = { - priority: '' - , exchange: '' + priority: '' // also known as preference + , exchange: '' // }; var temp = '' @@ -48,13 +48,22 @@ exports.DNS_TYPE_MX = function (ab, packet, record) { data = dv.getUint8(i, false); temp = String.fromCharCode(data); console.log("data at index " + i + ":" + temp); + + if ((temp.trim() === '' && i > 2) || (!temp.match(/^[a-zA-Z0-9._-]+$/) && i > 2)) { + s.exchange += "."; + } temp = temp.match(/^[a-zA-Z0-9._-]+$/); + + // if temp is null, do nothing if (temp === null){ + + // otherwise, append to s.exchange }else{ s.exchange += temp; + } @@ -66,7 +75,7 @@ exports.DNS_TYPE_MX = function (ab, packet, record) { } - // s.exchange = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).labels; + // s.exchange = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; return s;