Comparing version 0.1.4 to 0.1.5
var mdns = require('../'); | ||
var service = new mdns.createAdvertisement(mdns.tcp('_http'), 9876, | ||
var service = mdns.createAdvertisement(mdns.tcp('_http'), 9876, | ||
{ | ||
@@ -5,0 +5,0 @@ name:'hello', |
@@ -9,61 +9,6 @@ | ||
var ServiceType = require('./service_type').ServiceType; | ||
var pf = require('./packetfactory'); | ||
var internal = {}; | ||
internal.buildQDPacket = function () { | ||
var packet = new DNSPacket(); | ||
var name = this.options.name + this.nameSuffix; | ||
var domain = this.options.domain || 'local'; | ||
var serviceType = this.serviceType.toString() + '.' + domain; | ||
this.alias = name + '.' + serviceType; | ||
packet.push('qd', new DNSRecord(this.alias, DNSRecord.Type.ANY, 1)); | ||
return packet; | ||
}; | ||
internal.buildANPacket = function (ttl) { | ||
var packet = | ||
new DNSPacket(DNSPacket.Flag.RESPONSE | DNSPacket.Flag.AUTHORATIVE); | ||
var name = this.options.name + this.nameSuffix; | ||
var domain = this.options.domain || 'local'; | ||
var target = (this.options.host || name) + '.' + domain; | ||
var serviceType = this.serviceType.toString() + '.' + domain; | ||
var cl = DNSRecord.Class.IN | DNSRecord.Class.FLUSH; | ||
debug('alias:', this.alias); | ||
packet.push('an', new DNSRecord( | ||
serviceType, DNSRecord.Type.PTR, cl, ttl, DNSRecord.toName(this.alias))); | ||
packet.push('an', new DNSRecord( | ||
this.alias, DNSRecord.Type.SRV, cl, ttl, | ||
DNSRecord.toSrv(0, 0, this.port, target))); | ||
// TODO: https://github.com/agnat/node_mdns/blob/master/lib/advertisement.js | ||
// has 'txtRecord' | ||
if ('txt' in this.options) { | ||
packet.push('an', new DNSRecord( | ||
this.alias, DNSRecord.Type.TXT, cl, ttl, | ||
DNSRecord.toTxt(this.options.txt))); | ||
} | ||
var interfaces = os.networkInterfaces(); | ||
var ifaceFilter = this.options.networkInterface; | ||
for (var key in interfaces) { | ||
if (typeof ifaceFilter === 'undefined' || key === ifaceFilter) { | ||
debug('add A record for interface:' , key); | ||
for (var i = 0; i < interfaces[key].length; i++) { | ||
var address = interfaces[key][i].address; | ||
if (address.indexOf(':') === -1) { | ||
packet.push('an', new DNSRecord( | ||
target, DNSRecord.Type.A, cl, ttl, DNSRecord.toA(address))); | ||
} else { | ||
// TODO: also publish the ip6_address in an AAAA record | ||
} | ||
} | ||
} | ||
} | ||
return packet; | ||
}; | ||
internal.sendDNSPacket = function (packet, cb) { | ||
@@ -79,3 +24,5 @@ var buf = packet.toBuffer(); | ||
} | ||
sock.addMembership('224.0.0.251'); | ||
sock.setMulticastTTL(255); | ||
sock.setMulticastLoopback(true); | ||
sock.send(buf, 0, buf.length, 5353, '224.0.0.251', function (err, bytes) { | ||
@@ -102,14 +49,17 @@ debug('sent %d bytes with err:%s', bytes, err); | ||
var interfaces = os.networkInterfaces(); | ||
var ifaceFilter = this.options.networkInterface; | ||
var index = 0; | ||
for (var key in interfaces) { | ||
if (interfaces.hasOwnProperty(key)) { | ||
for (var i = 0; i < interfaces[key].length; i++) { | ||
var address = interfaces[key][i].address; | ||
debug('interface', key, interfaces[key]); | ||
//no IPv6 addresses | ||
if (address.indexOf(':') !== -1) { | ||
continue; | ||
if (typeof ifaceFilter === 'undefined' || key === ifaceFilter) { | ||
if (interfaces.hasOwnProperty(key)) { | ||
for (var i = 0; i < interfaces[key].length; i++) { | ||
var address = interfaces[key][i].address; | ||
debug('interface', key, interfaces[key]); | ||
//no IPv6 addresses | ||
if (address.indexOf(':') !== -1) { | ||
continue; | ||
} | ||
// these are for unicast queries ? | ||
createSocket(index++, key, address, 0, bindToAddress.bind(this)); | ||
} | ||
// these are for unicast queries ? | ||
createSocket(index++, key, address, 0, bindToAddress.bind(this)); | ||
} | ||
@@ -119,8 +69,15 @@ } | ||
// this is for multicast queries ? | ||
createSocket(index++, key, '224.0.0.251', 5353, bindToAddress.bind(this)); | ||
createSocket(index++, '(multicast)', '224.0.0.251', 5353, | ||
bindToAddress.bind(this)); | ||
function createSocket(interfaceIndex, networkInterface, address, port, cb) { | ||
var sock = dgram.createSocket('udp4'); | ||
debug('creating socket for interface %s', address); | ||
debug('creating socket for interface %s: %s:%d', | ||
networkInterface, address, port); | ||
sock.bind(port, address, function (err) { | ||
if (port === 5353) { | ||
sock.addMembership(address); | ||
sock.setMulticastTTL(255); | ||
sock.setMulticastLoopback(true); | ||
} | ||
cb(err, interfaceIndex, networkInterface, sock); | ||
@@ -160,4 +117,5 @@ }); | ||
if (rec.type !== DNSRecord.Type.PTR && | ||
rec.type !== DNSRecord.Type.SRV && | ||
rec.type !== DNSRecord.Type.ANY) { | ||
debug('skipping query: type not PTR/ANY'); | ||
debug('skipping query: type not PTR/SRV/ANY'); | ||
return; | ||
@@ -170,3 +128,3 @@ } | ||
if (rec.cl !== DNSRecord.Class.IN && rec.type !== DNSRecord.Class.ANY) { | ||
debug('skipping query: class not IN/ANY'); | ||
debug('skipping query: class not IN/ANY: %d', rec.cl); | ||
return; | ||
@@ -182,3 +140,3 @@ } | ||
internal.sendDNSPacket( | ||
internal.buildANPacket.apply(service, [DNSRecord.TTL])); | ||
pf.buildANPacket.apply(service, [DNSRecord.TTL])); | ||
} else { | ||
@@ -244,3 +202,3 @@ debug('skipping query; type %s not * or %s', type, | ||
debug('probing service %d', this.status + 1); | ||
internal.sendDNSPacket(internal.buildQDPacket.apply(this, [])); | ||
internal.sendDNSPacket(pf.buildQDPacket.apply(this, [])); | ||
break; | ||
@@ -250,9 +208,9 @@ case 3: | ||
internal.sendDNSPacket( | ||
internal.buildANPacket.apply(this, [DNSRecord.TTL])); | ||
pf.buildANPacket.apply(this, [DNSRecord.TTL])); | ||
// Repost announcement after 1sec (see rfc6762: 8.3) | ||
setTimeout(function onTimeout() { | ||
internal.sendDNSPacket( | ||
internal.buildANPacket.apply(this, [DNSRecord.TTL])); | ||
pf.buildANPacket.apply(this, [DNSRecord.TTL])); | ||
}.bind(this), 1000); | ||
// Service has been registered, repond to matching queries | ||
// Service has been registered, respond to matching queries | ||
internal.services.push(this); | ||
@@ -318,3 +276,3 @@ internal.probes = | ||
} | ||
internal.sendDNSPacket(internal.buildANPacket.apply(this, [0])); | ||
internal.sendDNSPacket(pf.buildANPacket.apply(this, [0])); | ||
this.nameSuffix = ''; | ||
@@ -321,0 +279,0 @@ this.alias = ''; |
var debug = require('debug')('mdns:browser'); | ||
var debugpacket = require('debug')('mdns:browser:packet'); | ||
var util = require('util'); | ||
@@ -36,2 +37,3 @@ var EventEmitter = require('events').EventEmitter; | ||
debug('got packet from remote', remote); | ||
debugpacket('incomming packet', message.toString('hex')); | ||
var data = decoder.decodePacket(message); | ||
@@ -38,0 +40,0 @@ |
@@ -34,3 +34,3 @@ var debug = require('debug')('mdns:lib:decoder'); | ||
} catch (e) { | ||
console.error('warning. cought an error generating ServiceType', e); | ||
debug('warning. cought an error generating ServiceType', e); | ||
debug('rec', rec); | ||
@@ -37,0 +37,0 @@ debug('packet: %s', message.toString('hex')); |
@@ -103,3 +103,3 @@ var debug = require('debug')('mdns:lib:dnspacket'); | ||
consumer.isEOF() || console.warn('was not EOF on incoming packet'); | ||
consumer.isEOF() || debug('was not EOF on incoming packet'); | ||
return packet; | ||
@@ -106,0 +106,0 @@ }; |
{ | ||
"name": "mdns-js", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -52,4 +52,10 @@ mDNS-js | ||
This will spit out a lot of information that might be useful. | ||
This will spit out LOTS of information that might be useful. | ||
If you have some issues with something where you might want | ||
to communicate the contents of a packet (ie create an issue on github) | ||
you could limit the debug information to just that. | ||
```bash | ||
DEBUG=mdns:browser:packet node examples/simple.js | ||
``` | ||
@@ -63,2 +69,9 @@ Contributing | ||
Please run any existing tests with | ||
npm test | ||
and preferably add more tests. | ||
Before creating a pull-request please run | ||
@@ -68,6 +81,7 @@ | ||
on any changed code. | ||
There is a .jshintrc file included in the project, use it, and don't | ||
be offended by it. | ||
This will run jshint as well as jscs that will do some basic syntax | ||
and code style checks. | ||
Fix any issues befor committing and creating a pull-request. | ||
Look at the .jshintrc and .jscs.json for the details. | ||
@@ -74,0 +88,0 @@ |
@@ -39,3 +39,3 @@ | ||
it('should parse service response sample5', function (done) { | ||
it('should parse service response samples', function (done) { | ||
var buf = new Buffer(packets.responses.services.sample5, 'hex'); | ||
@@ -155,2 +155,11 @@ var packet = DNSPacket.parse(buf); | ||
}); | ||
it('issue 11', function (done) { | ||
var buf = new Buffer(packets.responses.services.issue11, 'hex'); | ||
var data = decoder.decodePacket(buf); | ||
var t = data.type[0]; | ||
t.should.have.property('name', 'http'); | ||
t.should.have.property('protocol', 'tcp'); | ||
done(); | ||
}); | ||
}); |
@@ -32,3 +32,5 @@ /*global describe: true, it: true, before: true, after: true */ | ||
data.should.have.property('query'); | ||
data.should.have.property('type'); | ||
if (data.query !== '_services._dns-sd._udp.local') { | ||
data.should.have.property('type'); | ||
} | ||
done(); | ||
@@ -35,0 +37,0 @@ }); |
@@ -10,3 +10,4 @@ { | ||
"sample6": "000084000001000700000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000c095f736674702d737368c047c00c000c00010000000a0007045f736d62c047c00c000c00010000000a0007045f667470c047c00c000c00010000000a0007045f737368c047c00c000c00010000000a0008055f68747470c047c00c000c00010000000a0009065f6874747073c047", | ||
"linux_workstation": "000084000001000200000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f756469736b732d737368c047" | ||
"linux_workstation": "000084000001000200000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f756469736b732d737368c047", | ||
"issue11":"000084000000000400000000055f68747470045f746370056c6f63616c00000c000100000e10001b086d79736572766572055f68747470045f746370056c6f63616c00c0280021000100000e100017000000001f90096d7973657276657231056c6f63616c00c0280010000100000e10001c0f646570743d64657573746f746563680b68656c6c6f3d776f726c64c0550001000100000e1000047f000001" | ||
@@ -13,0 +14,0 @@ }, |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 8 instances 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
82666
39
1741
108
10