Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
IPAddr#link_local_unicast?
link_local_unicast?
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ipaddr.rb, line 337
def link_local?
case @family
when Socket::AF_INET
(@addr & 0xffff0000 == 0xa9fe0000) && prefix >= 16 # 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) && prefix >= 10 || # fe80::/10
(@addr >> 32 == 0xffff && (
(@addr & 0xffff0000 == 0xa9fe0000) && prefix >= 112 # ::ffff:169.254.0.0/112 (169.254.0.0/16)
))
else
raise AddressFamilyError, "unsupported address family"
end
end
Alias of #link_local?
Returns true if the ipaddr is a link-local unicast 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. Link-local IPv4 addresses in the IPv4-mapped IPv6 address range are also considered link-local.