[cli] add option to print more information for ipaddress (#7245)

This commit is contained in:
Zhangwx
2021-12-29 10:14:32 -08:00
committed by GitHub
parent be8383bc5a
commit 8b7d90f167
2 changed files with 36 additions and 2 deletions
+10
View File
@@ -1279,6 +1279,16 @@ fe80:0:0:0:f3d9:2a82:c8d8:fe43
Done
```
Use `-v` to get more verbose informations about the address.
```bash
> ipaddr -v
fdde:ad00:beef:0:0:ff:fe00:0 origin:thread
fdde:ad00:beef:0:558:f56b:d688:799 origin:thread
fe80:0:0:0:f3d9:2a82:c8d8:fe43 origin:thread
Done
```
### ipaddr add \<ipaddr\>
Add an IPv6 address to the Thread interface.
+26 -2
View File
@@ -2056,9 +2056,28 @@ exit:
return error;
}
const char *AddressOriginToString(uint8_t aOrigin)
{
static const char *const kOriginStrings[4] = {
"thread", // 0, OT_ADDRESS_ORIGIN_THREAD
"slaac", // 1, OT_ADDRESS_ORIGIN_SLAAC
"dhcp6", // 2, OT_ADDRESS_ORIGIN_DHCPV6
"manual", // 3, OT_ADDRESS_ORIGIN_MANUAL
};
return aOrigin < OT_ARRAY_LENGTH(kOriginStrings) ? kOriginStrings[aOrigin] : "unknown";
}
otError Interpreter::ProcessIpAddr(Arg aArgs[])
{
otError error = OT_ERROR_NONE;
otError error = OT_ERROR_NONE;
bool verbose = false;
if (aArgs[0] == "-v")
{
aArgs++;
verbose = true;
}
if (aArgs[0].IsEmpty())
{
@@ -2066,7 +2085,12 @@ otError Interpreter::ProcessIpAddr(Arg aArgs[])
for (const otNetifAddress *addr = unicastAddrs; addr; addr = addr->mNext)
{
OutputIp6AddressLine(addr->mAddress);
OutputIp6Address(addr->mAddress);
if (verbose)
{
OutputFormat(" origin:%s", AddressOriginToString(addr->mAddressOrigin));
}
OutputLine("");
}
}
else