multicast-dns
Advanced tools
Comparing version 6.2.0 to 6.2.1
11
index.js
@@ -144,5 +144,10 @@ var packet = require('dns-packet') | ||
Object.keys(networks).forEach(function (k) { | ||
networks[k].forEach(function (iface) { | ||
if (iface.family === 'IPv4') res.push(iface.address) | ||
}) | ||
for (var i = 0; i < networks[k].length; i++) { | ||
var iface = networks[k][i] | ||
if (iface.family === 'IPv4') { | ||
res.push(iface.address) | ||
// could only addMembership once per interface (https://nodejs.org/api/dgram.html#dgram_socket_addmembership_multicastaddress_multicastinterface) | ||
break | ||
} | ||
} | ||
}) | ||
@@ -149,0 +154,0 @@ |
{ | ||
"name": "multicast-dns", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "Low level multicast-dns implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
292
test.js
@@ -16,177 +16,211 @@ var mdns = require('./') | ||
var test = function (name, fn) { | ||
tape(name, function (t) { | ||
port(function (p) { | ||
var dns = mdns({ip: '127.0.0.1', port: p, multicast: false}) | ||
dns.on('warning', function (e) { | ||
t.error(e) | ||
var configs = [ | ||
{ip: '127.0.0.1', multicast: false} | ||
// {'interface': '127.0.0.1', multicast: true} | ||
] | ||
var tests = configs.map(function (config) { | ||
return function (name, fn) { | ||
tape(name, function (t) { | ||
port(function (p) { | ||
config.port = p | ||
var dns = mdns(config) | ||
dns.on('warning', function (e) { | ||
t.error(e) | ||
}) | ||
fn(dns, t) | ||
}) | ||
fn(dns, t) | ||
}) | ||
}) | ||
} | ||
} | ||
}) | ||
test('works', function (dns, t) { | ||
t.plan(3) | ||
tests.forEach(function (test) { | ||
test('works', function (dns, t) { | ||
t.plan(3) | ||
dns.once('query', function (packet) { | ||
t.same(packet.type, 'query') | ||
dns.destroy(function () { | ||
t.ok(true, 'destroys') | ||
dns.once('query', function (packet) { | ||
t.same(packet.type, 'query') | ||
dns.destroy(function () { | ||
t.ok(true, 'destroys') | ||
}) | ||
}) | ||
}) | ||
dns.query('hello-world', function () { | ||
t.ok(true, 'flushed') | ||
dns.query('hello-world', function () { | ||
t.ok(true, 'flushed') | ||
}) | ||
}) | ||
}) | ||
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() | ||
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') | ||
}) | ||
dns.query('hello-world', 'ANY') | ||
}) | ||
test('A record', 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: 'A', class: 1}) | ||
dns.respond([{type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1'}]) | ||
}) | ||
test('A record', 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: 'A', class: 1}) | ||
dns.respond([{type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1'}]) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1', class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
dns.query('hello-world', 'A') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1', class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
test('A record (two questions)', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions.length, 2, 'two questions') | ||
t.same(packet.questions[0], {name: 'hello-world', type: 'A', class: 1}) | ||
t.same(packet.questions[1], {name: 'hej.verden', type: 'A', class: 1}) | ||
dns.respond([{type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1'}, { | ||
type: 'A', | ||
name: 'hej.verden', | ||
ttl: 120, | ||
data: '127.0.0.2' | ||
}]) | ||
}) | ||
}) | ||
dns.query('hello-world', 'A') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 2, 'one answers') | ||
t.same(packet.answers[0], {type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1', class: 1, flush: false}) | ||
t.same(packet.answers[1], {type: 'A', name: 'hej.verden', ttl: 120, data: '127.0.0.2', class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
test('A record (two questions)', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions.length, 2, 'two questions') | ||
t.same(packet.questions[0], {name: 'hello-world', type: 'A', class: 1}) | ||
t.same(packet.questions[1], {name: 'hej.verden', type: 'A', class: 1}) | ||
dns.respond([{type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1'}, {type: 'A', name: 'hej.verden', ttl: 120, data: '127.0.0.2'}]) | ||
dns.query([{name: 'hello-world', type: 'A'}, {name: 'hej.verden', type: 'A'}]) | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 2, 'one answers') | ||
t.same(packet.answers[0], {type: 'A', name: 'hello-world', ttl: 120, data: '127.0.0.1', class: 1, flush: false}) | ||
t.same(packet.answers[1], {type: 'A', name: 'hej.verden', ttl: 120, data: '127.0.0.2', class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
test('AAAA record', 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: 'AAAA', class: 1}) | ||
dns.respond([{type: 'AAAA', name: 'hello-world', ttl: 120, data: 'fe80::5ef9:38ff:fe8c:ceaa'}]) | ||
}) | ||
}) | ||
dns.query([{name: 'hello-world', type: 'A'}, {name: 'hej.verden', type: 'A'}]) | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], { | ||
type: 'AAAA', | ||
name: 'hello-world', | ||
ttl: 120, | ||
data: 'fe80::5ef9:38ff:fe8c:ceaa', | ||
class: 1, | ||
flush: false | ||
}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
test('AAAA record', 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: 'AAAA', class: 1}) | ||
dns.respond([{type: 'AAAA', name: 'hello-world', ttl: 120, data: 'fe80::5ef9:38ff:fe8c:ceaa'}]) | ||
dns.query('hello-world', 'AAAA') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'AAAA', name: 'hello-world', ttl: 120, data: 'fe80::5ef9:38ff:fe8c:ceaa', class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
test('SRV record', 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: 'SRV', class: 1}) | ||
dns.respond([{ | ||
type: 'SRV', | ||
name: 'hello-world', | ||
ttl: 120, | ||
data: {port: 11111, target: 'hello.world.com', priority: 10, weight: 12} | ||
}]) | ||
}) | ||
}) | ||
dns.query('hello-world', 'AAAA') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], { | ||
type: 'SRV', | ||
name: 'hello-world', | ||
ttl: 120, | ||
data: {port: 11111, target: 'hello.world.com', priority: 10, weight: 12}, | ||
class: 1, | ||
flush: false | ||
}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
test('SRV record', 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: 'SRV', class: 1}) | ||
dns.respond([{type: 'SRV', name: 'hello-world', ttl: 120, data: {port: 11111, target: 'hello.world.com', priority: 10, weight: 12}}]) | ||
dns.query('hello-world', 'SRV') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'SRV', name: 'hello-world', ttl: 120, data: {port: 11111, target: 'hello.world.com', priority: 10, weight: 12}, class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
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.respond([{type: 'TXT', name: 'hello-world', ttl: 120, data: data}]) | ||
}) | ||
}) | ||
dns.query('hello-world', 'SRV') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'TXT', name: 'hello-world', ttl: 120, data: data, class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
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.respond([{type: 'TXT', name: 'hello-world', ttl: 120, data: data}]) | ||
dns.query('hello-world', 'TXT') | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers.length, 1, 'one answer') | ||
t.same(packet.answers[0], {type: 'TXT', name: 'hello-world', ttl: 120, data: data, class: 1, flush: false}) | ||
dns.destroy(function () { | ||
t.end() | ||
test('QU question bit', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions, [ | ||
{type: 'A', name: 'foo', class: 1}, | ||
{type: 'A', name: 'bar', class: 1} | ||
]) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
dns.query('hello-world', 'TXT') | ||
}) | ||
test('QU question bit', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
t.same(packet.questions, [ | ||
{type: 'A', name: 'foo', class: 1}, | ||
dns.query([ | ||
{type: 'A', name: 'foo', class: 32769}, | ||
{type: 'A', name: 'bar', class: 1} | ||
]) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
dns.query([ | ||
{type: 'A', name: 'foo', class: 32769}, | ||
{type: 'A', name: 'bar', class: 1} | ||
]) | ||
}) | ||
test('cache flush bit', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
dns.respond({ | ||
answers: [ | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.1', class: 1, flush: true}, | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.2', class: 1, flush: false} | ||
], | ||
additionals: [ | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.3', class: 1, flush: true} | ||
] | ||
}) | ||
}) | ||
test('cache flush bit', function (dns, t) { | ||
dns.once('query', function (packet) { | ||
dns.respond({ | ||
answers: [ | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers, [ | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.1', class: 1, flush: true}, | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.2', class: 1, flush: false} | ||
], | ||
additionals: [ | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.3', class: 1, flush: true} | ||
] | ||
]) | ||
t.same(packet.additionals[0], {type: 'A', name: 'foo', ttl: 120, data: '127.0.0.3', class: 1, flush: true}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
dns.once('response', function (packet) { | ||
t.same(packet.answers, [ | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.1', class: 1, flush: true}, | ||
{type: 'A', name: 'foo', ttl: 120, data: '127.0.0.2', class: 1, flush: false} | ||
]) | ||
t.same(packet.additionals[0], {type: 'A', name: 'foo', ttl: 120, data: '127.0.0.3', class: 1, flush: true}) | ||
dns.destroy(function () { | ||
t.end() | ||
}) | ||
dns.query('foo', 'A') | ||
}) | ||
dns.query('foo', 'A') | ||
}) |
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
19126
408