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

37 lines
886 B
JavaScript
Raw Permalink Normal View History

2017-10-09 13:19:54 -06:00
// NOTE: this should be EXACTLY the same as PTR
2017-03-08 17:53:15 -07:00
(function (exports) {
'use strict';
// NS name for the supplied domain. May be label, pointer or any combination
exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) {
2017-10-06 19:27:37 -06:00
if (!record.data) {
2017-03-08 17:53:15 -07:00
throw new Error("no data on NS record");
}
2017-10-09 13:19:54 -06:00
// RDLENGTH
// leading len and length of string and trailing null (all dots become lengths)
dv.setUint16(total, record.data.length + 2, false);
total += 2;
2017-03-08 17:53:15 -07:00
2017-10-06 19:27:37 -06:00
// RDATA
2017-03-08 17:53:15 -07:00
// a sequence of labels
2017-10-06 19:27:37 -06:00
record.data.split('.').forEach(function (label) {
2017-03-08 17:53:15 -07:00
dv.setUint8(total, label.length, false);
total += 1;
2017-10-06 19:27:37 -06:00
label.split('').forEach(function (ch) {
2017-03-08 17:53:15 -07:00
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
});
});
2017-10-09 13:19:54 -06:00
dv.setUint8(total, 0x00, false);
total += 1;
2017-03-08 17:53:15 -07:00
return total;
};
}('undefined' !== typeof window ? window : exports));