Skip to content

Commit da22ef8

Browse files
committed
Fix include? and ipv4_mapped to allow drb tests to pass
include? should return false if comparing an IPv4 address to an IPv6 address. ipv4_mapped needs to set the correct netmask on the mapped addresses.
1 parent 94c3391 commit da22ef8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/ipaddr.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ def mask(prefixlen)
173173
# p net1.include?(net4) #=> false
174174
# p net4.include?(net1) #=> true
175175
def include?(other)
176+
other = coerce_other(other)
177+
return false unless other.family == family
176178
range = to_range
177-
other = coerce_other(other).to_range
179+
other = other.to_range
178180
range.begin <= other.begin && range.end >= other.end
179181
end
180182
alias === include?
@@ -316,7 +318,9 @@ def ipv4_mapped
316318
if !ipv4?
317319
raise InvalidAddressError, "not an IPv4 address: #{@addr}"
318320
end
319-
return self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
321+
clone = self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
322+
clone.instance_variable_set(:@mask_addr, @mask_addr | 0xffffffffffffffffffffffff00000000)
323+
clone
320324
end
321325

322326
# Returns a new ipaddr built by converting the native IPv4 address

0 commit comments

Comments
 (0)