SUMMARY: Ethernet Address

From: Laurent Deniel <deniel_at_worldnet.fr>
Date: Tue, 11 Mar 1997 21:00:07 +0100

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 <mike_at_lib.utexas.edu>
 . Cliff Krieger <ckrieger_at_latrade.com>

--
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 <thomas_at_lkg.dec.com>, 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 <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;
>   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_at_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 <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 argc,char **argv)
{
  int s,i;
  u_char addr[6];
  struct  ifdevea  devea;
  if (argc != 2) {
    fprintf(stderr,"Usage: macreset <interface>\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_at_worldnet.fr
Paris, FRANCE                 |         deniel_at_airsys.thomson.fr
                              | WWW   : http://www.worldnet.fr/~deniel
     All above opinions are personal, unless stated otherwise.
Received on Tue Mar 11 1997 - 21:22:58 NZDT

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