@@ -118,12 +118,22 @@ Server.prototype.listen = function (/* port, hostname, onlistening */) {
118118
119119 debug ( 'listen %o %o' , port , hostname )
120120
121- // ATTENTION:
122- // binding to :: only receives IPv4 connections if the bindv6only
123- // sysctl is set 0, which is the default on many operating systems.
124- if ( self . http ) self . http . listen ( port . http || port , ( hostname && hostname . http ) || hostname || '::' )
125- if ( self . udp4 ) self . udp4 . bind ( port . udp || port , ( hostname && hostname . udp ) || hostname )
126- if ( self . udp6 ) self . udp6 . bind ( port . udp || port , ( hostname && hostname . udp ) || hostname )
121+ function isObject ( obj ) {
122+ return typeof obj === 'object' && obj !== null
123+ }
124+
125+ var httpPort = isObject ( port ) ? ( port . http || 0 ) : port
126+ var udpPort = isObject ( port ) ? ( port . udp || 0 ) : port
127+
128+ // binding to :: only receives IPv4 connections if the bindv6only sysctl is set 0,
129+ // which is the default on many operating systems
130+ var httpHostname = isObject ( hostname ) ? hostname . http : ( hostname || '::' )
131+ var udp4Hostname = isObject ( hostname ) ? hostname . udp : hostname
132+ var udp6Hostname = isObject ( hostname ) ? hostname . udp6 : hostname
133+
134+ if ( self . http ) self . http . listen ( httpPort , httpHostname )
135+ if ( self . udp4 ) self . udp4 . bind ( udpPort , udp4Hostname )
136+ if ( self . udp6 ) self . udp6 . bind ( udpPort , udp6Hostname )
127137}
128138
129139Server . prototype . close = function ( cb ) {
0 commit comments