Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!paladin.american.edu!gatech!newsfeed.internetmci.com!in2.uu.net!olivea!samba.rahul.net!rahul.net!a2i!hustle.rahul.net!rahul.net!a2i!squirrel.com!ratatosk!mch From: mch@squirrel.com (Mark Henderson) Newsgroups: comp.unix.questions,comp.unix.bsd,comp.unix.internals,comp.sys.sun.apps,alt.unix.wizards,can.sun-stroke,alt.sys.sun Subject: Re: Interface MAC address SunOS 4.1.3 Date: 16 Mar 1996 06:21:36 GMT Organization: RATATOSK Lines: 76 Message-ID: <4idmlg$6nl@hustle.rahul.net> References: <4ia1rs$1j1@sol.sun.csd.unb.ca> <p4trqukut.fsf@lpbcsun.lpbc.jussieu.fr> <DoC1x4.A7x@mail.auburn.edu> NNTP-Posting-Host: squirrel.com Xref: euryale.cc.adfa.oz.au comp.unix.questions:78968 comp.unix.bsd:16773 comp.unix.internals:9925 comp.sys.sun.apps:12818 alt.unix.wizards:3355 alt.sys.sun:10114 In article <DoC1x4.A7x@mail.auburn.edu>, Doug Hughes <doug@eng.auburn.edu> wrote: >Luckily, on Suns, there is only 1 MAC for all ethernets. The mac is >stored in nvram on the motherboard, so you don't have to worry about this. >(or unluckily, depending on your point of view) Well, this is usually true. The default MAC address for every ethernet interface is stored in NVRAM. If you don't specify an ethernet address when initialising the interface, you get the default. However, you can change the default MAC address for an interface with ifconfig or just specify any ethernet address you want in your startup files. e.g. ratatosk# ifconfig le0 ether 8:0:20:1:2:3 ratatosk# ifconfig le0 le0: flags=63<UP,BROADCAST,NOTRAILERS,RUNNING> inet 192.168.7.1 netmask ffffff00 broadcast 192.168.7.0 ether 8:0:20:1:2:3 If you are content to get the default ethernet address out of the NVRAM, then you can do this via the openprom driver. For an example see getobphostid.c in my change-sun-hostid package available from: ftp://ftp.netcom.com/pub/he/henderso/change-sun-hostid.tar.gz ftp://ftp.wimsey.com/pub/crypto/sun-stuff/change-sun-hostid.tar.gz http://www.squirrel.com/squirrel/sun-stuff/change-sun-hostid.tar.gz On the other hand, if you really want the real current MAC address of le0 (for example), the following should do under Sun OS 4.1.x. N.B. This code must be run as root #include <fcntl.h> #include <stdio.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> #include <sys/time.h> #include <net/nit_if.h> main() { struct ifreq foo; int i, j; if ((i = open("/dev/nit", O_RDONLY)) < 0) { fprintf(stderr, "cannot open /dev/nit\n"); exit(1); } strcpy(foo.ifr_name, "le0"); foo.ifr_addr.sa_family = AF_NIT; if (ioctl(i, NIOCBIND, &foo) < 0) { fprintf(stderr, "NIOCBIND failed\n"); exit(1); } if (ioctl(i, SIOCGIFADDR, &foo) < 0) { fprintf(stderr, "SIOCGIFADDR failed\n"); exit(1); } for (j = 0; j < 6; j++) printf("%02x ", foo.ifr_addr.sa_data[j]); printf("\n"); } e.g. the output on the machine I just executed the above ifconfig commands on is: 08 00 20 01 02 03 -- Mark Henderson -- markh@wimsey.bc.ca, mch@squirrel.com, henderso@netcom.com ViaCrypt PGP Key Fingerprint: 21 F6 AF 2B 6A 8A 0B E1 A1 2A 2A 06 4A D5 92 46 unstrip for Solaris, Wimsey cryptography archive, Wimsey TECO archive, change-sun-hostid, Sun NVRAM/hostid FAQ - http://www.squirrel.com/squirrel