From 44010b872921b4c0fe579e5bf69a47a693ccc9e0 Mon Sep 17 00:00:00 2001 From: Simon Rogers Date: Thu, 1 Mar 2018 17:09:52 +0100 Subject: [PATCH 1/4] Mask MS bit of class to indicate a unicast response to mDNS --- dns.parser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dns.parser.js b/dns.parser.js index 62bf578..92d7b31 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -143,6 +143,10 @@ pdns.unpack = function (ab) { total += 2; q.byteLength = total - ototal; + // mDNS uses the MS bit of class to request a unicast response + q.unicastResponse = (q.class & 0x8000) !== 0; + q.class &= 0x7fff; + q.className = classes[q.class]; q.typeName = types[q.type]; -- 2.38.5 From e8736016bf4ed7f5c33ad101d6a15f3fc0e6c5ac Mon Sep 17 00:00:00 2001 From: Simon Rogers Date: Thu, 1 Mar 2018 22:40:24 +0100 Subject: [PATCH 2/4] Mask MS bit of class in answer parser --- dns.parser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/dns.parser.js b/dns.parser.js index 92d7b31..1d4a8a6 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -198,6 +198,7 @@ pdns.unpack = function (ab) { q.rdlength = dv.getUint16(total, false); total += 2; + q.class &= 0x7fff; q.className = classes[q.class]; q.typeName = types[q.type]; -- 2.38.5 From 5e7f754ab3fc8e7defb13517c00661fea3b4527d Mon Sep 17 00:00:00 2001 From: Simon Rogers Date: Sat, 10 Mar 2018 11:31:54 +0100 Subject: [PATCH 3/4] Fix TXT record parser, add NSEC --- parser/type.nsec.js | 18 ++++++++++++++++++ parser/type.txt.js | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 parser/type.nsec.js diff --git a/parser/type.nsec.js b/parser/type.nsec.js new file mode 100644 index 0000000..c665a38 --- /dev/null +++ b/parser/type.nsec.js @@ -0,0 +1,18 @@ +(function (exports) { +'use strict'; + +exports.DNS_PARSER_TYPE_NSEC = function (ab, packet, record) { + + var rdataAb = ab.slice(record.rdstart,record.rdstart + record.rdlength) + var dv = new DataView(rdataAb); + + // !!! Not actually implemented !!! + record.priority = 0; + record.weight = 0; + record.port = 0; + record.target = null; + + return record; + +}; +}('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.txt.js b/parser/type.txt.js index 7cb9ea7..fc54686 100644 --- a/parser/type.txt.js +++ b/parser/type.txt.js @@ -10,7 +10,7 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js exports.DNS_PARSER_TYPE_TXT = function (ab, packet, record) { var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }); - record.data = [ labels.name ]; + record.data = labels.labels; return record; }; -- 2.38.5 From 498d6f71f8fe49635f4ed1c89888c6f31bf36e80 Mon Sep 17 00:00:00 2001 From: Simon Rogers Date: Mon, 19 Mar 2018 17:31:44 +0100 Subject: [PATCH 4/4] Remove IIFE that uses window scope --- dns.classes.js | 4 ++-- dns.js | 4 ++-- dns.opcodes.js | 4 ++-- dns.packer.js | 4 ++-- dns.parser.js | 4 ++-- dns.rcodes.js | 4 ++-- dns.rdata.pack.js | 4 ++-- dns.rdata.parse.js | 4 ++-- dns.type.any.js | 4 ++-- dns.types.js | 4 ++-- dns.unpack-labels.js | 4 ++-- packer/type.a.js | 4 ++-- packer/type.aaaa.js | 4 ++-- packer/type.caa.js | 4 ++-- packer/type.cname.js | 4 ++-- packer/type.mx.js | 4 ++-- packer/type.ns.js | 4 ++-- packer/type.ptr.js | 4 ++-- packer/type.soa.js | 4 ++-- packer/type.srv.js | 4 ++-- packer/type.txt.js | 4 ++-- parser/type.TEMPLATE.js | 4 ++-- parser/type.a.js | 4 ++-- parser/type.aaaa.js | 4 ++-- parser/type.caa.js | 4 ++-- parser/type.cname.js | 4 ++-- parser/type.mx.js | 4 ++-- parser/type.ns.js | 4 ++-- parser/type.nsec.js | 4 ++-- parser/type.ptr.js | 4 ++-- parser/type.soa.js | 4 ++-- parser/type.srv.js | 4 ++-- parser/type.txt.js | 4 ++-- 33 files changed, 66 insertions(+), 66 deletions(-) diff --git a/dns.classes.js b/dns.classes.js index d758503..ebf7974 100644 --- a/dns.classes.js +++ b/dns.classes.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var classes = exports.DNS_CLASSES = { @@ -9,4 +9,4 @@ Object.keys(classes).forEach(function (key) { classes[classes[key]] = key; }); -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.js b/dns.js index 902e37b..3f3984c 100644 --- a/dns.js +++ b/dns.js @@ -1,4 +1,4 @@ -;(function (exports) { +// ;(function (exports) { 'use strict'; var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER); @@ -55,4 +55,4 @@ if ('undefined' !== typeof module) { exports.Packer = exports.DNS_PACKER; } -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.opcodes.js b/dns.opcodes.js index 112108e..23bf6a1 100644 --- a/dns.opcodes.js +++ b/dns.opcodes.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var opcodes = exports.DNS_OPCODES = { @@ -10,4 +10,4 @@ Object.keys(opcodes).forEach(function (key) { opcodes[opcodes[key]] = key; }); -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.packer.js b/dns.packer.js index bba95f0..23fefb1 100644 --- a/dns.packer.js +++ b/dns.packer.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES; @@ -166,4 +166,4 @@ var dnspack = exports.DNS_PACKER = { }; dnspack.packRdata = exports.DNS_RDATA_PACK || require('./dns.rdata.pack.js').DNS_RDATA_PACK; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.parser.js b/dns.parser.js index 1d4a8a6..5e22a65 100644 --- a/dns.parser.js +++ b/dns.parser.js @@ -1,4 +1,4 @@ -;(function (exports) { +// ;(function (exports) { 'use strict'; var pdns = exports.DNS_PARSER = {}; @@ -264,4 +264,4 @@ pdns.unpack = function (ab) { }; pdns.unpackRdata = exports.DNS_RDATA_PARSE || require('./dns.rdata.parse.js').DNS_RDATA_PARSE; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.rcodes.js b/dns.rcodes.js index e1a3c0f..fb1f67a 100644 --- a/dns.rcodes.js +++ b/dns.rcodes.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var rcodes = exports.DNS_RCODES = { @@ -12,4 +12,4 @@ Object.keys(rcodes).forEach(function (key) { rcodes[rcodes[key]] = key; }); -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.rdata.pack.js b/dns.rdata.pack.js index 7187948..d38a4a3 100644 --- a/dns.rdata.pack.js +++ b/dns.rdata.pack.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES; @@ -42,4 +42,4 @@ exports.DNS_RDATA_PACK = function (ab, dv, total, record) { return packer(ab, dv, total, record); }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.rdata.parse.js b/dns.rdata.parse.js index 47b86ba..b83739a 100644 --- a/dns.rdata.parse.js +++ b/dns.rdata.parse.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; exports.DNS_RDATA_PARSE = function (ab, packet, record) { @@ -45,4 +45,4 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) { return parser(ab.slice(0, record.rdstart + record.rdlength), packet, record); }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.type.any.js b/dns.type.any.js index 69a9e51..e4ca356 100644 --- a/dns.type.any.js +++ b/dns.type.any.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; @@ -9,4 +9,4 @@ exports.DNS_TYPE_ANY = function (rdata) { }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.types.js b/dns.types.js index e10788d..dbe387d 100644 --- a/dns.types.js +++ b/dns.types.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; var types = exports.DNS_TYPES = { @@ -53,4 +53,4 @@ Object.keys(types).forEach(function (key) { types[types[key]] = key; }); -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/dns.unpack-labels.js b/dns.unpack-labels.js index 7823a74..a78fa97 100644 --- a/dns.unpack-labels.js +++ b/dns.unpack-labels.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // unpack labels with 0x20 compression pointer support @@ -96,4 +96,4 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) { return q; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.a.js b/packer/type.a.js index a901d5b..d7a116e 100644 --- a/packer/type.a.js +++ b/packer/type.a.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // An 'A' record is a 32-bit value representing the IP address @@ -23,4 +23,4 @@ exports.DNS_PACKER_TYPE_A = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.aaaa.js b/packer/type.aaaa.js index ed7d27d..8b5f41f 100644 --- a/packer/type.aaaa.js +++ b/packer/type.aaaa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // 'AAAA' @@ -38,4 +38,4 @@ exports.DNS_PACKER_TYPE_AAAA = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.caa.js b/packer/type.caa.js index 324fc67..fdf4d7e 100644 --- a/packer/type.caa.js +++ b/packer/type.caa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // RFC 6844 @@ -66,4 +66,4 @@ exports.DNS_PACKER_TYPE_CAA = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.cname.js b/packer/type.cname.js index 29d8711..c60a1d6 100644 --- a/packer/type.cname.js +++ b/packer/type.cname.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // A 'CNAME' record is a 32-bit value representing the IP address @@ -34,4 +34,4 @@ exports.DNS_PACKER_TYPE_CNAME = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.mx.js b/packer/type.mx.js index b434086..ca707d9 100644 --- a/packer/type.mx.js +++ b/packer/type.mx.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // An 'MX' record is a 32-bit value representing the IP address @@ -41,4 +41,4 @@ exports.DNS_PACKER_TYPE_MX = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.ns.js b/packer/type.ns.js index 462d83a..cc1b2ac 100644 --- a/packer/type.ns.js +++ b/packer/type.ns.js @@ -1,6 +1,6 @@ // NOTE: this should be EXACTLY the same as PTR -(function (exports) { +// (function (exports) { 'use strict'; // NS name for the supplied domain. May be label, pointer or any combination @@ -33,4 +33,4 @@ exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.ptr.js b/packer/type.ptr.js index 96a0a3d..f192828 100644 --- a/packer/type.ptr.js +++ b/packer/type.ptr.js @@ -1,6 +1,6 @@ // NOTE: this should be EXACTLY the same as NS -(function (exports) { +// (function (exports) { 'use strict'; // The host name that represents the supplied UP address @@ -34,4 +34,4 @@ exports.DNS_PACKER_TYPE_PTR = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.soa.js b/packer/type.soa.js index 40c86d8..c5d11f7 100644 --- a/packer/type.soa.js +++ b/packer/type.soa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // http://www.zytrax.com/books/dns/ch8/soa.html @@ -101,4 +101,4 @@ exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.srv.js b/packer/type.srv.js index cec8669..919c8f2 100644 --- a/packer/type.srv.js +++ b/packer/type.srv.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // SRV RDATA contains: @@ -70,4 +70,4 @@ exports.DNS_PACKER_TYPE_SRV = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/packer/type.txt.js b/packer/type.txt.js index 63e64fc..1f1627b 100644 --- a/packer/type.txt.js +++ b/packer/type.txt.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Record type is just any text. @@ -44,4 +44,4 @@ exports.DNS_PACKER_TYPE_TXT = function (ab, dv, total, record) { return total; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.TEMPLATE.js b/parser/type.TEMPLATE.js index 8b9b3a7..0543655 100644 --- a/parser/type.TEMPLATE.js +++ b/parser/type.TEMPLATE.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Put some documentation here in these comments. @@ -113,4 +113,4 @@ exports.DNS_PARSER_TYPE_MX = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.a.js b/parser/type.a.js index 100a9c2..bc23067 100644 --- a/parser/type.a.js +++ b/parser/type.a.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // An 'A' record is a 32-bit value representing the IP address @@ -11,4 +11,4 @@ exports.DNS_PARSER_TYPE_A = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.aaaa.js b/parser/type.aaaa.js index e05f20b..dc51f9c 100644 --- a/parser/type.aaaa.js +++ b/parser/type.aaaa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Value: IP Address @@ -45,4 +45,4 @@ exports.DNS_PARSER_TYPE_AAAA = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.caa.js b/parser/type.caa.js index affc960..3484eac 100644 --- a/parser/type.caa.js +++ b/parser/type.caa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // RFC 6844 https://tools.ietf.org/html/rfc6844#section-3 @@ -54,4 +54,4 @@ exports.DNS_PARSER_TYPE_CAA = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.cname.js b/parser/type.cname.js index e99700d..6f4e09c 100644 --- a/parser/type.cname.js +++ b/parser/type.cname.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // A CNAME reocord maps a single alias or nickname to the real or @@ -11,4 +11,4 @@ exports.DNS_PARSER_TYPE_CNAME = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.mx.js b/parser/type.mx.js index 63363b5..508180e 100644 --- a/parser/type.mx.js +++ b/parser/type.mx.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Value: Preference @@ -22,5 +22,5 @@ exports.DNS_PARSER_TYPE_MX = function (ab, packet, record) { }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.ns.js b/parser/type.ns.js index 20b9a28..2241fa3 100644 --- a/parser/type.ns.js +++ b/parser/type.ns.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // FORMAT: @@ -20,4 +20,4 @@ exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.nsec.js b/parser/type.nsec.js index c665a38..d37418e 100644 --- a/parser/type.nsec.js +++ b/parser/type.nsec.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; exports.DNS_PARSER_TYPE_NSEC = function (ab, packet, record) { @@ -15,4 +15,4 @@ exports.DNS_PARSER_TYPE_NSEC = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.ptr.js b/parser/type.ptr.js index 83de4a2..3a159aa 100644 --- a/parser/type.ptr.js +++ b/parser/type.ptr.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Pointer records are the opposite of A and AAAA and are @@ -18,4 +18,4 @@ exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) { record.data = labelInfo.name; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.soa.js b/parser/type.soa.js index 9f4e693..5304854 100644 --- a/parser/type.soa.js +++ b/parser/type.soa.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Value Meaning/Use @@ -73,4 +73,4 @@ exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.srv.js b/parser/type.srv.js index 63ebcde..822456a 100644 --- a/parser/type.srv.js +++ b/parser/type.srv.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // SRV identifies the host(s) that will support a particular service. It @@ -19,4 +19,4 @@ exports.DNS_PARSER_TYPE_SRV = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); diff --git a/parser/type.txt.js b/parser/type.txt.js index fc54686..edb17d5 100644 --- a/parser/type.txt.js +++ b/parser/type.txt.js @@ -1,4 +1,4 @@ -(function (exports) { +// (function (exports) { 'use strict'; // Used to provide the ability to associate some arbitrary and unformatted text @@ -15,4 +15,4 @@ exports.DNS_PARSER_TYPE_TXT = function (ab, packet, record) { return record; }; -}('undefined' !== typeof window ? window : exports)); +// }('undefined' !== typeof window ? window : exports)); -- 2.38.5