Module: Vagrant::Util::NetworkIP

Included in:
Action::VM::Network
Defined in:
lib/vagrant/util/network_ip.rb

Instance Method Summary collapse

Instance Method Details

#network_address(ip, subnet) ⇒ String

Returns the network address of the given IP and subnet.

Returns:

  • (String)


7
8
9
10
11
12
13
14
15
# File 'lib/vagrant/util/network_ip.rb', line 7

def network_address(ip, subnet)
  ip      = ip_parts(ip)
  netmask = ip_parts(subnet)

  # Bitwise-AND each octet to get the network address
  # in octets and join each part with a period to get
  # the resulting network address.
  ip.map { |part| part & netmask.shift }.join(".")
end