Class: IPAddr
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(arg) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/infra/ospf_common.rb', line 135 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
153 154 155 |
# File 'lib/infra/ospf_common.rb', line 153 def +(i) [IPAddr.create(to_i + i).to_s, mlen].join("/") end |
#^(i) ⇒ Object
156 157 158 159 |
# File 'lib/infra/ospf_common.rb', line 156 def ^(i) @increment ||= _generate_network_inc_ [IPAddr.create(to_i + @increment.call(i)).to_s, mlen].join("/") end |
#mlen ⇒ Object
149 150 151 |
# File 'lib/infra/ospf_common.rb', line 149 def mlen @_jme_mlen_ ||= _mlen_ end |
#netmask ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/infra/ospf_common.rb', line 161 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
174 175 176 |
# File 'lib/infra/ospf_common.rb', line 174 def to_s_net [to_s,mlen].join('/') end |