summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_netcmds.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-06 10:23:15 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-06 10:23:15 -0600
commitca99c2ef4dd63e344d4a4afb6a47bfcb379be0c6 (patch)
tree42201d76da159e7304f18ea1379165fbea5267b8 /apps/nshlib/nsh_netcmds.c
parent98fc285af45d3ef84bb70aa9f967d406c71eebbe (diff)
downloadpx4-nuttx-ca99c2ef4dd63e344d4a4afb6a47bfcb379be0c6.tar.gz
px4-nuttx-ca99c2ef4dd63e344d4a4afb6a47bfcb379be0c6.tar.bz2
px4-nuttx-ca99c2ef4dd63e344d4a4afb6a47bfcb379be0c6.zip
apps/netutils/netlib: Add utilities to convert to/from prefix lengths from/to 128-bit network masks. Modify the NSH IPv6 ifconfig command to show the network mask in a more standard, human readable way.
Diffstat (limited to 'apps/nshlib/nsh_netcmds.c')
-rw-r--r--apps/nshlib/nsh_netcmds.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c
index 5d4195cb3..bda6012e8 100644
--- a/apps/nshlib/nsh_netcmds.c
+++ b/apps/nshlib/nsh_netcmds.c
@@ -469,6 +469,7 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
#endif
#ifdef CONFIG_NET_IPv6
char addrstr[INET6_ADDRSTRLEN];
+ uint8_t preflen;
#endif
uint8_t iff;
const char *status;
@@ -504,12 +505,18 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
#endif
#ifdef CONFIG_NET_IPv4
+ /* Show the IPv4 address */
+
addr.s_addr = dev->d_ipaddr;
nsh_output(vtbl, "\tinet addr:%s ", inet_ntoa(addr));
+ /* Show the IPv4 default router address */
+
addr.s_addr = dev->d_draddr;
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
+ /* Show the IPv4 network mask */
+
addr.s_addr = dev->d_netmask;
nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr));
@@ -520,22 +527,25 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
#endif
#ifdef CONFIG_NET_IPv6
+ /* Convert the 128 network mask to a human friendly prefix length */
+
+ preflen = netlib_ipv6netmask2prefix(dev->d_ipv6netmask);
+
+ /* Show the assigned IPv6 address */
+
if (inet_ntop(AF_INET6, dev->d_ipv6addr, addrstr, INET6_ADDRSTRLEN))
{
- nsh_output(vtbl, "\tinet6 addr:%s\n", addrstr);
+ nsh_output(vtbl, "\tinet6 addr:%s/%d\n", addrstr, preflen);
}
- if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
- {
- nsh_output(vtbl, "\tinet6 DRaddr:%s\n", addrstr);
- }
+ /* REVISIT: Show the IPv6 default router address */
- if (inet_ntop(AF_INET6, dev->d_ipv6netmask, addrstr, INET6_ADDRSTRLEN))
+ if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
{
- nsh_output(vtbl, "\tinet6 Mask:%s\n", addrstr);
+ nsh_output(vtbl, "\tinet6 DRaddr:%s/%d\n", addrstr, preflen);
}
-#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+#if defined(CONFIG_NSH_DHCPCv6) || defined(CONFIG_NSH_DNS)
# warning Missing logic
#endif
#endif