From f35aab8e9109864945f606bef3e135be3763b9c4 Mon Sep 17 00:00:00 2001
From: Michael Miller <icy.arctic.fox@gmail.com>
Date: Thu, 3 Nov 2016 15:40:08 -0600
Subject: [PATCH] Implement #link_local? methods

---
 lib/ipaddress/ipv4.rb | 14 ++++++++++++++
 lib/ipaddress/ipv6.rb | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

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
     # 
-- 
GitLab