Subject: Re: get MAC address
To: None <>
From: Ben Harris <>
List: tech-userlevel
Date: 05/18/2003 15:30:10
In article <> 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
        address: 00:00:a4:10:7a:97
        media: Ethernet 10baseT
        status: active
        inet netmask 0xffffff00 broadcast

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