added actual port to the mDNS response

This commit is contained in:
tigerbot 2017-06-08 13:21:58 -06:00
parent 027494cd1d
commit ec07b6fcdb
2 changed files with 7 additions and 6 deletions

View File

@ -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);

View File

@ -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);