diff --git a/src/core/net/socket.hpp b/src/core/net/socket.hpp index 27d18d847..f59619d53 100644 --- a/src/core/net/socket.hpp +++ b/src/core/net/socket.hpp @@ -202,7 +202,13 @@ public: * This constructor initializes the object. * */ - SockAddr(void) { memset(this, 0, sizeof(*this)); } + SockAddr(void) { Clear(); } + + /** + * This method clears the object (sets all fields to zero). + * + */ + void Clear(void) { memset(this, 0, sizeof(*this)); } /** * This method returns a reference to the IPv6 address. diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index 874ef00af..5db03c4f1 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -75,8 +75,8 @@ otError UdpSocket::Open(otUdpReceive aHandler, void *aContext) { otError error = OT_ERROR_NONE; - memset(&mSockName, 0, sizeof(mSockName)); - memset(&mPeerName, 0, sizeof(mPeerName)); + GetSockName().Clear(); + GetPeerName().Clear(); mHandler = aHandler; mContext = aContext; @@ -142,8 +142,8 @@ otError UdpSocket::Close(void) #endif Get().RemoveSocket(*this); - memset(&mSockName, 0, sizeof(mSockName)); - memset(&mPeerName, 0, sizeof(mPeerName)); + GetSockName().Clear(); + GetPeerName().Clear(); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE exit: