diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 70b5dd1da..66d4c7739 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1536,9 +1536,8 @@ otError Interpreter::ProcessDns(Arg aArgs[]) { const otDnsQueryConfig *defaultConfig = otDnsClientGetDefaultConfig(GetInstancePtr()); - OutputFormat("Server: ["); - OutputIp6Address(defaultConfig->mServerSockAddr.mAddress); - OutputLine("]:%d", defaultConfig->mServerSockAddr.mPort); + OutputFormat("Server: "); + OutputSockAddrLine(defaultConfig->mServerSockAddr); OutputLine("ResponseTimeout: %u ms", defaultConfig->mResponseTimeout); OutputLine("MaxTxAttempts: %u", defaultConfig->mMaxTxAttempts); OutputLine("RecursionDesired: %s", diff --git a/src/cli/cli_history.cpp b/src/cli/cli_history.cpp index 2292e016b..2a8ce8f92 100644 --- a/src/cli/cli_history.cpp +++ b/src/cli/cli_history.cpp @@ -542,7 +542,6 @@ void History::OutputRxTxEntryListFormat(const otHistoryTrackerMessageInfo &aInfo constexpr uint8_t kIndentSize = 4; char ageString[OT_HISTORY_TRACKER_ENTRY_AGE_STRING_SIZE]; - char addrString[OT_IP6_SOCK_ADDR_STRING_SIZE]; otHistoryTrackerEntryAgeToString(aEntryAge, ageString, sizeof(ageString)); @@ -561,11 +560,11 @@ void History::OutputRxTxEntryListFormat(const otHistoryTrackerMessageInfo &aInfo OutputLine(" %s:0x%04x radio:%s", aIsRx ? "from" : "to", aInfo.mNeighborRloc16, RadioTypeToString(aInfo)); - otIp6SockAddrToString(&aInfo.mSource, addrString, sizeof(addrString)); - OutputLine(kIndentSize, "src:%s", addrString); + OutputFormat(kIndentSize, "src:"); + OutputSockAddrLine(aInfo.mSource); - otIp6SockAddrToString(&aInfo.mDestination, addrString, sizeof(addrString)); - OutputLine(kIndentSize, "dst:%s", addrString); + OutputFormat(kIndentSize, "dst:"); + OutputSockAddrLine(aInfo.mDestination); } void History::OutputRxTxEntryTableFormat(const otHistoryTrackerMessageInfo &aInfo, uint32_t aEntryAge, bool aIsRx) diff --git a/src/cli/cli_output.cpp b/src/cli/cli_output.cpp index 99a3e6fcf..5fc58d905 100644 --- a/src/cli/cli_output.cpp +++ b/src/cli/cli_output.cpp @@ -174,6 +174,21 @@ void Output::OutputIp6PrefixLine(const otIp6NetworkPrefix &aPrefix) OutputLine(""); } +void Output::OutputSockAddr(const otSockAddr &aSockAddr) +{ + char string[OT_IP6_SOCK_ADDR_STRING_SIZE]; + + otIp6SockAddrToString(&aSockAddr, string, sizeof(string)); + + return OutputFormat("%s", string); +} + +void Output::OutputSockAddrLine(const otSockAddr &aSockAddr) +{ + OutputSockAddr(aSockAddr); + OutputLine(""); +} + void Output::OutputDnsTxtData(const uint8_t *aTxtData, uint16_t aTxtDataLength) { otDnsTxtEntry entry; diff --git a/src/cli/cli_output.hpp b/src/cli/cli_output.hpp index d0f95a6d8..c2128a3ff 100644 --- a/src/cli/cli_output.hpp +++ b/src/cli/cli_output.hpp @@ -239,6 +239,22 @@ public: */ void OutputIp6PrefixLine(const otIp6NetworkPrefix &aPrefix); + /** + * This method outputs an IPv6 socket address to the CLI console. + * + * @param[in] aSockAddr A reference to the IPv6 socket address. + * + */ + void OutputSockAddr(const otSockAddr &aSockAddr); + + /** + * This method outputs an IPv6 socket address to the CLI console and at the end it also outputs newline "\r\n". + * + * @param[in] aSockAddr A reference to the IPv6 socket address. + * + */ + void OutputSockAddrLine(const otSockAddr &aSockAddr); + /** * This method outputs DNS TXT data to the CLI console. * @@ -375,6 +391,8 @@ protected: void OutputIp6PrefixLine(const otIp6Prefix &aPrefix) { mOutput.OutputIp6PrefixLine(aPrefix); } void OutputIp6Prefix(const otIp6NetworkPrefix &aPrefix) { mOutput.OutputIp6Prefix(aPrefix); } void OutputIp6PrefixLine(const otIp6NetworkPrefix &aPrefix) { mOutput.OutputIp6PrefixLine(aPrefix); } + void OutputSockAddr(const otSockAddr &aSockAddr) { mOutput.OutputSockAddr(aSockAddr); } + void OutputSockAddrLine(const otSockAddr &aSockAddr) { mOutput.OutputSockAddrLine(aSockAddr); } void OutputDnsTxtData(const uint8_t *aTxtData, uint16_t aTxtDataLength) { mOutput.OutputDnsTxtData(aTxtData, aTxtDataLength); diff --git a/src/cli/cli_srp_client.cpp b/src/cli/cli_srp_client.cpp index 980e743ca..ea54a6264 100644 --- a/src/cli/cli_srp_client.cpp +++ b/src/cli/cli_srp_client.cpp @@ -285,10 +285,7 @@ otError SrpClient::ProcessServer(Arg aArgs[]) if (aArgs[0].IsEmpty()) { - char string[OT_IP6_SOCK_ADDR_STRING_SIZE]; - - otIp6SockAddrToString(serverSockAddr, string, sizeof(string)); - OutputLine(string); + OutputSockAddrLine(*serverSockAddr); ExitNow(); } diff --git a/src/cli/cli_tcp.cpp b/src/cli/cli_tcp.cpp index d16e63aca..d7802afb6 100644 --- a/src/cli/cli_tcp.cpp +++ b/src/cli/cli_tcp.cpp @@ -475,7 +475,7 @@ void TcpExample::HandleTcpDisconnected(otTcpEndpoint *aEndpoint, otTcpDisconnect mEndpointConnected = false; mSendBusy = false; - // Mark the benchmark as inactive if the connction was disconnected. + // Mark the benchmark as inactive if the connection was disconnected. if (mBenchmarkBytesTotal != 0) { mBenchmarkBytesTotal = 0; @@ -491,9 +491,9 @@ otTcpIncomingConnectionAction TcpExample::HandleTcpAcceptReady(otTcpListener * if (mEndpointConnected) { - OutputFormat("TCP: Ignoring incoming connection request from ["); - OutputIp6Address(aPeer->mAddress); - OutputLine("]:%u (active socket is busy)", static_cast(aPeer->mPort)); + OutputFormat("TCP: Ignoring incoming connection request from "); + OutputSockAddr(*aPeer); + OutputLine(" (active socket is busy)"); return OT_TCP_INCOMING_CONNECTION_ACTION_DEFER; } @@ -507,9 +507,8 @@ void TcpExample::HandleTcpAcceptDone(otTcpListener *aListener, otTcpEndpoint *aE OT_UNUSED_VARIABLE(aListener); OT_UNUSED_VARIABLE(aEndpoint); - OutputFormat("Accepted connection from ["); - OutputIp6Address(aPeer->mAddress); - OutputLine("]:%u", static_cast(aPeer->mPort)); + OutputFormat("Accepted connection from "); + OutputSockAddrLine(*aPeer); } } // namespace Cli