diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index eaa7dc01e..83c5d5fca 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -486,21 +486,7 @@ exit: return; } -bool Udp::IsPortInUse(uint16_t aPort) const -{ - bool found = false; - - for (const SocketHandle &socket : mSockets) - { - if (socket.GetSockName().GetPort() == aPort) - { - found = true; - break; - } - } - - return found; -} +bool Udp::IsPortInUse(uint16_t aPort) const { return mSockets.ContainsMatching(aPort); } } // namespace Ip6 } // namespace ot diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index d9d7cc8b8..cd00cd5a3 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -162,6 +162,7 @@ public: #endif private: + bool Matches(uint16_t aSockPort) const { return GetSockName().GetPort() == aSockPort; } bool Matches(const MessageInfo &aMessageInfo) const; void HandleUdpReceive(Message &aMessage, const MessageInfo &aMessageInfo)