diff --git a/src/core/api/udp_api.cpp b/src/core/api/udp_api.cpp index dcca993fc..ed42d9a8a 100644 --- a/src/core/api/udp_api.cpp +++ b/src/core/api/udp_api.cpp @@ -81,7 +81,10 @@ exit: return error; } -otUdpSocket *otUdpGetSockets(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetUdpSockets(); } +otUdpSocket *otUdpGetSockets(otInstance *aInstance) +{ + return AsCoreType(aInstance).Get().GetUdpSockets().GetHead(); +} #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE void otUdpForwardSetForwarder(otInstance *aInstance, otUdpForwarder aForwarder, void *aContext) diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index b2ecc923a..ef88cbfaf 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -500,11 +500,11 @@ public: void HandlePayload(Message &aMessage, MessageInfo &aMessageInfo); /** - * Returns the head of UDP Sockets list. + * Returns the UDP Sockets linked list. * - * @returns A pointer to the head of UDP Socket linked list. + * @returns The UDP Sockets linked list. */ - SocketHandle *GetUdpSockets(void) { return mSockets.GetHead(); } + LinkedList &GetUdpSockets(void) { return mSockets; } #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE /** diff --git a/tests/nexus/platform/nexus_udp.cpp b/tests/nexus/platform/nexus_udp.cpp index 577e722dc..c3f802630 100644 --- a/tests/nexus/platform/nexus_udp.cpp +++ b/tests/nexus/platform/nexus_udp.cpp @@ -177,23 +177,22 @@ bool Udp::HandleReceive(const Message &aMessage, const Ip6::Headers &aHeaders) ExitNow(); } - for (Ip6::Udp::SocketHandle *socket = GetNode().Get().GetUdpSockets(); socket != nullptr; - socket = socket->GetNext()) + for (Ip6::Udp::SocketHandle &socket : GetNode().Get().GetUdpSockets()) { Ip6::MessageInfo messageInfo; - if (!socket->ShouldUsePlatformUdp()) + if (!socket.ShouldUsePlatformUdp()) { continue; } - if (socket->GetSockName().GetPort() != aHeaders.GetDestinationPort()) + if (socket.GetSockName().GetPort() != aHeaders.GetDestinationPort()) { continue; } - if (socket->GetSockName().GetAddress().IsUnspecified() || - socket->GetSockName().GetAddress() == aHeaders.GetDestinationAddress()) + if (socket.GetSockName().GetAddress().IsUnspecified() || + socket.GetSockName().GetAddress() == aHeaders.GetDestinationAddress()) { // Found a matching socket. } @@ -202,16 +201,16 @@ bool Udp::HandleReceive(const Message &aMessage, const Ip6::Headers &aHeaders) continue; } - if (socket->GetPeerName().GetPort() != 0) + if (socket.GetPeerName().GetPort() != 0) { - if (socket->GetPeerName().GetPort() != aHeaders.GetSourcePort() || - socket->GetPeerName().GetAddress() != aHeaders.GetSourceAddress()) + if (socket.GetPeerName().GetPort() != aHeaders.GetSourcePort() || + socket.GetPeerName().GetAddress() != aHeaders.GetSourceAddress()) { continue; } } - if (socket->mHandler == nullptr) + if (socket.mHandler == nullptr) { continue; } @@ -229,7 +228,7 @@ bool Udp::HandleReceive(const Message &aMessage, const Ip6::Headers &aHeaders) VerifyOrExit(payload != nullptr); payload->RemoveHeader(sizeof(Ip6::Header) + sizeof(Ip6::Udp::Header)); - socket->mHandler(socket->mContext, payload, &messageInfo); + socket.mHandler(socket.mContext, payload, &messageInfo); payload->Free(); }