Class: IPAddr
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(arg) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/infra/ospf_common.rb', line 115 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
133 134 135 |
# File 'lib/infra/ospf_common.rb', line 133 def +(i) [IPAddr.create(to_i + i).to_s, mlen].join("/") end |
#^(i) ⇒ Object
136 137 138 139 |
# File 'lib/infra/ospf_common.rb', line 136 def ^(i) @increment ||= _generate_network_inc_ [IPAddr.create(to_i + @increment.call(i)).to_s, mlen].join("/") end |
#mlen ⇒ Object
129 130 131 |
# File 'lib/infra/ospf_common.rb', line 129 def mlen @_jme_mlen_ ||= _mlen_ end |
#netmask ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/infra/ospf_common.rb', line 141 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
154 155 156 |
# File 'lib/infra/ospf_common.rb', line 154 def to_s_net [to_s,mlen].join('/') end |