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

38 lines
819 B
JavaScript
Raw Normal View History

2017-02-17 22:14:14 +00:00
(function (exports) {
'use strict';
// A 'CNAME' record is a 32-bit value representing the IP address
exports.DNS_PACKER_TYPE_CNAME = function (ab, dv, total, record) {
if (!record.data) {
throw new Error("no data for CNAME record");
}
var cnameLen = 0;
var rdLenIndex = total;
total += 2;
// RDATA
2017-02-17 22:37:07 +00:00
// a sequence of labels
2017-02-17 22:14:14 +00:00
record.data.split('.').forEach(function (label) {
2017-10-19 18:53:56 +00:00
cnameLen += 1 + label.length;
2017-02-17 22:14:14 +00:00
2017-10-19 18:53:56 +00:00
dv.setUint8(total, label.length, false);
2017-03-10 02:34:27 +00:00
total += 1;
2017-10-19 18:53:56 +00:00
label.split('').forEach(function (ch) {
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
2017-02-17 22:14:14 +00:00
});
});
2017-10-19 18:53:56 +00:00
dv.setUint8(total, 0x00, false);
total += 1;
2017-02-17 22:14:14 +00:00
// RDLENGTH
2017-10-19 18:53:56 +00:00
dv.setUint16(rdLenIndex, record.data.length + 2, false);
2017-02-17 22:14:14 +00:00
return total;
};
}('undefined' !== typeof window ? window : exports));