diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index 41cc7a01e..f6e52ba13 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -135,8 +135,8 @@ int netlib_setnodeaddr(FAR const char *ifname, FAR const struct pktradio_addr_s *nodeaddr); int netlib_getnodnodeaddr(FAR const char *ifname, FAR struct pktradio_addr_s *nodeaddr); -int netlib_nodeaddrconv(FAR const char *addrstr, - FAR struct pktradio_addr_s *nodeaddr); +bool netlib_nodeaddrconv(FAR const char *addrstr, + FAR struct pktradio_addr_s *nodeaddr); #endif #endif diff --git a/netutils/netlib/netlib_nodeaddrconv.c b/netutils/netlib/netlib_nodeaddrconv.c index 1bff6f00a..2770585fa 100644 --- a/netutils/netlib/netlib_nodeaddrconv.c +++ b/netutils/netlib/netlib_nodeaddrconv.c @@ -47,6 +47,7 @@ #include #include #include +#include #include "nuttx/wireless/pktradio.h" #include "netutils/netlib.h" @@ -116,17 +117,18 @@ static int get_byte(FAR const char *ptr, FAR uint8_t *byte) * nodeadd - Location to return the node address * * Return: - * 0 on success; -1 on failure. errno will be set on failure. + * true on success; false on failure. * ****************************************************************************/ -int netlib_nodeaddrconv(FAR const char *addrstr, - FAR struct pktradio_addr_s *nodeaddr) +bool netlib_nodeaddrconv(FAR const char *addrstr, + FAR struct pktradio_addr_s *nodeaddr) { uint8_t byte; int ret; DEBUGASSERT(addrstr != NULL && nodeaddr != NULL); + memset(nodeaddr, 0, sizeof(struct pktradio_addr_s)); /* FORM: xx:xx:...:xx */ @@ -146,7 +148,8 @@ int netlib_nodeaddrconv(FAR const char *addrstr, ret = get_byte(addrstr, &byte); if (ret < 0) { - goto errout; + wlwarn("get_byte failed: %s\n", addrstr); + return false; } /* Save the byte */ @@ -173,20 +176,16 @@ int netlib_nodeaddrconv(FAR const char *addrstr, } else if (*addrstr == '\0') { - return OK; + return true; } else { - ret = -EINVAL; - goto errout; + wlwarn("Unexpect delimiter: %s\n", addrstr); + break; } } - ret = -E2BIG; - -errout: - errno = -ret; - return ERROR; + return false; } #endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 80efb4c07..3d20116de 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -758,7 +758,7 @@ int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) if (argc != 2) { - nsh_output(vtbl, "Please select nic_name:\n"); + nsh_output(vtbl, "Please select ifname:\n"); return nsh_foreach_netdev(ifconfig_callback, vtbl, "ifup"); } @@ -781,7 +781,7 @@ int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) if (argc != 2) { - nsh_output(vtbl, "Please select nic_name:\n"); + nsh_output(vtbl, "Please select ifname:\n"); return nsh_foreach_netdev(ifconfig_callback, vtbl, "ifdown"); } @@ -821,6 +821,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) bool inet6 = false; #endif + bool missingarg = true; bool badarg = false; #ifdef HAVE_HWADDR mac_addr_t macaddr; @@ -852,24 +853,22 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* If both the network interface name and an IP address are supplied as * arguments, then ifconfig will set the address of the Ethernet device: * - * ifconfig nic_name ip_address + * ifconfig ifname [ip_address] [named options] */ if (argc > 2) { - for (i = 0; i < argc; i++) + for (i = 1; i < argc; i++) { if (i == 1) { ifname = argv[i]; - } - else if (i == 2) - { - hostip = argv[i]; + missingarg = false; } else { tmp = argv[i]; + if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway")) { if (argc - 1 >= i + 1) @@ -944,16 +943,30 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } } #endif + else if (i == 2) + { + hostip = tmp; + } + else + { + badarg = true; + } } } } - if (badarg) + if (missingarg) { nsh_output(vtbl, g_fmtargrequired, argv[0]); return ERROR; } + if (badarg) + { + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + return ERROR; + } + #ifdef HAVE_HWADDR /* Set Hardware Ethernet MAC address */ /* REVISIT: How will we handle Ethernet and SLIP networks together? */