summaryrefslogtreecommitdiffstats
path: root/apps/nshlib
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-19 09:59:43 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-19 09:59:43 -0600
commitbc4563d93ea4df6cffa4a3c0cec4aa2d3f8b379d (patch)
treeb1b1c971aab196cecd03501a360c37e91ffed4f4 /apps/nshlib
parentb48ca16de31149e173b1a7ae71b7f5504dd2a9d8 (diff)
apps/nshlib: Add logic to initialize IPv6 addresses, to display IPv6 addresses, and enough IPv6 ifconfig to allocation compilation (logic still not implemented)
Diffstat (limited to 'apps/nshlib')
-rw-r--r--apps/nshlib/nsh_netcmds.c211
-rw-r--r--apps/nshlib/nsh_netinit.c2
2 files changed, 170 insertions, 43 deletions
diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c
index 4c99fac637..e9315c4b51 100644
--- a/apps/nshlib/nsh_netcmds.c
+++ b/apps/nshlib/nsh_netcmds.c
@@ -280,7 +280,12 @@ static inline void net_statistics(FAR struct nsh_vtbl_s *vtbl)
int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
{
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
+#ifdef CONFIG_NET_IPv4
struct in_addr addr;
+#endif
+#ifdef CONFIG_NET_IPv6
+ char addrstr[INET6_ADDRSTRLEN];
+#endif
uint8_t iff;
const char *status;
int ret;
@@ -305,15 +310,18 @@ int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
status = "DOWN";
}
-#ifdef CONFIG_NET_ETHERNET
+#if defined(CONFIG_NET_ETHERNET)
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
- nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
+ nsh_output(vtbl, "%s\tLink encap: Ethernet HWaddr %s at %s\n",
dev->d_ifname, ether_ntoa(&dev->d_mac), status);
+#elif defined(CONFIG_NET_SLIP)
+ nsh_output(vtbl, "%s\tLink encap:SLIP\n");
#endif
+#ifdef CONFIG_NET_IPv4
addr.s_addr = dev->d_ipaddr;
- nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));
+ nsh_output(vtbl, "\tinet addr:%s ", inet_ntoa(addr));
addr.s_addr = dev->d_draddr;
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
@@ -325,6 +333,28 @@ int ifconfig_callback(FAR struct net_driver_s *dev, void *arg)
dns_getserver(&addr);
nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr));
#endif
+#endif
+
+#ifdef CONFIG_NET_IPv6
+ if (inet_ntop(AF_INET6, dev->d_ipv6addr, addrstr, INET6_ADDRSTRLEN))
+ {
+ nsh_output(vtbl, "\tinet6 addr:%s\n", addrstr);
+ }
+
+ if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
+ {
+ nsh_output(vtbl, "\tinet6 DRaddr:%s\n", addrstr);
+ }
+
+ if (inet_ntop(AF_INET6, dev->d_ipv6netmask, addrstr, INET6_ADDRSTRLEN))
+ {
+ nsh_output(vtbl, "\tinet6 Mask:%s\n", addrstr);
+ }
+
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+# warning Missing logic
+#endif
+#endif
nsh_output(vtbl, "\n");
return OK;
@@ -582,7 +612,12 @@ int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#ifndef CONFIG_NSH_DISABLE_IFCONFIG
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
+#ifdef CONFIG_NET_IPv4
struct in_addr addr;
+#endif
+#ifdef CONFIG_NET_IPv6
+ struct in6_addr addr6;
+#endif
in_addr_t gip;
int i;
FAR char *intf = NULL;
@@ -596,13 +631,16 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
FAR char *dns = NULL;
#endif
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+ bool inet6 = false;
+#endif
bool badarg = false;
uint8_t mac[IFHWADDRLEN];
#if defined(CONFIG_NSH_DHCPC)
FAR void *handle;
#endif
- /* With one or no arguments, ifconfig simply shows the status of ethernet
+ /* With one or no arguments, ifconfig simply shows the status of Ethernet
* device:
*
* ifconfig
@@ -661,6 +699,22 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
badarg = true;
}
}
+ else if (!strcmp(tmp, "inet"))
+ {
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+ inet6 = false;
+#elif !defined(CONFIG_NET_IPv4)
+ badarg = true;
+#endif
+ }
+ else if (!strcmp(tmp, "inet6"))
+ {
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+ inet6 = true;
+#elif !defined(CONFIG_NET_IPv6)
+ badarg = true;
+#endif
+ }
#ifdef CONFIG_NET_ETHERNET
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
@@ -715,77 +769,148 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
#endif
-#if defined(CONFIG_NSH_DHCPC)
- if (!strcmp(hostip, "dhcp"))
- {
- /* Set DHCP addr */
+ /* Set IP address */
- ndbg("DHCPC Mode\n");
- gip = addr.s_addr = 0;
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ if (inet6)
+#endif
+ {
+#warning Missing Logic
+ UNUSED(addr6);
+ UNUSED(gip);
+ UNUSED(hostip);
}
+#endif /* CONFIG_NET_IPv6 */
+
+#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv6
else
#endif
{
- /* Set host IP address */
+#if defined(CONFIG_NSH_DHCPC)
+ if (!strcmp(hostip, "dhcp"))
+ {
+ /* Set DHCP addr */
- ndbg("Host IP: %s\n", hostip);
- gip = addr.s_addr = inet_addr(hostip);
- }
+ ndbg("DHCPC Mode\n");
+ gip = addr.s_addr = 0;
+ }
+ else
+#endif
+ {
+ /* Set host IP address */
- netlib_set_ipv4addr(intf, &addr);
+ ndbg("Host IP: %s\n", hostip);
+ gip = addr.s_addr = inet_addr(hostip);
+ }
- /* Set gateway */
+ netlib_set_ipv4addr(intf, &addr);
+ }
+#endif /* CONFIG_NET_IPv4 */
- if (gwip)
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ if (inet6)
+#endif
{
- ndbg("Gateway: %s\n", gwip);
- gip = addr.s_addr = inet_addr(gwip);
+#warning Missing Logic
+ UNUSED(gwip);
}
+#endif /* CONFIG_NET_IPv6 */
+
+#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv6
else
+#endif
{
- if (gip)
+ /* Set gateway */
+
+ if (gwip)
{
- ndbg("Gateway: default\n");
- gip = NTOHL(gip);
- gip &= ~0x000000ff;
- gip |= 0x00000001;
- gip = HTONL(gip);
+ ndbg("Gateway: %s\n", gwip);
+ gip = addr.s_addr = inet_addr(gwip);
}
+ else
+ {
+ if (gip)
+ {
+ ndbg("Gateway: default\n");
+ gip = NTOHL(gip);
+ gip &= ~0x000000ff;
+ gip |= 0x00000001;
+ gip = HTONL(gip);
+ }
- addr.s_addr = gip;
- }
+ addr.s_addr = gip;
+ }
- netlib_set_dripv4addr(intf, &addr);
+ netlib_set_dripv4addr(intf, &addr);
+ }
+#endif /* CONFIG_NET_IPv4 */
/* Set network mask */
- if (mask)
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ if (inet6)
+#endif
{
- ndbg("Netmask: %s\n",mask);
- addr.s_addr = inet_addr(mask);
+#warning Missing Logic
+ UNUSED(mask);
}
+#endif /* CONFIG_NET_IPv6 */
+
+#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv6
else
+#endif
{
- ndbg("Netmask: Default\n");
- addr.s_addr = inet_addr("255.255.255.0");
- }
+ if (mask)
+ {
+ ndbg("Netmask: %s\n",mask);
+ addr.s_addr = inet_addr(mask);
+ }
+ else
+ {
+ ndbg("Netmask: Default\n");
+ addr.s_addr = inet_addr("255.255.255.0");
+ }
- netlib_set_ipv4netmask(intf, &addr);
+ netlib_set_ipv4netmask(intf, &addr);
+ }
+#endif /* CONFIG_NET_IPv4 */
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
- if (dns)
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ if (inet6)
+#endif
{
- ndbg("DNS: %s\n", dns);
- addr.s_addr = inet_addr(dns);
+#warning Missing Logic
}
+#endif /* CONFIG_NET_IPv6 */
+
+#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv6
else
+#endif
{
- ndbg("DNS: Default\n");
- addr.s_addr = gip;
- }
+ if (dns)
+ {
+ ndbg("DNS: %s\n", dns);
+ addr.s_addr = inet_addr(dns);
+ }
+ else
+ {
+ ndbg("DNS: Default\n");
+ addr.s_addr = gip;
+ }
- dns_setserver(&addr);
-#endif
+ dns_setserver(&addr);
+ }
+#endif /* CONFIG_NET_IPv4 */
+#endif /* CONFIG_NSH_DHCPC || CONFIG_NSH_DNS */
#if defined(CONFIG_NSH_DHCPC)
/* Get the MAC address of the NIC */
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c
index 6b4e3daeb7..ed42bb9ba4 100644
--- a/apps/nshlib/nsh_netinit.c
+++ b/apps/nshlib/nsh_netinit.c
@@ -200,7 +200,9 @@ static const uint16_t g_ipv6_netmask[8] =
static void nsh_netinit_configure(void)
{
+#ifdef CONFIG_NET_IPv4
struct in_addr addr;
+#endif
#if defined(CONFIG_NSH_DHCPC)
FAR void *handle;
#endif