From d09304008ee2d5d06a656e584c7bcb97dc1037b4 Mon Sep 17 00:00:00 2001 From: Nathan Hartman <59230071+hartmannathan@users.noreply.github.com> Date: Thu, 15 Sep 2022 10:36:47 -0400 Subject: [PATCH] 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. --- net/netdev/netdev_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index a6facbe41f..ef253c5ea5 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -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);