Skip to content

Commit 28663b0

Browse files
authored
Merge pull request #369 from avast/ipv6-local-unicast
add IPv6 check for Link-Local unicast address
2 parents de247fc + 731e36e commit 28663b0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/tins/ipv6_address.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ class TINS_API IPv6Address {
230230
*/
231231
bool is_multicast() const;
232232

233+
/**
234+
* \brief Return true if this is a Link-Local unicast IPv6 address.
235+
*
236+
* This method returns true if this address is in the address range
237+
* fe80::/10, false otherwise
238+
*/
239+
bool is_local_unicast() const;
240+
233241
/**
234242
* \brief Returns the size of an IPv6 Address.
235243
*

src/ipv6_address.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace Tins {
5757

5858
const IPv6Address loopback_address = "::1";
5959
const AddressRange<IPv6Address> multicast_range = IPv6Address("ff00::") / 8;
60+
const AddressRange<IPv6Address> local_unicast_range = IPv6Address("fe80::") / 10;
6061

6162
IPv6Address IPv6Address::from_prefix_length(uint32_t prefix_length) {
6263
IPv6Address address;
@@ -138,6 +139,10 @@ bool IPv6Address::is_multicast() const {
138139
return multicast_range.contains(*this);
139140
}
140141

142+
bool IPv6Address::is_local_unicast() const {
143+
return local_unicast_range.contains(*this);
144+
}
145+
141146
ostream& operator<<(ostream& os, const IPv6Address& addr) {
142147
return os << addr.to_string();
143148
}

0 commit comments

Comments
 (0)