tags:

views:

86

answers:

1

I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on IOKit/assert.h . Which doesn't seem to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress. Is assert.h necessary for my task? It would be great if someone coud give me a working sample. [edit] here's my code, think this will help understanding the problem:

#include <IOKit/assert.h>
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>

int main(){
    IOEthernetAddress addr;
    getHardwareAddress(&addr);
    printf("%x", addr);
    return 0;
}
A: 

You must be trying to do this from userspace; you wouldn't be using main() if you were writing for the kernel. however, these are kernel include files. One way to do this from userspace is to look at the I/O registry, and find the IOMACAddress for the piece of hardware that interests you. To get started with this, take a look at I/O Registry Explorer.

Another way is to use ioctl with SIOCSIFLLADDR, to get the link level address.

WhirlWind