getting interface MAC addr from C

Mario Lobo mario.lobo at ipad.com.br
Fri Aug 4 10:55:12 UTC 2006


Hi;

Would anyone have a tip on how to get the MAC from a C program?

I tried:

    struct ifreq ifreq;
    unsigned char *hw;

    strcpy(ifreq.ifr_name, "rl0");
    ioctl(fd, SIOCGIFMAC, &ifreq);
    hw = ifreq.ifr_ifru.ifru_data; ????

but i don't know if this is right or, if it is, where to get the MAC from the 
structure. I doesn't issue any error compiling or running though.

In linux i used:

    struct ifreq ifreq;
    unsigned char *hw;

    strcpy(ifreq.ifr_name, "rl0");
    ioctl(fd, SIOCGIFHWADDR, &ifreq);
    hw = ifreq.ifr_hwaddr.sa_data;

Thanks,

Mario


More information about the freebsd-hackers mailing list