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