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:
parent
d6050d70a2
commit
3b8c97747d
@ -135,7 +135,7 @@ int netlib_setnodeaddr(FAR const char *ifname,
|
|||||||
FAR const struct pktradio_addr_s *nodeaddr);
|
FAR const struct pktradio_addr_s *nodeaddr);
|
||||||
int netlib_getnodnodeaddr(FAR const char *ifname,
|
int netlib_getnodnodeaddr(FAR const char *ifname,
|
||||||
FAR struct pktradio_addr_s *nodeaddr);
|
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);
|
FAR struct pktradio_addr_s *nodeaddr);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include "nuttx/wireless/pktradio.h"
|
#include "nuttx/wireless/pktradio.h"
|
||||||
#include "netutils/netlib.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
|
* nodeadd - Location to return the node address
|
||||||
*
|
*
|
||||||
* Return:
|
* 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)
|
FAR struct pktradio_addr_s *nodeaddr)
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(addrstr != NULL && nodeaddr != NULL);
|
DEBUGASSERT(addrstr != NULL && nodeaddr != NULL);
|
||||||
|
memset(nodeaddr, 0, sizeof(struct pktradio_addr_s));
|
||||||
|
|
||||||
/* FORM: xx:xx:...:xx */
|
/* FORM: xx:xx:...:xx */
|
||||||
|
|
||||||
@ -146,7 +148,8 @@ int netlib_nodeaddrconv(FAR const char *addrstr,
|
|||||||
ret = get_byte(addrstr, &byte);
|
ret = get_byte(addrstr, &byte);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
goto errout;
|
wlwarn("get_byte failed: %s\n", addrstr);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the byte */
|
/* Save the byte */
|
||||||
@ -173,20 +176,16 @@ int netlib_nodeaddrconv(FAR const char *addrstr,
|
|||||||
}
|
}
|
||||||
else if (*addrstr == '\0')
|
else if (*addrstr == '\0')
|
||||||
{
|
{
|
||||||
return OK;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
wlwarn("Unexpect delimiter: %s\n", addrstr);
|
||||||
goto errout;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -E2BIG;
|
return false;
|
||||||
|
|
||||||
errout:
|
|
||||||
errno = -ret;
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */
|
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */
|
||||||
|
@ -758,7 +758,7 @@ int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
|
|
||||||
if (argc != 2)
|
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");
|
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)
|
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");
|
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)
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
bool inet6 = false;
|
bool inet6 = false;
|
||||||
#endif
|
#endif
|
||||||
|
bool missingarg = true;
|
||||||
bool badarg = false;
|
bool badarg = false;
|
||||||
#ifdef HAVE_HWADDR
|
#ifdef HAVE_HWADDR
|
||||||
mac_addr_t macaddr;
|
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
|
/* If both the network interface name and an IP address are supplied as
|
||||||
* arguments, then ifconfig will set the address of the Ethernet device:
|
* 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)
|
if (argc > 2)
|
||||||
{
|
{
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
ifname = argv[i];
|
ifname = argv[i];
|
||||||
}
|
missingarg = false;
|
||||||
else if (i == 2)
|
|
||||||
{
|
|
||||||
hostip = argv[i];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = argv[i];
|
tmp = argv[i];
|
||||||
|
|
||||||
if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway"))
|
if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway"))
|
||||||
{
|
{
|
||||||
if (argc - 1 >= i + 1)
|
if (argc - 1 >= i + 1)
|
||||||
@ -944,16 +943,30 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else if (i == 2)
|
||||||
|
{
|
||||||
|
hostip = tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
badarg = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (badarg)
|
if (missingarg)
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (badarg)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_HWADDR
|
#ifdef HAVE_HWADDR
|
||||||
/* Set Hardware Ethernet MAC address */
|
/* Set Hardware Ethernet MAC address */
|
||||||
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
|
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user