cp ptr updates

This commit is contained in:
AJ ONeal 2017-01-25 14:41:30 -07:00
parent 4b339429cb
commit 5e1fff748e
2 changed files with 29 additions and 15 deletions

View File

@ -39,6 +39,7 @@ fs.readFileAsync(filename, null).then(function (nb) {
try { try {
record.data = pdns.unpackRdata(nb.buffer, packet, record); record.data = pdns.unpackRdata(nb.buffer, packet, record);
} catch (e) { } catch (e) {
console.error(e.stack);
record.error = e; record.error = e;
} }
} }

View File

@ -26,21 +26,33 @@ pdns.unpackHeader = function (i) {
return header; return header;
}; };
pdns.unpackQname = function (ui8) { pdns.unpackQname = function (ab, ptr, q) {
var total = 0; var ui8 = new Uint8Array(ab);
var total = ptr;
var i; var i;
var len; var len;
var q = { var label = [];
q = q || {
name: '' name: ''
, type: 0 , type: 0
, class: 0 , class: 0
, byteLength: 0
, labels: []
, cpcount: 0
}; };
var str = [];
do { do {
label.length = 0;
len = ui8[total]; len = ui8[total];
if (0xc0 === len) { 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 throw new Error("discovered a compression pointer at byte " + total
+ " pointing to byte " + ui8[total + 1] + " pointing to byte " + ui8[total + 1]
+ ", but compression pointer support is not yet implemented" + ", but compression pointer support is not yet implemented"
@ -56,19 +68,21 @@ pdns.unpackQname = function (ui8) {
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
total += 1; total += 1;
// TODO check url-allowable characters // 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; total += 1;
if (ui8[total]) {
// pushd connecting '.', but not trailing
str.push('.');
}
//console.log('total', total, ui8[total], String.fromCharCode(ui8[total])); //console.log('total', total, ui8[total], String.fromCharCode(ui8[total]));
} while (len); } while (len);
//str.pop(); // remove trailing '.' //str.pop(); // remove trailing '.'
q.name = str.join(''); q.name = q.labels.join('.');
if (0 === q.cpcount) {
q.byteLength = total - ptr;
}
return q; return q;
}; };
@ -112,9 +126,8 @@ pdns.unpack = function (ab) {
function unpackQuestion(ab, dv, total) { function unpackQuestion(ab, dv, total) {
var ototal = total; var ototal = total;
var data = new Uint8Array(ab).slice(total); var data = new Uint8Array(ab).slice(total);
var q = pdns.unpackQname(data); var q = pdns.unpackQname(ab, total);
total += q.name.length + 2; // account for leading and trailing string length byte total += q.byteLength;
if (ab.byteLength - total < 4) { if (ab.byteLength - total < 4) {
// console.error(str.join('')); // console.error(str.join(''));
@ -135,8 +148,8 @@ pdns.unpack = function (ab) {
function unpackAnswer(ab, dv, total) { function unpackAnswer(ab, dv, total) {
var ototal = total; var ototal = total;
var data = new Uint8Array(ab).slice(total); var data = new Uint8Array(ab).slice(total);
var q = pdns.unpackQname(data); var q = pdns.unpackQname(ab, total);
total += q.name.length + 2; // account for leading and trailing string length byte total += q.byteLength;
if (ab.byteLength - total < 10) { if (ab.byteLength - total < 10) {