diff options
-rw-r--r-- | lib/ipaddress/ipv4.rb | 14 | ||||
-rw-r--r-- | lib/ipaddress/ipv6.rb | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index a123e71..a6bea7b 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -649,6 +649,20 @@ module IPAddress; 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 6ae651d..57ed143 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 # |