diff options
author | Earlopain <[email protected]> | 2023-12-16 13:58:58 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-12-25 21:12:49 +0900 |
commit | 86fa418dea646e52929b9df9163902c4728442d1 () | |
tree | d4d1e3b815069f71f81ce874390adc168653276e /lib | |
parent | da77c79d80a615130bc67b42d3795db2a3fdd3fe (diff) |
[ruby/ipaddr] Consider IPv4-mapped IPv6 addresses link local/loopback if IPV4 address is private
Same as #57 https://.com/ruby/ipaddr/commit/d56acecb80
-rw-r--r-- | lib/ipaddr.rb | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -252,12 +252,17 @@ class IPAddr end # Returns true if the ipaddr is a loopback address. def loopback? case @family when Socket::AF_INET - @addr & 0xff000000 == 0x7f000000 when Socket::AF_INET6 - @addr == 1 else raise AddressFamilyError, "unsupported address family" end @@ -287,15 +292,19 @@ class IPAddr end # Returns true if the ipaddr is a link-local address. IPv4 - # addresses in 169.254.0.0/16 reserved by RFC 3927 and Link-Local # IPv6 Unicast Addresses in fe80::/10 reserved by RFC 4291 are - # considered link-local. def link_local? case @family when Socket::AF_INET @addr & 0xffff0000 == 0xa9fe0000 # 169.254.0.0/16 when Socket::AF_INET6 - @addr & 0xffc0_0000_0000_0000_0000_0000_0000_0000 == 0xfe80_0000_0000_0000_0000_0000_0000_0000 else raise AddressFamilyError, "unsupported address family" end |