Class: IPAddr
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(arg) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/infra/ospf_common.rb', line 126 def self.create(arg) if arg.is_a?(String) and arg.is_packed? IPAddr.new_ntoh(arg) elsif arg.is_a?(Integer) IPAddr.new_ntoh([arg].pack('N')) elsif arg.is_a?(Array) and arg[0].is_a?(Fixnum) IPAddr.new_ntoh([arg].pack('C*')) elsif arg.is_a?(self) IPAddr.new else IPAddr.new(arg) end end |
Instance Method Details
#+(i) ⇒ Object
144 145 146 |
# File 'lib/infra/ospf_common.rb', line 144 def +(i) [IPAddr.create(to_i + i).to_s, mlen].join("/") end |
#^(i) ⇒ Object
147 148 149 150 |
# File 'lib/infra/ospf_common.rb', line 147 def ^(i) @increment ||= _generate_network_inc_ [IPAddr.create(to_i + @increment.call(i)).to_s, mlen].join("/") end |
#mlen ⇒ Object
140 141 142 |
# File 'lib/infra/ospf_common.rb', line 140 def mlen @_jme_mlen_ ||= _mlen_ end |
#netmask ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/infra/ospf_common.rb', line 152 def netmask if ipv4? [@mask_addr].pack('N').unpack('C4').collect { |x| x.to_s}.join('.') else i = @mask_addr arr=[] while i>0 arr << (i & 0xffff) and i >>= 16 end arr.reverse.collect { |x| x.to_s(16) }.join(':') end end |
#to_s_net ⇒ Object
165 166 167 |
# File 'lib/infra/ospf_common.rb', line 165 def to_s_net [to_s,mlen].join('/') end |