diff --git a/pure-parser.js b/pure-parser.js index b4fe39d..8158065 100644 --- a/pure-parser.js +++ b/pure-parser.js @@ -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; };