From 3a46d3efda978db91590cf29b092fa8c62ee0d96 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 21 Jan 2017 11:02:31 -0700 Subject: [PATCH] cleanup --- pure-parser.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) 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; };