diff options
author | Olivier Blin <oblin@mandriva.com> | 2008-04-03 03:00:22 +0000 |
---|---|---|
committer | Olivier Blin <oblin@mandriva.com> | 2008-04-03 03:00:22 +0000 |
commit | c33751f1f5288b1e2c726b986793e6d351d17739 (patch) | |
tree | badfb49443eb9ffce21d2e1561a1d0f826e8a999 | |
parent | 0cc45e06ebe1b7dba5ab3bc92e9d11fa6b97be5e (diff) | |
download | drakx-net-c33751f1f5288b1e2c726b986793e6d351d17739.tar drakx-net-c33751f1f5288b1e2c726b986793e6d351d17739.tar.gz drakx-net-c33751f1f5288b1e2c726b986793e6d351d17739.tar.bz2 drakx-net-c33751f1f5288b1e2c726b986793e6d351d17739.tar.xz drakx-net-c33751f1f5288b1e2c726b986793e6d351d17739.zip |
add netmask_to_vlsm function (for shorewall masq computing)
-rw-r--r-- | lib/network/network.pm | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/network/network.pm b/lib/network/network.pm index 4ec23a7..827e567 100644 --- a/lib/network/network.pm +++ b/lib/network/network.pm @@ -353,6 +353,18 @@ sub netmask { } } +sub netmask_to_vlsm { + my ($netmask) = @_; + #- based on Network::IPv4Addr::ipv4_msk2cidr + my @bytes = split /\./, $netmask; + my $prefix = 0; + foreach (@bytes) { + my $bits = unpack("B*", pack("C", $_)); + $prefix += $bits =~ tr/1/1/; + } + return $prefix; +} + sub masked_ip { my ($ip) = @_; my @ip = is_ip($ip) or return ''; |