Skip to content

Commit

Permalink
Modified Netmask::FromBits for longer prefixes
Browse files Browse the repository at this point in the history
Do not try to handle non IPv4 prefixes.
  • Loading branch information
mchf committed Sep 11, 2013
1 parent 78760bd commit 6926172
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/types/src/modules/Netmask.rb
Expand Up @@ -108,10 +108,16 @@ def Check(netmask)
Check4(netmask) || Check6(netmask)
end

# Convert netmask in bits form (20) to netmask string (255.255.240.0)
# @param [Fixnum] bits number of bits in netmask
# @return netmask string
#
# Convert netmask in bits form (20) to IPv4 netmask string (255.255.240.0)
#
# @param bits number of bits in netmask
# @return netmask string or empty string in case of invalid bits (e.g.
# when prefix is incompatible with IPv4)
#
def FromBits(bits)
return "" unless bits.between?( 0, 32)

b = Ops.divide(bits, 8)
d = Ops.modulo(bits, 8)

Expand Down

0 comments on commit 6926172

Please sign in to comment.