summaryrefslogtreecommitdiff
path: root/lib/internal/net.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/net.js')
-rw-r--r--lib/internal/net.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/internal/net.js b/lib/internal/net.js
new file mode 100644
index 0000000000..effc6485d2
--- /dev/null
+++ b/lib/internal/net.js
@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = { isLegalPort };
+
+// Check that the port number is not NaN when coerced to a number,
+// is an integer and that it falls within the legal range of port numbers.
+function isLegalPort(port) {
+ if (typeof port === 'string' && port.trim() === '')
+ return false;
+ return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF;
+}