Sha256: 3e455796bb5cbacf87f2421bf43215fda11f19bd9bf73eddd7324c2cdc7fb5d7

Contents?: true

Size: 607 Bytes

Versions: 10

Compression:

Stored size: 607 Bytes

Contents

require "ipaddr"

module Vagrant
  module Util
    module NetworkIP

      DEFAULT_MASK = "255.255.255.0".freeze

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

      # Returns the network address of the given IP and subnet.
      #
      # @return [String]
      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
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/util/network_ip.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/network_ip.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/network_ip.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/network_ip.rb