You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/15 18:59:57 UTC

[incubator-nuttx] branch master updated: net: Fix sa_family returned by SIOCGIFHWADDR

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new d09304008e net: Fix sa_family returned by SIOCGIFHWADDR
d09304008e is described below

commit d09304008ee2d5d06a656e584c7bcb97dc1037b4
Author: Nathan Hartman <59...@users.noreply.github.com>
AuthorDate: Thu Sep 15 10:36:47 2022 -0400

    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);