[cli] add OutputSockAddr() method (#7121)

This commit is contained in:
Abtin Keshavarzian
2021-11-01 09:24:50 -07:00
committed by GitHub
parent ba08ed6f34
commit 60aa8b4fb9
6 changed files with 46 additions and 19 deletions
+2 -3
View File
@@ -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",
+4 -5
View File
@@ -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)
+15
View File
@@ -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;
+18
View File
@@ -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);
+1 -4
View File
@@ -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();
}
+6 -7
View File
@@ -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<unsigned int>(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<unsigned int>(aPeer->mPort));
OutputFormat("Accepted connection from ");
OutputSockAddrLine(*aPeer);
}
} // namespace Cli