From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075323306467.tru64-unix-managers.marc@archive.invalid> From: "Michael R. Kline" Date: Wed, 06 Sep 1995 20:47:45 +0000 To: tru64-unix-managers Subject: SUMMARY !: How to change a MAC address? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075323306467 My two previous posts (the solution follows) : > I asked: > > > > > Gurus: > > > > Alphastation 200 4/100 running OSF/1 3.2A... > > > > I have a second ethernet interface on a machine I am using as a backup > > server. I want to configure this second ethernet interface with the same > > IP and MAC address as the server so that I can just unplug one and plug > > the other in to switch between machines. How do I change the MAC address > > on my ethernet card? > > > > Also, if anybody knows how to make my Alpha send a gratuitous arp to the > > router, I could do that instead. > > > > Well, I received some answers, but I did not like them. The consensus is > that it is not possible to change your ethernet address since it is part > of the hardware. This doesn't sit well with me. Solaris allows you to > do it with their ifconfig command, so I know that it is an open > possibility. If there is not an OSF/1 utility to do it, can I write a > device driver to take care of it? Maybe someone from DEC could answer this? > This is definitely possible. There is an ioctl call (SIOCSPHYSADDR) that handles it. Unfortunately, there appears to be a bug in this call, but it can be worked around. The way to do it can be found in man ln(7), sys/ioctl.h, and net/if.h. If anybody sees that I am doing something wrong and that there really is no bug in this ioctl call, please let me know! The example in ln(7) of how to read the address has 4 syntactical errors and a logic bug - bad scan or typos. Thanks go to: Matt Thomas Mike Iglesias Dan Riley Mr Tim J M Warren For pointing me to this ioctl. Thanks also to all of you who pointed out that DECNet does it, so you knew it could be done (gave me hope). Thanks also to the numerous folks out there who replied that it was impossible. Hey - this is UNIX, it's all possible! Here's my code (if I were to want my address to be ab:bc:cd:de:ef:f0) : ****************************************************************************** #include /* standard I/O */ #include /* error numbers */ #include /* socket definitions */ #include /* ioctls */ #include /* generic interface structures */ main() { int s,i; struct ifdevea devea; /* 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"); /* 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. */ printf("Setting values...\n"); devea.default_pa[2] = 0xab; devea.default_pa[3] = 0xbc; devea.default_pa[4] = 0xcd; devea.default_pa[5] = 0xde; devea.current_pa[0] = 0xef; devea.current_pa[1] = 0xf0; printf("Changing address...\n"); if (ioctl(s,SIOCSPHYSADDR,&devea) < 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~