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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,14 +13,14 @@ pdns.unpackHeader = function (i) {
|
||||||
, qr: (i & 0x8000) >> 15 // Query Response (0 is question, 1 is response)
|
, qr: (i & 0x8000) >> 15 // Query Response (0 is question, 1 is response)
|
||||||
, opcode: (i & 0x7800) >> 11 // 0 is question
|
, opcode: (i & 0x7800) >> 11 // 0 is question
|
||||||
, aa: (i & 0x400) >> 10 // Authoritative Answer (response-only)
|
, aa: (i & 0x400) >> 10 // Authoritative Answer (response-only)
|
||||||
, tc: (i & 0x200) >> 9 // TrunCated - expect another packet with same (?) id
|
, tc: (i & 0x200) >> 9 // TrunCated - expect another packet with same (?) id
|
||||||
, rd: (i & 0x100) >> 8 // Recursion Desired
|
, rd: (i & 0x100) >> 8 // Recursion Desired
|
||||||
|
|
||||||
, ra: (i & 0x80) >> 7
|
, ra: (i & 0x80) >> 7
|
||||||
, res1: (i & 0x40) >> 6 // z
|
, res1: (i & 0x40) >> 6 // z
|
||||||
, res2: (i & 0x20) >> 5 // ad
|
, res2: (i & 0x20) >> 5 // ad
|
||||||
, res3: (i & 0x10) >> 4 // cd
|
, res3: (i & 0x10) >> 4 // cd
|
||||||
, rcode: (i & 0xF) // Error Code (response-only)
|
, rcode: (i & 0xF) // Error Code (response-only)
|
||||||
};
|
};
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
|
@ -29,16 +29,16 @@ pdns.unpackHeader = function (i) {
|
||||||
pdns.packHeader = function(h) {
|
pdns.packHeader = function(h) {
|
||||||
var val = 0;
|
var val = 0;
|
||||||
|
|
||||||
val += (h.qr << 15) & 0x8000;
|
val += (h.qr << 15) & 0x8000;
|
||||||
val += (h.opcode << 11) & 0x7800;
|
val += (h.opcode << 11) & 0x7800;
|
||||||
val += (h.aa << 10) & 0x400;
|
val += (h.aa << 10) & 0x400;
|
||||||
val += (h.tc << 9) & 0x200;
|
val += (h.tc << 9) & 0x200;
|
||||||
val += (h.rd << 8) & 0x100;
|
val += (h.rd << 8) & 0x100;
|
||||||
val += (h.ra << 7) & 0x80;
|
val += (h.ra << 7) & 0x80;
|
||||||
val += (h.res1 << 6) & 0x40;
|
val += (h.res1 << 6) & 0x40;
|
||||||
val += (h.res2 << 5) & 0x20;
|
val += (h.res2 << 5) & 0x20;
|
||||||
val += (h.res3 << 4) & 0x10;
|
val += (h.res3 << 4) & 0x10;
|
||||||
val += h.rcode & 0xF;
|
val += h.rcode & 0xF;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
@ -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