(function () { 'use strict'; var input = process.argv[2]; var fs = require('fs'); var nb = fs.readFileSync(input, null); var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength) var dv = new DataView(ab); // // read header // console.log(''); console.log('//////////////////'); console.log('// HEADER //'); console.log('//////////////////'); console.log(''); console.log('id (int)', dv.getUint16(0)); var i = dv.getUint16(2, false); console.log('header 0x', i.toString(16)); var flagsstr = '' + 'qr ' + ((i & 0x8000) >> 15) + ', ' + 'opcode ' + ((i & 0x7800) >> 11) + ', ' + 'aa ' + ((i & 0x400) >> 10) + ', ' + 'tc ' + ((i & 0x200) >> 9) + ', ' + 'rd ' + ((i & 0x100) >> 8) + ', ' + 'ra ' + ((i & 0x80) >> 7) + ', ' + 'res1 ' + ((i & 0x40) >> 6) + ', ' + 'res2 ' + ((i & 0x20) >> 5) + ', ' + 'res3 ' + ((i & 0x10) >> 4) + ', ' + 'rcode ' + ((i & 0xF)); console.log('(flags: ' + flagsstr); var qdcount = dv.getUint16(4, false); // query count var ancount = dv.getUint16(6, false); // answer count var nscount = dv.getUint16(8, false); // authority count var arcount = dv.getUint16(10, false); // additional count console.log('qdcount', qdcount); console.log('ancount', ancount); console.log('nscount', nscount); console.log('arcount', arcount); console.log(''); console.log('//////////////////'); console.log('// QUESTION //'); console.log('//////////////////'); console.log(''); }());