NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: MAC addresses

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:


Home | Main Index | Thread Index | Old Index