summaryrefslogtreecommitdiff
path: root/lib/internal/net.js
diff options
context:
space:
mode:
authorEvan Lucas <evanlucas@me.com>2016-01-26 08:12:41 -0600
committerEvan Lucas <evanlucas@me.com>2016-01-30 17:53:55 -0600
commit6cbbfef994930bc47581d592124e82b58e55ac7b (patch)
tree26be4d68b357ef6fd473b04d04b4f449e8ae215e /lib/internal/net.js
parent6ad1f7b51ce06bfe89f32ab3d2324b81293608f8 (diff)
downloadandroid-node-v8-6cbbfef994930bc47581d592124e82b58e55ac7b.tar.gz
android-node-v8-6cbbfef994930bc47581d592124e82b58e55ac7b.tar.bz2
android-node-v8-6cbbfef994930bc47581d592124e82b58e55ac7b.zip
net: move isLegalPort to internal/net
isLegalPort can be used in more places than just net.js. This change moves it to a new internal net module in preparation for using it in the dns module. PR-URL: https://github.com/nodejs/node/pull/4882 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
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;
+}