cmd_arp: add device input for arp interface

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2022-12-06 13:42:15 +08:00
committed by Xiang Xiao
parent 11f0c2af43
commit df3121213e
7 changed files with 105 additions and 44 deletions

View File

@@ -53,6 +53,7 @@
* Parameters:
* inaddr The IPv4 address to use in the mapping
* macaddr The Ethernet MAC address to use in the mapping
* ifname The Network device name
*
* Return:
* 0 on success; a negated errno value on failure.
@@ -60,7 +61,7 @@
****************************************************************************/
int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr,
FAR const uint8_t *macaddr)
FAR const uint8_t *macaddr, FAR const char *ifname)
{
int ret = -EINVAL;
@@ -75,6 +76,15 @@ int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr,
req.arp_ha.sa_family = ARPHRD_ETHER;
memcpy(&req.arp_ha.sa_data, macaddr, ETHER_ADDR_LEN);
if (ifname != NULL)
{
strlcpy((FAR char *)&req.arp_dev, ifname,
sizeof(req.arp_dev));
}
else
{
req.arp_dev[0] = '\0';
}
ret = ioctl(sockfd, SIOCSARP, (unsigned long)((uintptr_t)&req));
if (ret < 0)