Module: Vagrant::Util::NetworkIP

Defined in:
lib/vagrant/util/network_ip.rb

Constant Summary collapse

DEFAULT_MASK =
"255.255.255.0".freeze
LOGGER =
Log4r::Logger.new("vagrant::util::NetworkIP")

Instance Method Summary collapse

Instance Method Details

#network_address(ip, subnet) ⇒ String

Returns the network address of the given IP and subnet.

Returns:

  • (String)

14
15
16
17
18
19
20
21
# File 'lib/vagrant/util/network_ip.rb', line 14

def network_address(ip, subnet)
  begin
    IPAddr.new(ip).mask(subnet).to_s
  rescue IPAddr::InvalidPrefixError
    LOGGER.warn("Provided mask '#{subnet}' is invalid. Falling back to using mask '#{DEFAULT_MASK}'")
    IPAddr.new(ip).mask(DEFAULT_MASK).to_s
  end
end