Subject: Re: get MAC address
To: None <email@example.com>
From: Ben Harris <firstname.lastname@example.org>
Date: 05/18/2003 15:30:10
In article <email@example.com> you write:
>Is there a portable way to learn the Ethernet address of a device?
>I see the kernel spit it out at configuration time. I don't know any
>other way to display it.
You can always use ifconfig:
fastnet:~$ ifconfig ne0
ne0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
media: Ethernet 10baseT
inet 172.17.11.29 netmask 0xffffff00 broadcast 172.17.11.255
The first address listed there is the MAC address for Ethernet devices.
>One of my compatriots wrote an ioctl query for Linux that uses flags (e.g.
>SIOCGIFHWADDR) that we don't support, leading me to wonder if there wasn't
>a higher level interface.
I _think_ that getifaddrs() should return it as an AF_LINK address, along
with all the other addresses for each interface. Alternatively, it looks
like SIOCGIFADDR might do what you want, at least if you call it on a
PF_LINK socket. See networking(4) for (too few) details.