multicast-dns
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -95,3 +95,3 @@ var packets = require('./packets') | ||
if (typeof q === 'string') q = [{name: q, type: type || 'A'}] | ||
if (typeof q === 'string') q = [{name: q, type: type || 'ANY'}] | ||
if (Array.isArray(q)) q = {type: 'query', questions: q} | ||
@@ -98,0 +98,0 @@ |
{ | ||
"name": "multicast-dns", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Low level multicast-dns implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -130,6 +130,18 @@ var types = require('./types') | ||
rtxt.encode = function (s, buf, offset) { | ||
str.encode(s, buf, offset + 2) | ||
buf.writeUInt16BE(str.encode.bytes, offset) | ||
rtxt.encode.bytes = str.encode.bytes + 2 | ||
rtxt.encode = function (data, buf, offset) { | ||
if (typeof data === 'string') data = new Buffer(data) | ||
var oldOffset = offset | ||
offset += 2 | ||
if (!data || data.length === 0) { | ||
str.encode('', buf, offset) | ||
offset += str.encode.bytes | ||
} else { | ||
var len = data.length | ||
data.copy(buf, offset, 0, len) | ||
offset += len | ||
} | ||
buf.writeUInt16BE(offset - oldOffset - 2, oldOffset) | ||
rtxt.encode.bytes = offset - oldOffset | ||
return buf | ||
@@ -139,9 +151,18 @@ } | ||
rtxt.decode = function (buf, offset) { | ||
var s = str.decode(buf, offset + 2) | ||
rtxt.decode.bytes = str.decode.bytes + 2 | ||
return s | ||
var oldOffset = offset | ||
var len = buf.readUInt16BE(offset) | ||
offset += 2 | ||
var data = buf.slice(offset, offset + len) | ||
offset += len | ||
rtxt.decode.bytes = offset - oldOffset | ||
return data | ||
} | ||
rtxt.encodingLength = function (s) { | ||
return str.encodingLength(s) + 2 | ||
rtxt.encodingLength = function (data) { | ||
if (!data) return 3 // 2 bytes (RDATA field length) + 1 byte (single empty byte) | ||
if (!data || data.length === 0) return 3 // 2 bytes (RDATA field length) + 1 byte (single empty byte) | ||
return data.length + 2 // +2 bytes (RDATA field length) | ||
} | ||
@@ -148,0 +169,0 @@ |
33
test.js
@@ -39,2 +39,14 @@ var mdns = require('./') | ||
test('ANY query', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions.length, 1, 'one question') | ||
t.same(packet.questions[0], {name: 'hello-world', type: 'ANY', class: 1}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
dns.query('hello-world', 'ANY') | ||
}) | ||
test('A record', function (dns, t) { | ||
@@ -115,6 +127,8 @@ dns.once('query', function (packet) { | ||
test('TXT record', function (dns, t) { | ||
var data = new Buffer('black box') | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions.length, 1, 'one question') | ||
t.same(packet.questions[0], {name: 'hello-world', type: 'TXT', class: 1}) | ||
dns.response([{type: 'TXT', name: 'hello-world', ttl: 120, data: 'hello=world,hej=verden'}]) | ||
dns.response([{type: 'TXT', name: 'hello-world', ttl: 120, data: data}]) | ||
}) | ||
@@ -124,3 +138,3 @@ | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'TXT', name: 'hello-world', ttl: 120, data: 'hello=world,hej=verden', class: 1}) | ||
t.same(packet.answers[0], {type: 'TXT', name: 'hello-world', ttl: 120, data: data, class: 1}) | ||
dns.destroy(function () { | ||
@@ -133,1 +147,16 @@ t.end() | ||
}) | ||
test('TXT record - empty', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
dns.response([{type: 'TXT', name: 'hello-world', ttl: 120}]) | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers[0], {type: 'TXT', name: 'hello-world', ttl: 120, data: new Buffer('00', 'hex'), class: 1}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
dns.query('hello-world', 'TXT') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28165
710