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

37 lines
892 B
JavaScript
Raw Normal View History

2017-10-09 19:19:54 +00:00
// NOTE: this should be EXACTLY the same as PTR
2018-03-19 16:31:44 +00:00
// (function (exports) {
2017-03-09 00:53:15 +00:00
'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;
};
2018-03-19 16:31:44 +00:00
// }('undefined' !== typeof window ? window : exports));