Subject: Re: get MAC address
To: None <jklowden@schemamania.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 05/18/2003 15:30:10
In article <20030518090038.780d7d26.jklowden@schemamania.org> 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
address: 00:00:a4:10:7a:97
media: Ethernet 10baseT
status: active
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.
--
Ben Harris