}
if (address || port) {
- debug('bind to ' + address);
- if (addressType === 6) {
+ debug('bind to ' + (address || 'anycast'));
+ if (!address) {
+ // Try binding to ipv6 first
+ err = handle.bind6('::', port);
+ if (err) {
+ handle.close();
+ // Fallback to ipv4
+ return createServerHandle('0.0.0.0', port);
+ }
+ } else if (addressType === 6) {
err = handle.bind6(address, port);
} else {
err = handle.bind(address, port);
if (arguments.length == 0 || util.isFunction(arguments[0])) {
// Bind to a random port.
- listen(self, '0.0.0.0', 0, null, backlog);
+ listen(self, null, 0, null, backlog);
} else if (arguments[0] && util.isObject(arguments[0])) {
var h = arguments[0];
util.isFunction(arguments[1]) ||
util.isNumber(arguments[1])) {
// The first argument is the port, no IP given.
- listen(self, '0.0.0.0', port, 4, backlog);
+ listen(self, null, port, 4, backlog);
} else {
// The first argument is the port, the second an IP.
if (err) {
self.emit('error', err);
} else {
- listen(self, ip || '0.0.0.0', port, ip ? addressType : 4, backlog);
+ listen(self, ip, port, ip ? addressType : 4, backlog);
}
});
}