cp ptr updates
This commit is contained in:
parent
4b339429cb
commit
5e1fff748e
|
@ -39,6 +39,7 @@ fs.readFileAsync(filename, null).then(function (nb) {
|
|||
try {
|
||||
record.data = pdns.unpackRdata(nb.buffer, packet, record);
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
record.error = e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,21 +26,33 @@ pdns.unpackHeader = function (i) {
|
|||
return header;
|
||||
};
|
||||
|
||||
pdns.unpackQname = function (ui8) {
|
||||
var total = 0;
|
||||
pdns.unpackQname = function (ab, ptr, q) {
|
||||
var ui8 = new Uint8Array(ab);
|
||||
var total = ptr;
|
||||
var i;
|
||||
|
||||
var len;
|
||||
var q = {
|
||||
var label = [];
|
||||
q = q || {
|
||||
name: ''
|
||||
, type: 0
|
||||
, class: 0
|
||||
, byteLength: 0
|
||||
, labels: []
|
||||
, cpcount: 0
|
||||
};
|
||||
var str = [];
|
||||
|
||||
do {
|
||||
label.length = 0;
|
||||
len = ui8[total];
|
||||
if (0xc0 === len) {
|
||||
console.log('byteLength', ui8.byteLength);
|
||||
var cpptr = ui8[total + 1];
|
||||
var cplen = ui8[ui8[total + 1]];
|
||||
console.log('cp at', total);
|
||||
console.log('ptr to', cpptr);
|
||||
console.log('label len', cplen);
|
||||
console.log('label', Buffer.from(ui8.slice(cpptr + 1, cpptr + 1 + cplen)).toString('ascii'));
|
||||
throw new Error("discovered a compression pointer at byte " + total
|
||||
+ " pointing to byte " + ui8[total + 1]
|
||||
+ ", but compression pointer support is not yet implemented"
|
||||
|
@ -56,19 +68,21 @@ pdns.unpackQname = function (ui8) {
|
|||
for (i = 0; i < len; i += 1) {
|
||||
total += 1;
|
||||
// TODO check url-allowable characters
|
||||
str.push(String.fromCharCode(ui8[total]));
|
||||
label.push(String.fromCharCode(ui8[total]));
|
||||
}
|
||||
if (label.length) {
|
||||
q.labels.push(label.join(''));
|
||||
}
|
||||
total += 1;
|
||||
if (ui8[total]) {
|
||||
// pushd connecting '.', but not trailing
|
||||
str.push('.');
|
||||
}
|
||||
//console.log('total', total, ui8[total], String.fromCharCode(ui8[total]));
|
||||
} while (len);
|
||||
|
||||
//str.pop(); // remove trailing '.'
|
||||
|
||||
q.name = str.join('');
|
||||
q.name = q.labels.join('.');
|
||||
if (0 === q.cpcount) {
|
||||
q.byteLength = total - ptr;
|
||||
}
|
||||
|
||||
return q;
|
||||
};
|
||||
|
@ -112,9 +126,8 @@ pdns.unpack = function (ab) {
|
|||
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
|
||||
|
||||
var q = pdns.unpackQname(ab, total);
|
||||
total += q.byteLength;
|
||||
|
||||
if (ab.byteLength - total < 4) {
|
||||
// console.error(str.join(''));
|
||||
|
@ -135,8 +148,8 @@ pdns.unpack = function (ab) {
|
|||
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
|
||||
var q = pdns.unpackQname(ab, total);
|
||||
total += q.byteLength;
|
||||
|
||||
|
||||
if (ab.byteLength - total < 10) {
|
||||
|
|
Loading…
Reference in New Issue