[api] add API to find source address (#3273)

This commit is contained in:
Yakun Xu
2018-11-07 22:35:39 -08:00
committed by Jonathan Hui
parent 4f99bcfaf3
commit cf5352fb43
2 changed files with 25 additions and 0 deletions
+11
View File
@@ -537,6 +537,17 @@ OTAPI uint8_t OTCALL otIp6PrefixMatch(const otIp6Address *aFirst, const otIp6Add
*/
bool otIp6IsAddressUnspecified(const otIp6Address *aAddress);
/**
* This function perform OpenThread source address selection.
*
* @param[inout] aMessageInfo A pointer to the message information.
*
* @retval OT_ERROR_NONE Found a source address and is filled into mSockAddr of @p aMessageInfo.
* @retval OT_ERROR_NOT_FOUND No source address was found and @p aMessageInfo is unchanged.
*
*/
otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageInfo);
/**
* @}
*
+14
View File
@@ -264,3 +264,17 @@ bool otIp6IsAddressUnspecified(const otIp6Address *aAddress)
{
return static_cast<const Ip6::Address *>(aAddress)->IsUnspecified();
}
otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageInfo)
{
otError error = OT_ERROR_NONE;
Instance & instance = *static_cast<Instance *>(aInstance);
const Ip6::NetifUnicastAddress *netifAddr;
netifAddr = instance.GetIp6().SelectSourceAddress(*static_cast<Ip6::MessageInfo *>(aMessageInfo));
VerifyOrExit(netifAddr != NULL, error = OT_ERROR_NOT_FOUND);
memcpy(&aMessageInfo->mSockAddr, &netifAddr->mAddress, sizeof(aMessageInfo->mSockAddr));
exit:
return error;
}