aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-07-04 11:25:31 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-07-04 11:33:29 -0700
commit38f3bf66108d398697f20dbca8c19df29329323d (patch)
treeda5cb3f825dfdb0800a21a37b37017150ffb6bce /lib
parentf6fa20fd5551b0af76b6735a9af781462daf836d (diff)
downloadandroid-node-v8-38f3bf66108d398697f20dbca8c19df29329323d.tar.gz
android-node-v8-38f3bf66108d398697f20dbca8c19df29329323d.tar.bz2
android-node-v8-38f3bf66108d398697f20dbca8c19df29329323d.zip
net_uv: add isIP
Issue #1270: Doesn't completely pass test/simple/test-net-isip.js yet.
Diffstat (limited to 'lib')
-rw-r--r--lib/net_uv.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/net_uv.js b/lib/net_uv.js
index e9db1b2cba..37888eda28 100644
--- a/lib/net_uv.js
+++ b/lib/net_uv.js
@@ -540,3 +540,35 @@ function onconnection(clientHandle) {
Server.prototype.close = function() {
this._handle.close();
};
+
+
+// TODO: isIP should be moved to the DNS code. Putting it here now because
+// this is what the legacy system did.
+exports.isIP = function(input) {
+ if (!input) {
+ return 4;
+ } else if (/^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$/.test(input)) {
+ var parts = input.split('.');
+ for (var i = 0; i < parts.length; i++) {
+ var part = parseInt(parts[i]);
+ if (part < 0 || 255 < part) {
+ return 0;
+ }
+ }
+ return 4;
+ } else if (/^(::)?([a-fA-F0-9]+(::?)?)*$/.test(input)) {
+ return 6;
+ } else {
+ return 0;
+ }
+}
+
+
+exports.isIPv4 = function(input) {
+ return TCP.isIP(input) === 4;
+};
+
+
+exports.isIPv6 = function(input) {
+ return TCP.isIP(input) === 6;
+};