1

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.

Thomas
  • 4,208
  • 2
  • 29
  • 31

3 Answers3

2
#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
  • 13,974
  • 3
  • 42
  • 42
1

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

phoebus
  • 14,673
  • 2
  • 33
  • 35
  • 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 Sep 29 '09 at 06:40
0

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

qrdl
  • 34,062
  • 14
  • 56
  • 86
  • 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 Sep 29 '09 at 06:40
  • Did you check possible ioctl() request in ioctl headers? – qrdl Sep 29 '09 at 07:09