dns-suite.js/packer/type.mx.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-02-17 22:37:07 +00:00
(function (exports) {
'use strict';
// An 'MX' record is a 32-bit value representing the IP address
exports.DNS_PACKER_TYPE_MX = function (ab, dv, total, record) {
if (!record.exchange) {
throw new Error("no exchange for MX record");
}
if (!record.priority) {
// TODO: Check that number is in range 1-64k
throw new Error("no priority for MX record");
}
var mxLen = 2; // 16-bit priority plus label sequence
var rdLenIndex = total;
total += 2; // The space for RDLENGTH is reserved now and set below
dv.setUint16(total, parseInt(record.priority, 10), false);
total += 2;
// RDATA
// 16-bit priority and a sequence of labels as the exchange
record.exchange.split('.').forEach(function (label) {
mxLen += 1 + label.length;
2017-10-19 18:15:45 +00:00
2017-02-17 22:37:07 +00:00
dv.setUint8(total, label.length, false);
total += 1;
label.split('').forEach(function (ch) {
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
});
});
2017-10-19 18:53:56 +00:00
dv.setUint8(total, 0x00, false);
2017-10-19 18:15:45 +00:00
total += 1;
mxLen += 1;
2017-02-17 22:37:07 +00:00
// RDLENGTH
dv.setUint16(rdLenIndex, mxLen, false);
2017-10-19 18:15:45 +00:00
2017-02-17 22:37:07 +00:00
return total;
};
}('undefined' !== typeof window ? window : exports));