user211491
user211491

Reputation: 43

convert CIDR to subnet mask in tcl

Given a CIDR, how can I convert it to a subnet mask.

Upvotes: 1

Views: 1839

Answers (2)

andrewsh
andrewsh

Reputation: 1169

Sure it's easy to do in plain Tcl, but you may consider using ip package from Tcllib for IP addresses transformations as it provides numerous convenience functions that make it easy to almost anything you need to do with IPv4 and IPv6 addresses.

Upvotes: 1

ephemient
ephemient

Reputation: 204946

Same way you do in any other language

set n 24
set mask [expr {~ 0 << ( 32 - $n )}]
format "%d.%d.%d.%d" [expr {$mask >> 24 & 255}] [expr {$mask >> 16 & 255}] [expr {$mask >> 8 & 255}] [expr {$mask & 255}]

Upvotes: 3

Related Questions