Skip to content

Commit

Permalink
[nrf5-demo] Change perference when selecting IP for publishing service (
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored Aug 19, 2020
1 parent 4af7537 commit eaa1380
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/platform/nrf528xx/app/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ void PublishService()
memset(&mSocket, 0, sizeof(mSocket));
memset(&messageInfo, 0, sizeof(messageInfo));

// Use mesh local EID by default, if we have GUA, use that IP address.
memcpy(&messageInfo.mSockAddr, otThreadGetMeshLocalEid(ThreadStackMgrImpl().OTInstance()), sizeof(messageInfo.mSockAddr));

// Select a address to send
const otNetifAddress * otAddrs = otIp6GetUnicastAddresses(ThreadStackMgrImpl().OTInstance());
for (const otNetifAddress * otAddr = otAddrs; otAddr != NULL; otAddr = otAddr->mNext)
{
addr = chip::DeviceLayer::Internal::ToIPAddress(otAddr->mAddress);
if (otAddr->mValid && !otAddr->mRloc &&
(!addr.IsIPv6ULA() ||
::chip::DeviceLayer::Internal::IsOpenThreadMeshLocalAddress(ThreadStackMgrImpl().OTInstance(), addr)))
if (otAddr->mValid && addr.IsIPv6GlobalUnicast())
{
memcpy(&messageInfo.mSockAddr, &(otAddr->mAddress), sizeof(otAddr->mAddress));
break;
Expand Down

0 comments on commit eaa1380

Please sign in to comment.