Method: NetAddr::IPv6Net#summ
- Defined in:
- lib/ipv6net.rb
#summ(other) ⇒ Object
summ creates a summary address from this IPv6Net and another. It returns nil if the two networks are incapable of being summarized.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ipv6net.rb', line 202 def summ(other) if (!other.kind_of?(IPv6Net)) raise ArgumentError, "Expected an IPv6Net object for 'other' but got a #{other.class}." end # netmasks must be identical if (self.netmask.prefix_len != other.netmask.prefix_len) return nil end # merge-able networks will be identical if you right shift them by the number of bits in the hostmask + 1 shift = 128 - self.netmask.prefix_len + 1 addr = self.network.addr >> shift otherAddr = other.network.addr >> shift if (addr != otherAddr) return nil end return self.resize(self.netmask.prefix_len - 1) end |