From f35aab8e9109864945f606bef3e135be3763b9c4 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 3 Nov 2016 15:40:08 -0600 Subject: Implement #link_local? methods --- lib/ipaddress/ipv4.rb | 14 ++++++++++++++ lib/ipaddress/ipv6.rb | 14 ++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'lib') 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 @@ -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 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 # -- cgit v1.2.1 From f131450c187953ff3c4e20c9e7e8c0ce7070e224 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 14 Nov 2016 14:32:23 -0700 Subject: Doc fix - copy/paste fail --- lib/ipaddress/ipv6.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 57ed143..6850c03 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -423,7 +423,7 @@ module IPAddress; end # - # Checks if an IPv4 address objects belongs + # Checks if an IPv6 address objects belongs # to a link-local network RFC4291 # # Example: -- cgit v1.2.1 From 548f00716f483876d00532bf76deec6c4171e9d6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 14 Nov 2016 14:33:13 -0700 Subject: Implement unique_local? method --- lib/ipaddress/ipv6.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 6850c03..1012d7d 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -436,6 +436,20 @@ module IPAddress; [self.class.new("fe80::/64")].any? {|i| i.include? self} end + # + # Checks if an IPv6 address objects belongs + # to a unique-local network RFC4193 + # + # Example: + # + # ip = IPAddress "fc00::1" + # ip.unique_local? + # #=> true + # + def unique_local? + [self.class.new("fc00::/7")].any? {|i| i.include? self} + end + # # Returns true if the address is a mapped address # -- cgit v1.2.1