diff options
author | Alan Somers <asomers@gmail.com> | 2017-08-28 16:41:04 -0600 |
---|---|---|
committer | Romain Tartière <romain@blogreen.org> | 2017-08-29 21:44:28 +0200 |
commit | 2edbae88448d0a6b0ea24a7fe6b39a62073af234 (patch) | |
tree | d18a224154faa746455723c415047473fabc18a6 | |
parent | 7f68225cc4a72c00b310c1ecbd6900b193ac2ec6 (diff) | |
download | ipaddress-2edbae88448d0a6b0ea24a7fe6b39a62073af234.tar.gz |
Add IPv6#link_local?
-rw-r--r-- | lib/ipaddress/ipv6.rb | 7 | ||||
-rw-r--r-- | test/ipaddress/ipv6_test.rb | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 88098bc..6ae651d 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -397,6 +397,13 @@ module IPAddress; @compressed end + # + # Returns true if the address is a link local address + # + def link_local? + @groups[0] == 0xfe80 + end + # # Returns true if the address is an unspecified address # diff --git a/test/ipaddress/ipv6_test.rb b/test/ipaddress/ipv6_test.rb index dcfb601..7eaa765 100644 --- a/test/ipaddress/ipv6_test.rb +++ b/test/ipaddress/ipv6_test.rb @@ -200,6 +200,12 @@ class IPv6Test < Minitest::Test assert_equal "1::1", @klass.new("1:0:0:0:0:0:0:1").compressed end + def test_method_link_local? + assert_equal true, @klass.new("fe80::1").link_local? + assert_equal true, @klass.new("fe80:ffff::1").link_local? + assert_equal false, @klass.new("fe81::1").link_local? + end + def test_method_unspecified? assert_equal true, @klass.new("::").unspecified? assert_equal false, @ip.unspecified? |