From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,51fa14f1a24833b7 X-Google-Attributes: gidfee84,public From: jude@tsi.com.my Subject: Re: Ethernet Address Date: 1997/06/12 Message-ID: <866167750.6750@dejanews.com> X-Deja-AN: 248020251 References: <339fddc5.293592@news.flex.com.au> X-Http-User-Agent: Mozilla/3.0 (Win95; I) X-Originating-IP-Addr: 192.228.248.52 () Organization: Deja News Usenet Posting Service X-Article-Creation-Date: Fri Jun 13 02:10:05 1997 GMT X-Authenticated-Sender: jude@tsi.com.my Newsgroups: comp.unix.osf.osf1 In article <339fddc5.293592@news.flex.com.au>, damien@flex.com.au (Damien Lee) wrote: > > How do you change the Ethernet address on a AlphaStation255? In the > SRM console? > > Damien I don't think it's possible via the SRM console but I'm attaching a previous Summary of some code to do just that. Hope it helps. Regards, Jude T. Cruz, TIME Systems Integrators, MALAYSIA Date: Tue, 11 Mar 1997 21:00:07 +0100 From: Laurent Deniel Organization: Home To: alpha-osf-managers@ornl.gov Subject: SUMMARY: Ethernet Address Thanks a lot for your quick response : . Anil Khullar . Santosh Krishnan . Cliff Krieger . Michael R. Kline Original message : > Is there a way to change the ethernet address of a DEC LANCE interface > (or whatever else) on Digital UNIX machines like on some others > operating systems/hardware ? Special thanks to : . Michael R. Kline . Cliff Krieger -- Michael wrote : Laurent, He's the important part of my post from some time ago: > I sure hope somebody out there is interested in all of this. I am > including my previous posts at the bottom of this message. According > to Matt Thomas , the ioctl.h def of SIOCSPHYSADDR is > incorrect. The device driver actually takes a struct ifreq, not a > struct > ifdevea. I have rewritten my code to use this (thanks Matt). I wonder > if future releases will correct this and which struct will wind up being > the correct one. > > At any rate here's a corrected version of the code which will change > tu1's MAC address to ab:bc:cd:de:ef:fa. I am setting this up so it will > occur after each boot, thus replacing the actual hardware address. > > ****************************************************************************** > > #include /* standard I/O */ > #include /* error numbers */ > #include /* socket definitions */ > #include /* ioctls */ > #include /* generic interface structures */ > > main() > { > int s,i; > struct ifdevea devea; > struct ifreq req; > > /* Get a socket */ > > s = socket(AF_INET,SOCK_DGRAM,0); > if (s < 0) { > perror("socket"); > exit(1); > } > > /* Just for grins, we'll see what our current value is */ > > strcpy(devea.ifr_name,"tu1"); > if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { > perror(&devea.ifr_name[0]); > exit(1); > } > printf("Address is "); > for (i = 0; i < 6; i++) > printf("%X ", devea.current_pa[i] & 0xff); > printf("\n"); > > /* We set the values in the ifreq struct, not ifdevea. */ > /* Although ioctl.h defines SIOCSPHYSADDR to take ifdevea, */ > /* the driver really takes ifreq. */ > /* If a later release has the driver read ifdevea, we will */ > /* need to set the values in devea.default_pa[0..5] */ > > printf("Setting values...\n"); > strcpy(req.ifr_name, devea.ifr_name); > req.ifr_addr.sa_data[0] = 0xab; > req.ifr_addr.sa_data[1] = 0xbc; > req.ifr_addr.sa_data[2] = 0xcd; > req.ifr_addr.sa_data[3] = 0xde; > req.ifr_addr.sa_data[4] = 0xef; > req.ifr_addr.sa_data[5] = 0xfa; > printf("Changing address...\n"); > if (ioctl(s,SIOCSPHYSADDR,&req) < 0) { > perror(&devea.ifr_name[0]); > exit(1); > } > printf("Address changed.\n"); > > /* check our work */ > > if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { > perror(&devea.ifr_name[0]); > exit(1); > } > printf("Address is "); > for (i = 0; i < 6; i++) > printf("%X ", devea.current_pa[i] & 0xff); > printf("\n"); > > close(s); > } > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Michael R. Kline mike@lib.utexas.edu General Libraries Office: (512) 495-4391 University of Texas at Austin FAX : (512) 495-4347 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And Cliff's response : : Is there a way to change the ethernet address of a DEC LANCE interface : (or whatever else) on Digital UNIX machines like on some others : operating systems/hardware ? Not an easy way. I have written a small program that will copy the mac address from one card to another. I will give you a copy of the code that will reset the MAC address to the default. You should be able to easly modify it to put in whatever you want. Just change the 6 lines in the middle replacing addr[?] with the byte you want. Of course the standard disclaimers apply. This code is not in the public domain. Lattice Trading and State Street Bank retain the Copyright 1997. No promises or warantees or garuntees of any kind are made for this program. In fact, we did have a card go bad after using this program. That may just be a coincidence. Basicly just save this code. It should compile with cc. I hope this helps. -cliff Here it is: /* Program Copyright 1997 Lattice Trading and State Street Bank. */ /* Use at your own risk. */ #include /* standard I/O */ #include /* error numbers */ #include /* socket definitions */ #include /* ioctls */ #include /* generic interface structures */ main(int argc,char **argv) { int s,i; u_char addr[6]; struct ifdevea devea; if (argc != 2) { fprintf(stderr,"Usage: macreset \n"); exit(-1); } /* Get a socket */ s = socket(AF_INET,SOCK_DGRAM,0); if (s < 0) { perror("socket"); exit(1); } /* Just for grins, we'll see what our current value is */ strcpy(devea.ifr_name,argv[1]); if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { perror(&devea.ifr_name[0]); exit(1); } printf(argv[1]); printf(" address is: "); for (i = 0; i < 6; i++) { printf("%X ", devea.current_pa[i] & 0xff); addr[i] = devea.default_pa[i]; } printf("\n"); /* Now, we set our values to the address we want. We should */ /* be setting devea.default_pa[0..5], but there is a bug and */ /* the SIOCSPHYSADDR call will actually look at what is in */ /* devea.default_pa[2]..devea.default_pa[5], */ /* devea.current_pa[0], devea.current_pa[1]. So we set our */ /* address there instead. */ devea.default_pa[2] = addr[0]; devea.default_pa[3] = addr[1]; devea.default_pa[4] = addr[2]; devea.default_pa[5] = addr[3]; devea.current_pa[0] = addr[4]; devea.current_pa[1] = addr[5]; if (ioctl(s,SIOCSPHYSADDR,&devea) < 0) { perror(&devea.ifr_name[0]); exit(1); } printf(argv[1]); printf(" address changed.\n"); /* check our work */ strcpy(devea.ifr_name,argv[1]); if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { perror(&devea.ifr_name[0]); exit(1); } printf(argv[1]); printf(" address is: "); for (i = 0; i < 6; i++) printf("%X ", devea.current_pa[i] & 0xff); printf("\n"); close(s); } -- Laurent DENIEL | E-mail: deniel@worldnet.fr Paris, FRANCE | deniel@airsys.thomson.fr | WWW : http://www.worldnet.fr/~deniel All above opinions are personal, unless stated otherwise. -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet