How do I find the MAC address programatically on IRIX?

741 Views Asked by At

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.

3

There are 3 best solutions below

1
On BEST ANSWER
#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.

1
On

I don't know about programmatically, but you could try /etc/nvram eaddr, I suppose you could exec() that.

2
On

On some platforms (Linux, for example) ioctl() allows to obtain MAC address. You need to check on IRIX as ioctl() is platform-dependent.