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

37 lines
886 B
JavaScript
Raw Permalink Normal View History

2017-10-09 19:19:54 +00:00
// NOTE: this should be EXACTLY the same as PTR
2017-03-09 00:53:15 +00: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-07 01:27:37 +00:00
if (!record.data) {
2017-03-09 00:53:15 +00:00
throw new Error("no data on NS record");
}
2017-10-09 19:19:54 +00: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-09 00:53:15 +00:00
2017-10-07 01:27:37 +00:00
// RDATA
2017-03-09 00:53:15 +00:00
// a sequence of labels
2017-10-07 01:27:37 +00:00
record.data.split('.').forEach(function (label) {
2017-03-09 00:53:15 +00:00
dv.setUint8(total, label.length, false);
total += 1;
2017-10-07 01:27:37 +00:00
label.split('').forEach(function (ch) {
2017-03-09 00:53:15 +00:00
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
});
});
2017-10-09 19:19:54 +00:00
dv.setUint8(total, 0x00, false);
total += 1;
2017-03-09 00:53:15 +00:00
return total;
};
}('undefined' !== typeof window ? window : exports));