Tcl Library Source Code

Artifact Content
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Artifact 927b8447a3cb4dbbf87deff48cd3f8e90675676b9abf845f2ffa6636a171dce0:

Attachment "make_ip_version_and_mask_more_strict.diff" to ticket [b1c2d07148] added by buzzdeee 2019-06-13 11:56:15. (unpublished)
--- 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
 }