finished task #6. Moved the location where the class and type is being assigned.
This commit is contained in:
parent
2c436fbefc
commit
51e1cae5a2
|
@ -5,7 +5,7 @@ Fast, lightweight, **pure JavaScript** (ES5.1) implementation for DNS / mDNS.
|
||||||
|
|
||||||
Works great in **Web Browsers** and in node.js!
|
Works great in **Web Browsers** and in node.js!
|
||||||
|
|
||||||
Details error checking makes it great for
|
Detailed error checking makes it great for
|
||||||
|
|
||||||
* capture
|
* capture
|
||||||
* packing (JSON to DNS)
|
* packing (JSON to DNS)
|
||||||
|
@ -82,6 +82,10 @@ Parsing a saved packet
|
||||||
node bin/dns-parse.js samples/a-0.mdns.bin
|
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**
|
**Library**
|
||||||
|
|
||||||
* `packet = dnsjs.unpack(arrayBuffer)`
|
* `packet = dnsjs.unpack(arrayBuffer)`
|
||||||
|
|
|
@ -9,7 +9,7 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) {
|
||||||
// packet is given for convenience
|
// packet is given for convenience
|
||||||
var parser;
|
var parser;
|
||||||
|
|
||||||
record.className = classes[record.class];
|
|
||||||
if (!record.className) {
|
if (!record.className) {
|
||||||
throw new Error("Support for DNS Class " + record.class.toString(16) + "(" + record.class + ")"
|
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"
|
+ " 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) {
|
if (!record.typeName) {
|
||||||
throw new Error("Support for DNS Type " + record.type.toString(16) + "(" + record.type + ")"
|
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"
|
+ " is not implemented yet. Open an issue if you actually need support"
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
(function (exports) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exports.DNS_TYPE_A = function (rdata) {
|
||||||
|
var ui8 = new Uint8Array(rdata);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}('undefined' !== typeof window ? window : exports));
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 296bfe5337b57e93a605838a4da48924e8d46e4b
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
var pdns = module.exports;
|
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/
|
// Order http://www.zytrax.com/books/dns/ch15/
|
||||||
|
|
||||||
pdns.unpackHeader = function (i) {
|
pdns.unpackHeader = function (i) {
|
||||||
|
@ -30,12 +33,15 @@ pdns.unpackQname = function (ui8, ptr, q) {
|
||||||
return pdns._unpackQname(ui8, ptr, q || {
|
return pdns._unpackQname(ui8, ptr, q || {
|
||||||
name: ''
|
name: ''
|
||||||
, type: 0
|
, type: 0
|
||||||
|
, typeName: ''
|
||||||
, class: 0
|
, class: 0
|
||||||
|
, className: ''
|
||||||
, byteLength: 0
|
, byteLength: 0
|
||||||
, labels: []
|
, labels: []
|
||||||
, cpcount: 0
|
, cpcount: 0
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
pdns._unpackQname = function (ui8, ptr, q) {
|
pdns._unpackQname = function (ui8, ptr, q) {
|
||||||
if (q.cpcount > 25) {
|
if (q.cpcount > 25) {
|
||||||
throw new Error("compression pointer loop detected (over 25 pointers seems like a loop)");
|
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);
|
//console.log(q);
|
||||||
total += q.byteLength;
|
total += q.byteLength;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ab.byteLength - total < 4) {
|
if (ab.byteLength - total < 4) {
|
||||||
// console.error(str.join(''));
|
// console.error(str.join(''));
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -145,6 +155,10 @@ pdns.unpack = function (ab) {
|
||||||
q.class = dv.getUint16(total);
|
q.class = dv.getUint16(total);
|
||||||
total += 2;
|
total += 2;
|
||||||
q.byteLength = total - ototal;
|
q.byteLength = total - ototal;
|
||||||
|
|
||||||
|
q.className = classes[q.class];
|
||||||
|
q.typeName = types[q.type];
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +168,8 @@ pdns.unpack = function (ab) {
|
||||||
//console.log('unpackAnswer QNAME:');
|
//console.log('unpackAnswer QNAME:');
|
||||||
//console.log(q);
|
//console.log(q);
|
||||||
total += q.byteLength;
|
total += q.byteLength;
|
||||||
|
q.className = classes[q.class];
|
||||||
|
q.typeName = types[q.type];
|
||||||
|
|
||||||
if (ab.byteLength - total < 10) {
|
if (ab.byteLength - total < 10) {
|
||||||
// console.error(str.join(''));
|
// console.error(str.join(''));
|
||||||
|
@ -173,6 +188,10 @@ pdns.unpack = function (ab) {
|
||||||
q.rdlength = dv.getUint16(total);
|
q.rdlength = dv.getUint16(total);
|
||||||
total += 2;
|
total += 2;
|
||||||
|
|
||||||
|
q.className = classes[q.class];
|
||||||
|
q.typeName = types[q.type];
|
||||||
|
|
||||||
|
|
||||||
// TODO actually parse RDATA
|
// TODO actually parse RDATA
|
||||||
q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength);
|
q.rdata = new Uint8Array(ab).slice(total, total + q.rdlength);
|
||||||
console.log('q.rdata', q.rdata.byteLength, 'bytes:');
|
console.log('q.rdata', q.rdata.byteLength, 'bytes:');
|
||||||
|
|
Loading…
Reference in New Issue