This commit is contained in:
AJ ONeal 2017-01-21 11:02:31 -07:00
parent 6c08537f3e
commit 3a46d3efda
1 changed files with 7 additions and 15 deletions

View File

@ -119,9 +119,6 @@ pdns.unpack = function (ab) {
var i;
var rec;
//console.log('datalen', data.length);
console.log(dv, qdcount);
// TODO move to pdns.unpackQuestion to make testable
function unpackQuestion(ab, dv, total) {
var ototal = total;
@ -139,12 +136,9 @@ pdns.unpack = function (ab) {
}
q.type = dv.getUint16(total);
console.log('type', q.type, total);
total += 2;
q.class = dv.getUint16(total);
console.log('class', q.class, total);
total += 2;
console.log('total', total);
q.qtotal = total - ototal;
return q;
}
@ -165,22 +159,15 @@ pdns.unpack = function (ab) {
}
q.type = dv.getUint16(total);
console.log('type', q.type, total);
total += 2;
q.class = dv.getUint16(total);
console.log('class', q.class, total);
total += 2;
q.ttl = dv.getUint32(total);
console.log('ttl', q.ttl, total);
total += 4;
q.rdlength = dv.getUint16(total);
console.log('rdlength', q.rdlength, total);
total += 2;
// TODO actually parse rdata
// TODO actually parse RDATA
console.log(ab.byteLength, ab.byteLength - total, ab.byteLength + -total + q.rdlength);
q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength);
console.log('q.rdata', q.rdata.byteLength);
@ -225,6 +212,11 @@ pdns.unpack = function (ab) {
unpackAnswer(header.additional);
}
if (ab.byteLength !== total) {
throw new Error(
"Parsed " + total + " bytes, but packet is " + ab.byteLength + " bytes."
);
}
header.total = total;
return header;
};