From 0c2184ae00ba2b11325b80eec48ea893f0fd7dcc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 30 Jan 2017 11:43:41 -0700 Subject: [PATCH] fix #17 only use explicit big-endian methods --- pure-parser.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pure-parser.js b/pure-parser.js index c798e9e..992fde5 100644 --- a/pure-parser.js +++ b/pure-parser.js @@ -47,7 +47,7 @@ pdns.unpack = function (ab) { // DO: new Uint8Array(arrayBuffer); // DO NOT: Uint8Array.from(arrayBuffer); // WILL NOT WORK - // DO: new DataView(arrayBuffer).getUint16(7); + // DO: new DataView(arrayBuffer).getUint16(7, false); // DO NOT: arrayBuffer.slice(); // // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer @@ -57,12 +57,12 @@ pdns.unpack = function (ab) { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView var dv = new DataView(ab); - var id = dv.getUint16(0); - var header = pdns.unpackHeader(dv.getUint16(2)); - var qdcount = dv.getUint16(4); // query count - var ancount = dv.getUint16(6); // answer count - var nscount = dv.getUint16(8); // authority count - var arcount = dv.getUint16(10); // additional count + var id = dv.getUint16(0, false); + var header = pdns.unpackHeader(dv.getUint16(2, false)); + var qdcount = dv.getUint16(4, false); // query count + var ancount = dv.getUint16(6, false); // answer count + var nscount = dv.getUint16(8, false); // authority count + var arcount = dv.getUint16(10, false); // additional count var total = 12; var i; var rec; @@ -97,9 +97,9 @@ pdns.unpack = function (ab) { ); } - q.type = dv.getUint16(total); + q.type = dv.getUint16(total, false); total += 2; - q.class = dv.getUint16(total); + q.class = dv.getUint16(total, false); total += 2; q.byteLength = total - ototal; @@ -142,13 +142,13 @@ pdns.unpack = function (ab) { ); } - q.type = dv.getUint16(total); + q.type = dv.getUint16(total, false); total += 2; - q.class = dv.getUint16(total); + q.class = dv.getUint16(total, false); total += 2; - q.ttl = dv.getUint32(total); + q.ttl = dv.getUint32(total, false); total += 4; - q.rdlength = dv.getUint16(total); + q.rdlength = dv.getUint16(total, false); total += 2; q.className = classes[q.class]; @@ -157,13 +157,13 @@ pdns.unpack = function (ab) { // TODO actually parse RDATA q.rdstart = total; - console.log('q.rdata', q.rdata.byteLength, 'bytes:'); + console.log('q.rdata', q.rdlength, 'bytes:'); console.log(new Uint8Array(ab).slice(total, total + q.rdlength)); //q.rdata = Array.prototype.slice.apply(q.rdata); - total += q.rdlength; //q.rdend = q.rdstart + q.rdlength; + total += q.rdlength; q.byteLength = total - ototal; return q; }