net: Fix sa_family returned by SIOCGIFHWADDR

* net/netdev/netdev_ioctl.c:
  (netdev_ifr_ioctl): The ioctl SIOCGIFHWADDR provides the hardware
   address (e.g., Ethernet MAC, etc.) of a network interface. It is
   based on Linux. (BSD-based systems don't have this ioctl.) The Linux
   implementation sets sa_family to ARPHRD_ETHER for Ethernet and IEEE
   802.11 interfaces [1]. NuttX was setting it to NET_SOCK_FAMILY for
   these interface types as well as 6LoWPAN and PKTRADIO; this was
   incorrect and also the value of NET_SOCK_FAMILY varies based on
   Kconfig settings. Correcting this to ARPHRD_ETHER for Ethernet and
   IEEE 802.11 and ARPHRD_IEEE802154 for 6LoWPAN and PKTRADIO.

References:
[1] 'man 7 netdevice' on Linux.
This commit is contained in:
Nathan Hartman 2022-09-15 10:36:47 -04:00 committed by Xiang Xiao
parent 6c4bd5c5ef
commit d09304008e

View File

@ -901,7 +901,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
if (dev->d_lltype == NET_LL_ETHERNET ||
dev->d_lltype == NET_LL_IEEE80211)
{
req->ifr_hwaddr.sa_family = NET_SOCK_FAMILY;
req->ifr_hwaddr.sa_family = ARPHRD_ETHER;
memcpy(req->ifr_hwaddr.sa_data,
dev->d_mac.ether.ether_addr_octet, IFHWADDRLEN);
}
@ -911,7 +911,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
if (dev->d_lltype == NET_LL_IEEE802154 ||
dev->d_lltype == NET_LL_PKTRADIO)
{
req->ifr_hwaddr.sa_family = NET_SOCK_FAMILY;
req->ifr_hwaddr.sa_family = ARPHRD_IEEE802154;
memcpy(req->ifr_hwaddr.sa_data,
dev->d_mac.radio.nv_addr,
dev->d_mac.radio.nv_addrlen);