You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Nathan Hartman <ha...@gmail.com> on 2022/09/15 03:30:54 UTC

Bug - SIOCGIFHWADDR?

SIOCGIFHWADDR gets the MAC address of an Ethernet interface.

E.g., something like this works on Linux:

  strcpy(req.ifr_name, dev_name);
  ret = ioctl(tmpsock, SIOCGIFHWADDR, &req);
  if ((ret >= 0) && (req.ifr_hwaddr.sa_family == ARPHRD_ETHER))
    {
      memcpy((void *) mac_addr, (const void *) req.ifr_hwaddr.sa_data,
IFHWADDRLEN);
    }

Notice that sa_family is ARPHRD_ETHER. This tells the code above that
sa_data contains a 6-byte Ethernet MAC.

In NuttX, SIOCGIFHWADDR is implemented in netdev_ifr_ioctl(). See
net/netdev/netdev_ioctl.c, line 904, is setting sa_family to
NET_SOCK_FAMILY, not ARPHRD_ETHER.

I think that's a mistake?

It should be ARPHRD_ETHER?

And if so, then line 914 is wrong also?

Thanks,
Nathan