diff options
author | Francis Luong (Franco) <franco@definefunk.com> | 2017-09-01 14:25:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 14:25:54 -0400 |
commit | a172928b3a29c9286800bf8e4d9a9f13f0cf738a (patch) | |
tree | 17c0673bca4b2bcc1a3f101d4e9b6b14dabade21 /lib | |
parent | f16c587af31c750a93ca40def9e7f2f7115fb1c7 (diff) | |
parent | 548f00716f483876d00532bf76deec6c4171e9d6 (diff) | |
download | ipaddress-a172928b3a29c9286800bf8e4d9a9f13f0cf738a.tar.gz |
Merge pull request #83 from icy-arctic-fox/link-local
Add detection of link-local addresses
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ipaddress/ipv4.rb | 14 | ||||
-rw-r--r-- | lib/ipaddress/ipv6.rb | 28 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 19ab14c..ade1851 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -651,6 +651,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 3e506ac..adc6243 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -423,6 +423,34 @@ module IPAddress; @prefix == 128 and @compressed == "::1" end + # + # Checks if an IPv6 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 + + # + # 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 # |