Search code examples
cunixirix

How do I find the MAC address programatically on IRIX?


How do I find the MAC address of a network card on IRIX? I'd rather not shell out to something that displays it and parse the output.

I'm coding C.

Methods that require root access are acceptable.


Solution

  • #include <net/raw.h>
    #include <net/if.h>
    #include <net/soioctl.h> 
    #include <sys/ioctl.h> 
    #include <sys/types.h> 
    #include <sys/socket.h>
    #include <unistd.h>
    
    ...
    
    struct ifreq ifdat;
    int s;
    
    s = socket (PF_RAW, SOCK_RAW, RAWPROTO_SNOOP);
    strcpy (ifdat.ifr_name, "en0");
    ioctl (s, SIOCGIFADDR, &ifdat);
    
    ...
    

    Clean it up a little, and ifdat should contain your MAC address.