views:

210

answers:

3

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.

+1  A: 

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

phoebus
I'd prefer not to shell out, but at least it works. Thanks. Does this mean that all network cards have the same MAC address?
Thomas
A: 

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

qrdl
Yeah, I'm looking for something a bit more specific than that. I've looked at ioctl() and sysctl() already, but nothing sticks out to me.
Thomas
Did you check possible ioctl() request in ioctl headers?
qrdl
+2  A: 
#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.

WhirlWind
Success (ifdat.enaddr). I hereby crown you king of IRIX. Thank you.
Thomas