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

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-01-27 02:18:46 +00:00
(function (exports) {
'use strict';
// Value: IP Address
// Meaning:Use: 16 octets represting the IP address
2017-01-29 01:35:57 +00:00
exports.DNS_TYPE_AAAA = function (ab, packet, record) {
2017-01-30 18:21:06 +00:00
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;
2017-01-29 01:35:57 +00:00
var s = '';
2017-01-30 18:21:06 +00:00
// 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);
2017-01-29 01:35:57 +00:00
}
2017-01-30 18:21:06 +00:00
record.address = s;
return record;
2017-01-27 02:18:46 +00:00
};
2017-01-30 18:21:06 +00:00
2017-01-27 02:18:46 +00:00
}('undefined' !== typeof window ? window : exports));