Class: Puppet::Util::IPCidr
- Inherits:
-
IPAddr
- Object
- IPAddr
- Puppet::Util::IPCidr
- Defined in:
- lib/puppet/util/ipcidr.rb
Overview
IPCidr object wrapper for IPAddr
Instance Method Summary collapse
- #cidr ⇒ Object
-
#initialize(ipaddr, family = Socket::AF_UNSPEC) ⇒ IPCidr
constructor
A new instance of IPCidr.
- #netmask ⇒ Object
- #prefixlen ⇒ Object
Constructor Details
#initialize(ipaddr, family = Socket::AF_UNSPEC) ⇒ IPCidr
Returns a new instance of IPCidr.
8 9 10 11 12 13 |
# File 'lib/puppet/util/ipcidr.rb', line 8 def initialize(ipaddr, family = Socket::AF_UNSPEC) super(ipaddr, family) rescue ArgumentError => e raise ArgumentError, "Invalid address from IPAddr.new: #{ipaddr}" if %r{invalid address}.match?(e.) raise e end |
Instance Method Details
#cidr ⇒ Object
32 33 34 |
# File 'lib/puppet/util/ipcidr.rb', line 32 def cidr "#{self}/#{prefixlen}" end |
#netmask ⇒ Object
15 16 17 |
# File 'lib/puppet/util/ipcidr.rb', line 15 def netmask _to_string(@mask_addr) end |
#prefixlen ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet/util/ipcidr.rb', line 19 def prefixlen m = case @family when Socket::AF_INET IN4MASK when Socket::AF_INET6 IN6MASK else raise 'unsupported address family' end return Regexp.last_match(1).length if %r{\A(1*)(0*)\z} =~ (@mask_addr & m).to_s(2) raise 'bad addr_mask format' end |