diff --git a/parser/type.soa.js b/parser/type.soa.js index 175047b..1a3f834 100644 --- a/parser/type.soa.js +++ b/parser/type.soa.js @@ -18,41 +18,38 @@ exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) { var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength); var dv = new DataView(rdataAb); + + // we need this information for this parser var cpcount = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).cpcount; var offset = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).byteLength; var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).labels; - console.log("offset is: " + offset); - console.log("cpcount is: " + cpcount); - console.log("the labels are : " + labels); - console.log("rdstart is: " + record.rdstart); - for(var i = 0; i < dv.byteLength;i++){ - - console.log(parseInt(dv.getUint8(i), 10).toString(16)); - } // Primary NS record.name_server = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; - // var offset = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).byteLength; - // Admin MB. This email address is always preceeded by 6 Bytes of the name_server data and email_addr length. - // ie: ns1.example.com, where ns1 is 3 bytes, example.com represented by 2 bytes (c0 0c - compression pointer) and then - // 1 more byte representing the email_addr length. - // TODO: email_addr probably shouldn't be parsed this way. The email_addr length byte is probably there to parse this in a more robust way - // we just have to figure that out - - + + // if there exists compression pointers in the rdata if (cpcount > 0){ // do something awesome with compression pointers to get the email address + // I need the length of all the data before the email address starts. + // if there are compression pointers then there will be a byte to indicate the length of each label, the label, + // then there will be a compression pointer to grab the longest label. - console.log("name server length is: " + record.name_server.length); - var email_len = parseInt(dv.getUint8(0), 10) + ;dv.getUint16(0) - console.log("email_start is: " + email_len); - record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart , { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; + var start = 2; // start or email_addr. take into account compression pointer and address length + for(var i = 0; i < labels.length; i++){ - } + // increase start by the label length. the +1 is to take into account the next label size byte + start = start + labels[i].length + 1; + // check for cpcount. 2 counts behind + if(parseInt(dv.getUint8(start - 2), 10) === 192){ + record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + start ,{ byteLength: 0, cpcount: 0, labels: [], name: '' }).name; + } + } + } // if there are no compression pointers, we can get the email address directly from the offset else { record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; } + // Serial Number record.sn = dv.getUint32(dv.byteLength - 20, false); // Refresh Interval