diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 38afbb10de9c4be7afe9dc444c8fb9b92f02c160..643781046de33dc446b2bfc44e5aee13c92ea0f8 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -598,6 +598,34 @@ module IPAddress; [self.class.new("224.0.0.0/4")].any? {|i| i.include? self} end + # + # Checks if an IPv4 address objects belongs + # to a multicast network RFC3171 + # + # Example: + # + # ip = IPAddress "224.0.0.0/4" + # ip.multicast? + # #=> true + # + def multicast? + [self.class.new("224.0.0.0/4")].any? {|i| i.include? self} + end + + # + # Checks if an IPv4 address objects belongs + # to a loopback network RFC1122 + # + # Example: + # + # ip = IPAddress "127.0.0.1" + # ip.loopback? + # #=> true + # + def loopback? + [self.class.new("127.0.0.0/8")].any? {|i| i.include? self} + end + # # Returns the IP address in in-addr.arpa format # for DNS lookups