diff options
author | Michael Miller <icy.arctic.fox@gmail.com> | 2016-11-03 15:40:08 -0600 |
---|---|---|
committer | Romain Tartière <romain@blogreen.org> | 2017-08-30 09:13:22 +0200 |
commit | f35aab8e9109864945f606bef3e135be3763b9c4 (patch) | |
tree | 75edbad63537ba617c155c50e460734b18d81027 | |
parent | 591ad0d5fd81fc0ad447b67fb4ec04ec40eddcd5 (diff) | |
download | ipaddress-f35aab8e9109864945f606bef3e135be3763b9c4.tar.gz |
Implement #link_local? methods
-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 # |