Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IPv6 check for Link-Local unicast address #369

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/tins/ipv6_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ class TINS_API IPv6Address {
*/
bool is_multicast() const;

/**
* \brief Return true if this is a Link-Local unicast IPv6 address.
*
* This method returns true if this address is in the address range
* fe80::/10, false otherwise
*/
bool is_local_unicast() const;

/**
* \brief Returns the size of an IPv6 Address.
*
Expand Down
5 changes: 5 additions & 0 deletions src/ipv6_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Tins {

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

IPv6Address IPv6Address::from_prefix_length(uint32_t prefix_length) {
IPv6Address address;
Expand Down Expand Up @@ -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();
}
Expand Down