[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:
Abtin Keshavarzian
2026-02-13 15:15:32 -06:00
committed by GitHub
parent 3ea572212e
commit da64c7cc95
6 changed files with 41 additions and 118 deletions
+21
View File
@@ -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