diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index a123e7116931b0e8d6b4dfbc5461c681c02a111b..a6bea7b2f0829cb8212c8462e011d36fa3e67ac1 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -648,6 +648,20 @@ module IPAddress; [self.class.new("127.0.0.0/8")].any? {|i| i.include? self} end + # + # Checks if an IPv4 address objects belongs + # to a link-local network RFC3927 + # + # Example: + # + # ip = IPAddress "169.254.0.1" + # ip.link_local? + # #=> true + # + def link_local? + [self.class.new("169.254.0.0/16")].any? {|i| i.include? self} + end + # # Returns the IP address in in-addr.arpa format # for DNS lookups diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 6ae651dc509b628bd15825947317e48fefbfd65b..57ed143903de856b04f6d3688317fe06092d18d0 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -422,6 +422,20 @@ module IPAddress; @prefix == 128 and @compressed == "::1" end + # + # Checks if an IPv4 address objects belongs + # to a link-local network RFC4291 + # + # Example: + # + # ip = IPAddress "fe80::1" + # ip.link_local? + # #=> true + # + def link_local? + [self.class.new("fe80::/64")].any? {|i| i.include? self} + end + # # Returns true if the address is a mapped address #