Skip to content

Commit

Permalink
Fix include? and ipv4_mapped to allow drb tests to pass
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeremyevans committed Oct 7, 2021
1 parent 94c3391 commit da22ef8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ def mask(prefixlen)
# p net1.include?(net4) #=> false
# p net4.include?(net1) #=> true
def include?(other)
other = coerce_other(other)
return false unless other.family == family
range = to_range
other = coerce_other(other).to_range
other = other.to_range
range.begin <= other.begin && range.end >= other.end
end
alias === include?
Expand Down Expand Up @@ -316,7 +318,9 @@ def ipv4_mapped
if !ipv4?
raise InvalidAddressError, "not an IPv4 address: #{@addr}"
end
return self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
clone = self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
clone.instance_variable_set(:@mask_addr, @mask_addr | 0xffffffffffffffffffffffff00000000)
clone
end

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

0 comments on commit da22ef8

Please sign in to comment.