finished task #6. Moved the location where the class and type is being assigned.

This commit is contained in:
Daplie 2017-01-26 17:03:16 -07:00
parent 2c436fbefc
commit 51e1cae5a2
6 changed files with 39 additions and 4 deletions

View File

@ -5,7 +5,7 @@ Fast, lightweight, **pure JavaScript** (ES5.1) implementation for DNS / mDNS.
Works great in **Web Browsers** and in node.js!
Details error checking makes it great for
Detailed error checking makes it great for
* capture
* packing (JSON to DNS)
@ -82,6 +82,10 @@ Parsing a saved packet
node bin/dns-parse.js samples/a-0.mdns.bin
```
You can also parse a saved packet from the `native-dns-packet` directory.
these test packets have the binary for each record type and what it's parsed output
should be.
**Library**
* `packet = dnsjs.unpack(arrayBuffer)`

View File

@ -9,7 +9,7 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) {
// packet is given for convenience
var parser;
record.className = classes[record.class];
if (!record.className) {
throw new Error("Support for DNS Class " + record.class.toString(16) + "(" + record.class + ")"
+ " is not implemented yet. Open an issue if you actually need support"
@ -17,7 +17,7 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) {
);
}
record.typeName = types[record.type];
if (!record.typeName) {
throw new Error("Support for DNS Type " + record.type.toString(16) + "(" + record.type + ")"
+ " is not implemented yet. Open an issue if you actually need support"

0
dns.type.ptr.js Normal file
View File

11
dns.type.soa.js Normal file
View File

@ -0,0 +1,11 @@
(function (exports) {
'use strict';
exports.DNS_TYPE_A = function (rdata) {
var ui8 = new Uint8Array(rdata);
};
}('undefined' !== typeof window ? window : exports));

1
native-dns-packet Submodule

@ -0,0 +1 @@
Subproject commit 296bfe5337b57e93a605838a4da48924e8d46e4b

View File

@ -2,6 +2,9 @@
var pdns = module.exports;
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/
pdns.unpackHeader = function (i) {
@ -30,12 +33,15 @@ pdns.unpackQname = function (ui8, ptr, q) {
return pdns._unpackQname(ui8, ptr, q || {
name: ''
, type: 0
, typeName: ''
, class: 0
, className: ''
, byteLength: 0
, labels: []
, cpcount: 0
});
};
pdns._unpackQname = function (ui8, ptr, q) {
if (q.cpcount > 25) {
throw new Error("compression pointer loop detected (over 25 pointers seems like a loop)");
@ -132,6 +138,10 @@ pdns.unpack = function (ab) {
//console.log(q);
total += q.byteLength;
if (ab.byteLength - total < 4) {
// console.error(str.join(''));
throw new Error(
@ -145,6 +155,10 @@ pdns.unpack = function (ab) {
q.class = dv.getUint16(total);
total += 2;
q.byteLength = total - ototal;
q.className = classes[q.class];
q.typeName = types[q.type];
return q;
}
@ -154,7 +168,8 @@ pdns.unpack = function (ab) {
//console.log('unpackAnswer QNAME:');
//console.log(q);
total += q.byteLength;
q.className = classes[q.class];
q.typeName = types[q.type];
if (ab.byteLength - total < 10) {
// console.error(str.join(''));
@ -173,6 +188,10 @@ pdns.unpack = function (ab) {
q.rdlength = dv.getUint16(total);
total += 2;
q.className = classes[q.class];
q.typeName = types[q.type];
// TODO actually parse RDATA
q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength);
console.log('q.rdata', q.rdata.byteLength, 'bytes:');