diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 2334aa712..3637b9008 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1330,18 +1330,18 @@ const Address *Ip6::SelectSourceAddress(const Address &aDestination) const overrideScope = destScope; } - if (bestAddr == nullptr) - { - // Rule 0: Prefer any address - bestAddr = &addr; - bestMatchLen = matchLen; - } - else if (addr.GetAddress() == aDestination) + if (addr.GetAddress() == aDestination) { // Rule 1: Prefer same address bestAddr = &addr; ExitNow(); } + + if (bestAddr == nullptr) + { + bestAddr = &addr; + bestMatchLen = matchLen; + } else if (addr.GetScope() < bestAddr->GetScope()) { // Rule 2: Prefer appropriate scope