netutils/netlib: Fix netlib_nodaddrconv() so that its return type is the same as other address conversion functions. NSH: Correct parsing of ifconfig so that you can specify the HW address without specifying the IP address.

This commit is contained in:
Gregory Nutt 2017-08-02 14:30:34 -06:00
parent d6050d70a2
commit 3b8c97747d
3 changed files with 35 additions and 23 deletions

View File

@ -135,7 +135,7 @@ 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,
bool netlib_nodeaddrconv(FAR const char *addrstr,
FAR struct pktradio_addr_s *nodeaddr);
#endif
#endif

View File

@ -47,6 +47,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#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,
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 */

View File

@ -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? */