2017-01-27 00:03:16 +00:00
|
|
|
(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
2017-02-02 21:46:25 +00:00
|
|
|
// Value Meaning/Use
|
|
|
|
// Primary NS Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
|
|
|
|
// Admin MB Variable length. The administrator's mailbox. May be a label, pointer, or any combination
|
|
|
|
// Serial Number Unsigned 32-bit integer
|
|
|
|
// Refresh Interval Unsigned 32-bit integer
|
|
|
|
// Retry Interval Unsigned 32-bit integer
|
|
|
|
// Expiration Limit Unsigned 32-bit integer
|
|
|
|
// Minimum TTL Unsigned 32-bit integer
|
2017-01-27 00:03:16 +00:00
|
|
|
|
2017-03-10 02:34:27 +00:00
|
|
|
var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
2017-02-02 05:11:07 +00:00
|
|
|
|
2017-02-17 23:13:57 +00:00
|
|
|
exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) {
|
2017-10-05 21:02:25 +00:00
|
|
|
//
|
|
|
|
// Look!
|
|
|
|
// http://www.peerwisdom.org/2013/05/15/dns-understanding-the-soa-record/
|
2017-02-17 23:13:57 +00:00
|
|
|
|
2017-03-05 00:11:33 +00:00
|
|
|
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
|
2017-03-10 02:34:27 +00:00
|
|
|
var dv = new DataView(rdataAb);
|
2017-03-16 02:24:03 +00:00
|
|
|
|
|
|
|
// we need this information for this parser
|
2017-09-28 19:13:18 +00:00
|
|
|
var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
2017-10-05 21:02:25 +00:00
|
|
|
//var cpcount = labelInfo.cpcount;
|
2017-09-28 19:13:18 +00:00
|
|
|
var offset = labelInfo.byteLength;
|
2017-10-05 21:02:25 +00:00
|
|
|
//var labels = labelInfo.labels;
|
2017-03-10 02:34:27 +00:00
|
|
|
|
|
|
|
// Primary NS
|
2017-10-05 21:02:25 +00:00
|
|
|
record.primary = labelInfo.name;
|
|
|
|
record.name_server = record.primary;
|
2017-05-22 20:14:18 +00:00
|
|
|
|
2017-09-28 19:13:18 +00:00
|
|
|
// TODO delete this commented out code after some testing
|
|
|
|
// (pretty sure it was unnecessary and it seemed to work on code with compression pointers just fine)
|
|
|
|
/*
|
2017-03-16 02:24:03 +00:00
|
|
|
// if there exists compression pointers in the rdata
|
2017-09-28 19:13:18 +00:00
|
|
|
if (cpcount > 0) {
|
2017-03-15 23:55:59 +00:00
|
|
|
// do something awesome with compression pointers to get the email address
|
2017-03-16 02:24:03 +00:00
|
|
|
// I need the length of all the data before the email address starts.
|
2017-05-22 20:14:18 +00:00
|
|
|
// if there are compression pointers then there will be a byte to indicate the length of each label, the label,
|
2017-03-16 02:24:03 +00:00
|
|
|
// then there will be a compression pointer to grab the longest label.
|
2017-03-15 23:55:59 +00:00
|
|
|
|
2017-03-16 02:24:03 +00:00
|
|
|
var start = 2; // start or email_addr. take into account compression pointer and address length
|
2017-09-28 19:13:18 +00:00
|
|
|
for (var i = 0; i < labels.length; i += 1) {
|
2017-03-15 23:55:59 +00:00
|
|
|
|
2017-03-16 02:24:03 +00:00
|
|
|
// 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
|
2017-09-28 19:13:18 +00:00
|
|
|
if (parseInt(dv.getUint8(start - 2), 10) === 192) {
|
2017-03-16 02:24:03 +00:00
|
|
|
record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + start ,{ byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
|
|
|
}
|
2017-05-22 20:14:18 +00:00
|
|
|
}
|
2017-03-16 02:24:03 +00:00
|
|
|
} // if there are no compression pointers, we can get the email address directly from the offset
|
2017-03-15 23:55:59 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
|
|
|
}
|
2017-09-28 19:13:18 +00:00
|
|
|
*/
|
2017-10-05 21:02:25 +00:00
|
|
|
record.admin = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
|
|
|
|
record.email_addr = record.admin;
|
2017-09-28 19:13:18 +00:00
|
|
|
|
2017-03-05 00:11:33 +00:00
|
|
|
// Serial Number
|
2017-10-05 21:02:25 +00:00
|
|
|
record.serial = record.sn = dv.getUint32(dv.byteLength - 20, false);
|
2017-03-05 00:11:33 +00:00
|
|
|
// Refresh Interval
|
2017-10-05 21:02:25 +00:00
|
|
|
record.refresh = record.ref = dv.getUint32(dv.byteLength - 16, false);
|
2017-03-05 00:11:33 +00:00
|
|
|
// Retry Interval
|
2017-10-05 21:02:25 +00:00
|
|
|
record.retry = record.ret = dv.getUint32(dv.byteLength - 12, false);
|
2017-03-05 00:11:33 +00:00
|
|
|
// Expiration Limit
|
2017-10-05 21:02:25 +00:00
|
|
|
record.expiration = record.ex = dv.getUint32(dv.byteLength - 8, false);
|
2017-03-05 00:11:33 +00:00
|
|
|
// Minimum TTL
|
2017-10-05 21:02:25 +00:00
|
|
|
record.minimum = record.nx = dv.getUint32(dv.byteLength - 4, false);
|
2017-05-22 20:14:18 +00:00
|
|
|
|
2017-03-05 00:11:33 +00:00
|
|
|
return record;
|
2017-01-27 00:03:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}('undefined' !== typeof window ? window : exports));
|