diff options
author | Jeremy Evans <[email protected]> | 2019-10-31 10:06:13 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-10-11 13:50:54 +0900 |
commit | 9a321dd9b2fb929873a6b50b41efdf3bd3119536 () | |
tree | 469c1870ae05bd2cf524d00dde36f5489aa8a4c8 /lib/ipaddr.rb | |
parent | b9f7286fe95827631b11342501e471e5e6f13bbb (diff) |
[ruby/ipaddr] Make IPAddr#include? consider range of argument
It would be nice to use Range#cover? here, but it doesn't work correctly before Ruby 2.6. Switch to manual checks of the beginning of end of the ranges. Fixes Ruby Bug 14119 https://.com/ruby/ipaddr/commit/f45630da31
-rw-r--r-- | lib/ipaddr.rb | 31 |
1 files changed, 6 insertions, 25 deletions
@@ -167,34 +167,15 @@ class IPAddr # net1 = IPAddr.new("192.168.2.0/24") # net2 = IPAddr.new("192.168.2.100") # net3 = IPAddr.new("192.168.3.0") # p net1.include?(net2) #=> true # p net1.include?(net3) #=> false def include?(other) - other = coerce_other(other) - if ipv4_mapped? - if (@mask_addr >> 32) != 0xffffffffffffffffffffffff - return false - end - mask_addr = (@mask_addr & IN4MASK) - addr = (@addr & IN4MASK) - family = Socket::AF_INET - else - mask_addr = @mask_addr - addr = @addr - family = @family - end - if other.ipv4_mapped? - other_addr = (other.to_i & IN4MASK) - other_family = Socket::AF_INET - else - other_addr = other.to_i - other_family = other.family - end - - if family != other_family - return false - end - return ((addr & mask_addr) == (other_addr & mask_addr)) end alias === include? |