Gave packet a header class

This commit is contained in:
dwes7 2017-02-04 13:25:31 -07:00
parent e3f2551889
commit ffac12f700
1 changed files with 14 additions and 13 deletions

View File

@ -7,7 +7,7 @@ var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
// Order http://www.zytrax.com/books/dns/ch15/
var packet = {};
pdns.unpackHeader = function (i) {
// i is one element from a Uint16Array (as a 16-bit unsigned integer)
@ -58,7 +58,7 @@ 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, false);
var header = pdns.unpackHeader(dv.getUint16(2, false));
packet.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
@ -168,38 +168,39 @@ pdns.unpack = function (ab) {
return q;
}
header.id = id;
packet.header.id = id;
console.log('qdcount', qdcount);
header.question = [];
packet.question = [];
for (i = 0; i < qdcount; i += 1) {
rec = unpackQuestion(ab, dv, ui8, total);
total += rec.byteLength;
header.question.push(rec);
packet.question.push(rec);
}
console.log('ancount', ancount);
header.answer = [];
packet.answer = [];
for (i = 0; i < ancount; i += 1) {
rec = unpackAnswer(ab, dv, ui8, total);
total += rec.byteLength;
header.answer.push(rec);
packet.answer.push(rec);
}
console.log('nscount', nscount);
header.authority = [];
packet.authority = [];
for (i = 0; i < nscount; i += 1) {
rec = unpackAnswer(ab, dv, ui8, total);
total += rec.byteLength;
header.authority.push(rec);
packet.authority.push(rec);
}
console.log('arcount', arcount);
header.additional = [];
packet.additional = [];
for (i = 0; i < arcount; i += 1) {
rec = unpackAnswer(ab, dv, ui8, total);
total += rec.byteLength;
header.additional.push(rec);
packet.additional.push(rec);
}
if (ab.byteLength !== total) {
@ -207,8 +208,8 @@ pdns.unpack = function (ab) {
"Parsed " + total + " bytes, but packet is " + ab.byteLength + " bytes."
);
}
header.byteLength = total;
return header;
packet.byteLength = total;
return packet;
};
pdns.unpackRdata = exports.DNS_RDATA_PARSE || require('./dns.rdata.parse.js').DNS_RDATA_PARSE;