From ec07b6fcdbed60d1973f48a399dafb180c02d1ee Mon Sep 17 00:00:00 2001 From: tigerbot Date: Thu, 8 Jun 2017 13:21:58 -0600 Subject: [PATCH] added actual port to the mDNS response --- lib/goldilocks.js | 5 +++-- lib/mdns.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/goldilocks.js b/lib/goldilocks.js index 9164d44..3c510ae 100644 --- a/lib/goldilocks.js +++ b/lib/goldilocks.js @@ -232,7 +232,8 @@ module.exports.create = function (deps, config) { addPorts(config.tls.bind); addPorts(config.http.bind); - Object.keys(tcpPortMap).forEach(function (port) { + var portList = Object.keys(tcpPortMap).map(Number).sort(); + portList.forEach(function (port) { listenPromises.push(listeners.tcp.add(port, netHandler)); }); @@ -247,7 +248,7 @@ module.exports.create = function (deps, config) { } if (!config.mdns.disabled) { - require('./mdns').start(deps, config); + require('./mdns').start(deps, config, portList[0]); } return PromiseA.all(listenPromises); diff --git a/lib/mdns.js b/lib/mdns.js index 7da687a..974d6dc 100644 --- a/lib/mdns.js +++ b/lib/mdns.js @@ -31,7 +31,7 @@ var randomId = { } }; -function createResponse(name, packet, ttl) { +function createResponse(name, packet, ttl, mainPort) { var rpacket = { header: { id: packet.header.id @@ -93,7 +93,7 @@ function createResponse(name, packet, ttl) { , className: 'IN' , priority: 1 , weight: 0 - , port: 443 + , port: mainPort , target: name + ".local" }); rpacket.additional.push({ @@ -107,7 +107,7 @@ function createResponse(name, packet, ttl) { return require('dns-suite').DNSPacket.write(rpacket); } -module.exports.start = function (deps, config) { +module.exports.start = function (deps, config, mainPort) { var socket = require('dgram').createSocket({ type: 'udp4', reuseAddr: true }); var dns = require('dns-suite'); var nextBroadcast = -1; @@ -136,7 +136,7 @@ module.exports.start = function (deps, config) { } randomId.get().then(function (name) { - var resp = createResponse(name, packet, config.mdns.ttl); + var resp = createResponse(name, packet, config.mdns.ttl, mainPort); var now = Date.now(); if (now > nextBroadcast) { socket.send(resp, config.mdns.port, config.mdns.broadcast);