mirror of
https://github.com/espressif/openthread.git
synced 2026-09-10 03:00:09 +00:00
[nexus] add Node::FindMatchingAddress() helper (#12437)
This commit adds the `Node::FindMatchingAddress()` helper method to the `Nexus::Node` class. This method simplifies the process of finding a unicast address on a node that matches a given IPv6 prefix.
This commit is contained in:
@@ -135,5 +135,26 @@ void Node::GetTrelSockAddr(Ip6::SockAddr &aSockAddr) const
|
||||
}
|
||||
#endif
|
||||
|
||||
const Ip6::Address &Node::FindMatchingAddress(const char *aPrefix)
|
||||
{
|
||||
Ip6::Prefix prefix;
|
||||
const Ip6::Address *matchedAddress = nullptr;
|
||||
|
||||
SuccessOrQuit(prefix.FromString(aPrefix));
|
||||
|
||||
for (const Ip6::Netif::UnicastAddress &unicastAddress : Get<ThreadNetif>().GetUnicastAddresses())
|
||||
{
|
||||
if (unicastAddress.GetAddress().MatchesPrefix(prefix))
|
||||
{
|
||||
matchedAddress = &unicastAddress.GetAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VerifyOrQuit(matchedAddress != nullptr, "no matching address found");
|
||||
|
||||
return *matchedAddress;
|
||||
}
|
||||
|
||||
} // namespace Nexus
|
||||
} // namespace ot
|
||||
|
||||
Reference in New Issue
Block a user