On 20/10/2020 18:50, Steve Blinkhorn wrote:
Is there any way to access the MAC addresses of network interface
devices programmatically?

Call getifaddrs(3) and find the interface by ifa_name and family by ifa_addr->sa_family == AF_LINK.
You can then cast ifa_addr to sockaddr_dl.
Use CLLADDR to access the MAC address inside sockaddr_dl like so

memcpy(mac, CLLADDR(sdl), sdl->sdl_alen);

You can find an example here:
http://anonhg.netbsd.org/src/file/ROY/external/bsd/dhcpcd/dist/src/if.c#l574

Roy

Reply via email to