scoping query

This commit is contained in:
AJ ONeal 2017-01-21 10:45:45 -07:00
parent 676dbabfbc
commit 6c08537f3e
2 changed files with 41 additions and 31 deletions

View File

@ -30,5 +30,8 @@ fs.readFileAsync(filename, null).then(function (nb) {
// nb is a Uint8Array (ArrayBufferView) for nb.buffer
// nb.buffer is the actual ArrayBuffer
pdns.unpack(nb.buffer);
var packet = pdns.unpack(nb.buffer);
console.log('[packet]', nb.byteLength, 'bytes:');
console.log(packet);
});

View File

@ -116,17 +116,17 @@ pdns.unpack = function (ab) {
var nscount = dv.getUint16(8); // authority count
var arcount = dv.getUint16(10); // additional count
var total = 12;
var data;
var i;
var q;
var rec;
//console.log('datalen', data.length);
console.log(dv, qdcount);
// TODO move to pdns.unpackQuestion to make testable
function unpackQuestion() {
data = new Uint8Array(ab).slice(total);
q = pdns.unpackQname(data);
function unpackQuestion(ab, dv, total) {
var ototal = total;
var data = new Uint8Array(ab).slice(total);
var q = pdns.unpackQname(data);
total += q.name.length + 2; // account for leading and trailing string length byte
@ -145,13 +145,14 @@ pdns.unpack = function (ab) {
console.log('class', q.class, total);
total += 2;
console.log('total', total);
header.questions.push(q);
q.qtotal = total - ototal;
return q;
}
function unpackAnswer(answers) {
data = new Uint8Array(ab).slice(total);
q = pdns.unpackQname(data);
function unpackAnswer(ab, dv, total) {
var ototal = total;
var data = new Uint8Array(ab).slice(total);
var q = pdns.unpackQname(data);
total += q.name.length + 2; // account for leading and trailing string length byte
@ -190,7 +191,8 @@ pdns.unpack = function (ab) {
total += q.rdlength;
console.log('total', total);
answers.push(q);
q.qtotal = total - ototal;
return q;
}
header.id = id;
@ -198,13 +200,17 @@ pdns.unpack = function (ab) {
console.log('qdcount', qdcount);
header.questions = [];
for (i = 0; i < qdcount; i += 1) {
unpackQuestion();
rec = unpackQuestion(ab, dv, total);
total += rec.qtotal;
header.questions.push(rec);
}
console.log('ancount', ancount);
header.answers = [];
for (i = 0; i < ancount; i += 1) {
unpackAnswer(header.answers);
rec = unpackAnswer(ab, dv, total);
total += rec.qtotal;
header.answers.push(rec);
}
console.log('nscount', nscount);
@ -219,5 +225,6 @@ pdns.unpack = function (ab) {
unpackAnswer(header.additional);
}
console.log('[packet]', header);
header.total = total;
return header;
};