getting MAC address from network card

I can’t seem to get the below code to work. Any suggestions?
How do I print out the nicconfig.permanent_address[] variable?

int main()
{
nic_config_t nicconfig;
int fd,i;
char mac[10];
fd=open("/dev/io-net/en0,",O_RDONLY);
devctl(fd, DCMD_IO_NET_GET_CONFIG, &nicconfig, sizeof(nicconfig), NULL);
printf(“Device id=\n”);
for (i=0;i<8;i++)
{
printf("%x\n",nicconfig.permanent_address[i]);
}
printf("\n");
return 1;
}

/////////////////////////////////////
I also tried using this function but it always fails to print the mac and goes
to “failed”

 char mac[10];
 if (!nic_get_syspage_mac(mac))
printf("%s\n",mac);
 else
printf("failed\n");

thanks

i do not even have the nic_config_t anywhere. I guess there is the advanced networking package necessary?

So i actually found nic_info_t, but fd seems to be -1, so open fails on /dev/io-net/en0

Reading carefully points out:

fd=open("/dev/io-net/en0,",O_RDONLY);

should be:

fd=open("/dev/io-net/en0",O_RDONLY);

now I feel embarrassed :blush:
But then why doesn’t the nic_get_syspage_mac work?

The nic_get_syspage_mac will only work, if someone (that’d be you :slight_smile: added the mac into the syspage :slight_smile:

If you didn’t do that, then it won’t be there.

The purpose of this, is for embedded devices where the embedded ethernet mac, does not come with a ROM with a mac address on it. The embedded developer is supposed to figure out (in the startup) what the mac addr is and then write it into the syspage. The driver will then read the mac from the syspage (usually there is a “syspage” option to the driver to tell it to do this).

I see, I thought all other drivers also wrote to the syspage. So then, when I run the nicinfo or pci -v util, where does it get its information from not from syspage??