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.
7 8 9 10 11 12 |
# File 'lib/puppet/util/ipcidr.rb', line 7 def initialize(ipaddr, family = Socket::AF_UNSPEC) super(ipaddr, family) rescue ArgumentError => e raise ArgumentError, "Invalid address from IPAddr.new: #{ipaddr}" if e. =~ %r{invalid address} raise e end |
Instance Method Details
#cidr ⇒ Object
31 32 33 34 |
# File 'lib/puppet/util/ipcidr.rb', line 31 def cidr cidr = '%s/%s' % [to_s, prefixlen] cidr end |
#netmask ⇒ Object
14 15 16 |
# File 'lib/puppet/util/ipcidr.rb', line 14 def netmask _to_string(@mask_addr) end |
#prefixlen ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet/util/ipcidr.rb', line 18 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 |