SUMMARY:reading and changing MAC adress using software

From: <baranowskit_at_gdynia_at_genesis.prokom.gdynia.pl>
Date: Mon, 05 Aug 96 08:22:39 cet

Thanks to:


  Simon Amor
        mailto:spa_at_dmu.ac.uk
        http://www.dmu.ac.uk/~spa/

  Robert Schuhl
        office: Robert.Schuhl_at_ald-vt.de;http://www.ald-vt.de
        priv: rschuhl_at_rsl000.rhein-main.de

  Gary
        GLADNEY_at_stsci.edu

.. and most complete and useful response was:

  Michael R. Kline mike_at_lib.utexas.edu
   General Libraries Office: (512) 495-4391
   University of Texas at Austin FAX : (512) 495-4347

Here it is (all):

baranowskit_at_gdynia_at_genesis.prokom.gdynia.pl wrote:
>
> Hello managers.
>
> Machine: AlphaServer 2100; ... 2000; ... 1000
> OS: OSF 3.0; DU 3.2c; DU 3.2d and up
>
> First problem:
> I need sometimes change MAC adres of tu0 in few instalations, but I
> didn't find utility for do that. Does it exist, where ? Is changing
MAC

> address is possible ?

I solved this problem a while back. Here is the summary I gave:

> 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 <thomas_at_lkg.dec.com>
Mike Iglesias <iglesias_at_draco.acs.uci.edu>
Dan Riley <dsr_at_lns598.lns.cornell.edu>
Mr Tim J M Warren <twarren_at_HK.Super.NET>

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 <stdio.h> /* standard I/O */
#include <errno.h> /* error numbers */
#include <sys/socket.h> /* socket definitions */
#include <sys/ioctl.h> /* ioctls */
#include <net/if.h> /* 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);
}





>
> Second problem:
> Programmers division ask me how to read MAC address from inside
program

> written in C. They don't want to use external programs.


You can use some of the code from the above program to read the MAC
address.

  /* 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);


>
> Thanks in advance
>
> Tomasz Baranowski, PROKOM, Poland

-- 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         Michael R. Kline                        mike_at_lib.utexas.edu
         General Libraries                      Office: (512) 495-4391
         University of Texas at Austin          FAX   : (512) 495-4347
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks,
Best regards,
Tomasz Baranowski, PROKOM, Poland.
Received on Mon Aug 05 1996 - 09:00:03 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT