Sha256: aa906bd9ca7d1e50e6453778f73d48aa9500f5ed1b250a257bf6aad5eeccd5a2

Contents?: true

Size: 934 Bytes

Versions: 20

Compression:

Stored size: 934 Bytes

Contents

require 'ipaddr'

# IPCidr object wrapper for IPAddr
module Puppet
  module Util
    class IPCidr < IPAddr
      def initialize(ipaddr)
        begin
          super(ipaddr)
        rescue ArgumentError => e
          if e.message =~ /invalid address/
            raise ArgumentError, "Invalid address from IPAddr.new: #{ipaddr}"
          else
            raise e
          end
        end
      end

      def netmask
        _to_string(@mask_addr)
      end

      def prefixlen
        m = case @family
            when Socket::AF_INET
              IN4MASK
            when Socket::AF_INET6
              IN6MASK
            else
              raise "unsupported address family"
            end
        return $1.length if /\A(1*)(0*)\z/ =~ (@mask_addr & m).to_s(2)
        raise "bad addr_mask format"
      end

      def cidr
        cidr = sprintf("%s/%s", self.to_s, self.prefixlen)
        cidr
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
freighthop-0.6.1 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.6.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.5.2 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.5.1 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.5.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.4.1 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.4.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.3.3 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.3.2 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.3.1 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.3.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.2.1 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.2.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.1.0 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.6 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.5 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.4 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.3 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.2 modules/firewall/lib/puppet/util/ipcidr.rb
freighthop-0.0.1 modules/firewall/lib/puppet/util/ipcidr.rb