scoping query
This commit is contained in:
parent
676dbabfbc
commit
6c08537f3e
|
@ -30,5 +30,8 @@ fs.readFileAsync(filename, null).then(function (nb) {
|
||||||
|
|
||||||
// nb is a Uint8Array (ArrayBufferView) for nb.buffer
|
// nb is a Uint8Array (ArrayBufferView) for nb.buffer
|
||||||
// nb.buffer is the actual ArrayBuffer
|
// 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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -116,17 +116,17 @@ pdns.unpack = function (ab) {
|
||||||
var nscount = dv.getUint16(8); // authority count
|
var nscount = dv.getUint16(8); // authority count
|
||||||
var arcount = dv.getUint16(10); // additional count
|
var arcount = dv.getUint16(10); // additional count
|
||||||
var total = 12;
|
var total = 12;
|
||||||
var data;
|
|
||||||
var i;
|
var i;
|
||||||
var q;
|
var rec;
|
||||||
|
|
||||||
//console.log('datalen', data.length);
|
//console.log('datalen', data.length);
|
||||||
console.log(dv, qdcount);
|
console.log(dv, qdcount);
|
||||||
|
|
||||||
// TODO move to pdns.unpackQuestion to make testable
|
// TODO move to pdns.unpackQuestion to make testable
|
||||||
function unpackQuestion() {
|
function unpackQuestion(ab, dv, total) {
|
||||||
data = new Uint8Array(ab).slice(total);
|
var ototal = total;
|
||||||
q = pdns.unpackQname(data);
|
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
|
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);
|
console.log('class', q.class, total);
|
||||||
total += 2;
|
total += 2;
|
||||||
console.log('total', total);
|
console.log('total', total);
|
||||||
|
q.qtotal = total - ototal;
|
||||||
header.questions.push(q);
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpackAnswer(answers) {
|
function unpackAnswer(ab, dv, total) {
|
||||||
data = new Uint8Array(ab).slice(total);
|
var ototal = total;
|
||||||
q = pdns.unpackQname(data);
|
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
|
total += q.name.length + 2; // account for leading and trailing string length byte
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,7 +191,8 @@ pdns.unpack = function (ab) {
|
||||||
total += q.rdlength;
|
total += q.rdlength;
|
||||||
console.log('total', total);
|
console.log('total', total);
|
||||||
|
|
||||||
answers.push(q);
|
q.qtotal = total - ototal;
|
||||||
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
header.id = id;
|
header.id = id;
|
||||||
|
@ -198,13 +200,17 @@ pdns.unpack = function (ab) {
|
||||||
console.log('qdcount', qdcount);
|
console.log('qdcount', qdcount);
|
||||||
header.questions = [];
|
header.questions = [];
|
||||||
for (i = 0; i < qdcount; i += 1) {
|
for (i = 0; i < qdcount; i += 1) {
|
||||||
unpackQuestion();
|
rec = unpackQuestion(ab, dv, total);
|
||||||
|
total += rec.qtotal;
|
||||||
|
header.questions.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('ancount', ancount);
|
console.log('ancount', ancount);
|
||||||
header.answers = [];
|
header.answers = [];
|
||||||
for (i = 0; i < ancount; i += 1) {
|
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);
|
console.log('nscount', nscount);
|
||||||
|
@ -219,5 +225,6 @@ pdns.unpack = function (ab) {
|
||||||
unpackAnswer(header.additional);
|
unpackAnswer(header.additional);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[packet]', header);
|
header.total = total;
|
||||||
|
return header;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue