portfinder
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -19,2 +19,3 @@ /* | ||
var debugTestPort = debug('portfinder:testPort'), | ||
debugTryConnection = debug('portfinder:tryConnection'), | ||
debugGetPort = debug('portfinder:getPort'), | ||
@@ -33,6 +34,4 @@ debugDefaultHosts = debug('portfinder:defaultHosts'); | ||
options.host = options.host || null; | ||
options.server = options.server || net.createServer(function () { | ||
// | ||
// Create an empty listener for the port testing server. | ||
// | ||
options.server = options.server || net.createServer(function (connection) { | ||
connection.pipe(connection); | ||
}); | ||
@@ -43,7 +42,29 @@ | ||
function onListen () { | ||
internals.windows10BindError = { | ||
message: 'client and server unable to communicate over '+options.server.address(), | ||
code: 'windows10BindError' | ||
} | ||
debugTestPort("done w/ testPort(): OK", options.host, "port", options.port); | ||
options.server.removeListener('error', onError); | ||
options.server.close(); | ||
callback(null, options.port); | ||
var client = net.createConnection(options, function() { | ||
client.write('OK PORTFINDER'); | ||
}); | ||
client.setEncoding('utf8'); | ||
client.on('data', function(data) { | ||
debugTryConnection('Try Connection client -> server -> client: ', data); | ||
if (data === 'OK PORTFINDER') { | ||
options.server.removeListener('error', onError); | ||
options.server.close(); | ||
client.end(); | ||
} else { | ||
options.server.emit('error', new Error(internals.windows10BindError)); | ||
} | ||
}); | ||
client.on('end', function() { | ||
callback(null, options.port); | ||
}); | ||
} | ||
@@ -56,3 +77,3 @@ | ||
if (err.code !== 'EADDRINUSE' && err.code !== 'EACCES') { | ||
if (err.code !== 'EADDRINUSE' && err.code !== 'EACCES' && err.code !== internals.windows10BindError.code) { | ||
return callback(err); | ||
@@ -386,3 +407,2 @@ } | ||
* [ | ||
* '0.0.0.0', | ||
* '::1', | ||
@@ -400,6 +420,24 @@ * '127.0.0.1', | ||
exports._defaultHosts = (function() { | ||
var interfaces = os.networkInterfaces(), | ||
interfaceNames = Object.keys(interfaces), | ||
hiddenButImportantHost = '0.0.0.0', // !important - dont remove, hence the naming :) | ||
results = [hiddenButImportantHost]; | ||
var interfaces = {}; | ||
try{ | ||
interfaces = os.networkInterfaces(); | ||
} | ||
catch(e) { | ||
// As of October 2016, Windows Subsystem for Linux (WSL) does not support | ||
// the os.networkInterfaces() call and throws instead. For this platform, | ||
// assume 0.0.0.0 as the only address | ||
// | ||
// - https://github.com/Microsoft/BashOnWindows/issues/468 | ||
if (e.syscall === 'uv_interface_addresses') { | ||
debugDefaultHosts("exports._defaultHosts is reverting to dumb logic to account for Windows on Bash bug https://github.com/Microsoft/BashOnWindows/issues/468. Original Error is: %o", e); | ||
return ['0.0.0.0']; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
var interfaceNames = Object.keys(interfaces), | ||
results = []; | ||
for (var i = 0; i < interfaceNames.length; i++) { | ||
@@ -406,0 +444,0 @@ var _interface = interfaces[interfaceNames[i]]; |
{ | ||
"name": "portfinder", | ||
"description": "A simple tool to find an open port on the current machine", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"author": "Charlie Robbins <charlie.robbins@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15496
393