module Proxy::DHCP::Infoblox::IpAddressArithmetic
Public Instance Methods
cidr_to_bitmask(prefix_length)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 16 def cidr_to_bitmask(prefix_length) 0xFFFFFFFF ^ (2**(32 - prefix_length) - 1) end
cidr_to_i(an_address_with_cidr)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 20 def cidr_to_i(an_address_with_cidr) an_address_with_cidr.split("/").last.to_i end
cidr_to_ip_mask(prefix_length)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 3 def cidr_to_ip_mask(prefix_length) bitmask = 0xFFFFFFFF ^ (2**(32 - prefix_length) - 1) (0..3).map { |i| (bitmask >> i * 8) & 0xFF }.reverse.join('.') end
i_to_ipv4(i)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 12 def i_to_ipv4(i) (0..3).inject([]) { |a, c| a.push((i >> (c * 8)) & 0xFF) }.reverse.join('.') end
ipv4_to_i(an_address)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 8 def ipv4_to_i(an_address) an_address.split('.').inject(0) { |a, c| (a << 8) + c.to_i } end
network_cidr_to_range(network_and_cidr)
click to toggle source
# File lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb, line 24 def network_cidr_to_range(network_and_cidr) network_addr, cidr = network_and_cidr.split('/') mask = cidr_to_bitmask(cidr.to_i) range_start = ipv4_to_i(network_addr) & mask range_end = range_start | (0xFFFFFFFF ^ mask) [i_to_ipv4(range_start), i_to_ipv4(range_end)] end