2017-02-16 22:52:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-02-17 23:07:26 +00:00
|
|
|
var packer = require('../packer/type.a.js').DNS_PACKER_TYPE_A;
|
2017-02-17 22:14:14 +00:00
|
|
|
var ab = new ArrayBuffer(6); // 16-bit RDLENGTH + 32-bit address
|
2017-02-16 22:52:07 +00:00
|
|
|
var dv = new DataView(ab);
|
|
|
|
var total;
|
|
|
|
|
|
|
|
// just to see that bytes are changed as a marker
|
|
|
|
dv.setUint32(0x0, 0xDDDDDDDD, false);
|
|
|
|
|
|
|
|
[ '0.0.0.0'
|
|
|
|
, '127.0.0.1'
|
|
|
|
, '192.168.1.100'
|
|
|
|
, '216.21.170.44'
|
|
|
|
, '255.255.255.255'
|
|
|
|
].forEach(function (ipv4) {
|
|
|
|
total = 0;
|
|
|
|
total = packer(ab, dv, total, { address: ipv4 });
|
2017-02-17 22:14:14 +00:00
|
|
|
if (0x06 !== total) {
|
2017-02-16 22:52:07 +00:00
|
|
|
console.error('unexpected total ' + total);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2017-02-17 22:14:14 +00:00
|
|
|
// 0.4 is just a hacky way to account for the RDLENGTH
|
|
|
|
if ('0.4.' + ipv4 !== new Uint8Array(ab).join('.')) {
|
2017-02-16 22:52:07 +00:00
|
|
|
console.error("expected: ", ipv4);
|
|
|
|
console.error("actual: ", new Uint8Array(ab).join('.'));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('PASS');
|