--- ip.tcl.orig	Thu Jun 13 13:15:56 2019
+++ ip.tcl	Thu Jun 13 13:51:19 2019
@@ -66,9 +66,26 @@
     foreach {addr mask} [split $ip /] break
     if {[IPv4? $addr]} {
         set version 4
+        set maxlen 32
     } elseif {[IPv6? $addr]} {
         set version 6
+        set maxlen 128
     }
+    if { "" != $mask } {
+        if {[string is integer -strict $mask]} {
+          switch -exact $version {
+              4 {
+                    if {$mask < 0 || $mask > 32} { return -1 }
+                }
+              6 {
+                    if {$mask < 0 || $mask > 128} { return -1 }
+                }
+          }
+        } else {
+            return -1
+        }
+    }
+
     return $version
 }
         
@@ -337,6 +354,10 @@
 }
 
 proc ::ip::mask {ip} {
+    set version [version $ip]
+    if { -1 == $version } {
+      return $version
+    }
     foreach {addr mask} [split $ip /] break
     return $mask
 }
