From 608b48f25cf45062caf4cfa3de5a483cee305300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karas=20Luk=C3=A1=C5=A1?= Date: Tue, 1 Oct 2019 17:08:01 +0200 Subject: [PATCH 1/2] add IPv6 check for Link-Local unicast address --- include/tins/ipv6_address.h | 8 ++++++++ src/ipv6_address.cpp | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index 553e38e..ee21022 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -230,6 +230,14 @@ public: */ bool is_multicast() const; + /** + * \brief Return true fi this is a Link-Local unicast IPv6 address. + * + * This method returns true fi this address is in the address range + * fe80::/10, false otherwise + */ + bool is_local_unicast() const; + /** * \brief Returns the size of an IPv6 Address. * diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index cd2d7a3..8272213 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -57,6 +57,7 @@ namespace Tins { const IPv6Address loopback_address = "::1"; const AddressRange multicast_range = IPv6Address("ff00::") / 8; +const AddressRange local_unicast_range = IPv6Address("fe80::") / 10; IPv6Address IPv6Address::from_prefix_length(uint32_t prefix_length) { IPv6Address address; @@ -138,6 +139,10 @@ bool IPv6Address::is_multicast() const { return multicast_range.contains(*this); } +bool IPv6Address::is_local_unicast() const { + return local_unicast_range.contains(*this); +} + ostream& operator<<(ostream& os, const IPv6Address& addr) { return os << addr.to_string(); } From 731e36e3736f8e4c8278a301167fdcbe49747a10 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Wed, 2 Oct 2019 08:32:54 -0700 Subject: [PATCH 2/2] Fix "fi" in comment --- include/tins/ipv6_address.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index ee21022..7597921 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -231,9 +231,9 @@ public: bool is_multicast() const; /** - * \brief Return true fi this is a Link-Local unicast IPv6 address. + * \brief Return true if this is a Link-Local unicast IPv6 address. * - * This method returns true fi this address is in the address range + * This method returns true if this address is in the address range * fe80::/10, false otherwise */ bool is_local_unicast() const;