dns-suite.js/dns.type.aaaa.js

34 lines
1.1 KiB
JavaScript

(function (exports) {
'use strict';
// Value: IP Address
// Meaning:Use: 16 octets represting the IP address
exports.DNS_TYPE_AAAA = function (ab, packet, record) {
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
// We can't use Uint16Array because it doesn't specify Endianness
// Intel x86, x64, and (usually) ARM are Little Endian, but Network Order is Big Endian
// DataView *does* let us specify endianness, so we can use that
// http://stackoverflow.com/questions/13514614/why-is-network-byte-order-defined-to-be-big-endian
var dv = new DataView(rdataAb);
var i = 0;
var s = '';
// Note: byteLength is always 16 for AAAA records
for (i = 0; i < dv.byteLength; i += 2) {
if (i > 0 && i < dv.byteLength) {
// add ':' between all... sedectets? sexdectets? ... pairs of two octets :)
s += ':';
}
// Big Endian Uint16 is specified by using `false`, Little Endian is `true`
s += dv.getUint16(i, false).toString(16);
}
return s;
};
}('undefined' !== typeof window ? window : exports));