From a420af8a627ee95a7d8be81b1956d4b7199cf8da Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 3 May 2015 21:00:38 -0700 Subject: [PATCH] separate hostname.upd6 option for IPv6 --- server.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 1f20fe3..6b39439 100644 --- a/server.js +++ b/server.js @@ -118,12 +118,22 @@ Server.prototype.listen = function (/* port, hostname, onlistening */) { debug('listen %o %o', port, hostname) - // ATTENTION: - // binding to :: only receives IPv4 connections if the bindv6only - // sysctl is set 0, which is the default on many operating systems. - if (self.http) self.http.listen(port.http || port, (hostname && hostname.http) || hostname || '::') - if (self.udp4) self.udp4.bind(port.udp || port, (hostname && hostname.udp) || hostname) - if (self.udp6) self.udp6.bind(port.udp || port, (hostname && hostname.udp) || hostname) + function isObject (obj) { + return typeof obj === 'object' && obj !== null + } + + var httpPort = isObject(port) ? (port.http || 0) : port + var udpPort = isObject(port) ? (port.udp || 0) : port + + // binding to :: only receives IPv4 connections if the bindv6only sysctl is set 0, + // which is the default on many operating systems + var httpHostname = isObject(hostname) ? hostname.http : (hostname || '::') + var udp4Hostname = isObject(hostname) ? hostname.udp : hostname + var udp6Hostname = isObject(hostname) ? hostname.udp6 : hostname + + if (self.http) self.http.listen(httpPort, httpHostname) + if (self.udp4) self.udp4.bind(udpPort, udp4Hostname) + if (self.udp6) self.udp6.bind(udpPort, udp6Hostname) } Server.prototype.close = function (cb) {