Finding ethernet addresses

Kemp at dockmaster.ncsc.mil Kemp at dockmaster.ncsc.mil
Wed May 3 19:14:25 AEST 1989


Dan Ehrlich <ehrlich at shire.cs.psu.edu> writes:  Does anyone know how to
determine the ethernet address of the second ethernet interface on a Sun?

There is a program in the Sun Software Technical Bulletin (November 1988,
page 2202) that does exactly that, using /dev/nit.  The code is 1 1/2
pages, but the relevant lines are (omitting error checking):

 #include <net/if.h>
 #include <net/nit_if.h>
 struct ifreq if_data;

 sfd = open("/dev/nit", O_RDONLY);
 if_data.ifr_addr.sa_family = AF_NIT;
 strcpy(if_data.ifr_name, argv[1]);l      /* the interface name */
 ioctl(sfd, NIOCBIND, &if_data);
 ioctl(sfd, SIOCGIFADDR, &if_data);      /* Get the ethernet addr */
    /*   print if_data.ifr_addr.sa_data[0:5]  */

I typed the program in and it works.  If you don't get the STB, the
above should be enough to get you pointed in the right direction.

   Dave Kemp <Kemp at dockmaster.ncsc.mil>



More information about the Comp.sys.sun mailing list