Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
IPAddr#multicast?
multicast?
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ipaddr.rb, line 357
def multicast?
case @family
when Socket::AF_INET
(@addr & 0xf0000000 == 0xe0000000) && prefix >= 4 # 224.0.0.0/4
when Socket::AF_INET6
(@addr & 0xff00_0000_0000_0000_0000_0000_0000_0000 == 0xff00_0000_0000_0000_0000_0000_0000_0000) && prefix >= 8 || # ff00::/8
(@addr >> 32 == 0xffff &&
(@addr & 0xf0000000 == 0xe0000000) && prefix >= 100 # ::ffff:224.0.0.0/100 (224.0.0.0/4)
)
else
raise AddressFamilyError, "unsupported address family"
end
end
Returns true if the ipaddr is a multicast address. IPv4 addresses in 224.0.0.0/4 and IPv6 multicast addresses in ff00::/8 are considered multicast. Multicast IPv4 addresses in the IPv4-mapped IPv6 address range are also considered multicast.