instance method
IPAddr#loopback?
() -> bool
loopback?
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/ipaddr.rb, line 290
def loopback?
case @family
when Socket::AF_INET
@addr & 0xff000000 == 0x7f000000 # 127.0.0.1/8
when Socket::AF_INET6
@addr == 1 || # ::1
(@addr & 0xffff_0000_0000 == 0xffff_0000_0000 && (
@addr & 0xff000000 == 0x7f000000 # ::ffff:127.0.0.1/8
))
else
raise AddressFamilyError, "unsupported address family"
end
end
Returns true if the ipaddr is a loopback address. Loopback IPv4 addresses in the IPv4-mapped IPv6 address range are also considered as loopback addresses.