My original posting:
I am writing some license management software. It needs to be node-
locked. I would prefer not to use the hostid or the IP address
since both of those can be changed under OSF/1 and Ultrix. Is there a C
system call that will give me the ethernet address? I would prefer
to use the ethernet address (That can't be changed, right?).
Many people were quick to point out that the ethernet address can be
changed either by replacing the ethernet card or by setting in
software. Many were also quick to complain that node-locking a license
to an ethernet address is a bad idea. I received quit a few sets of
code to get the ethernet address. Note that there are two addresses
(default hardware address and current physical address). Here is
one:
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <stdio.h>
main(argc,argv)
char **argv;
{
struct ifdevea ifr;
int s;
if (argc != 2) {
fprintf(stderr,"Usage: %s devname\n",argv[0]);
fprintf(stderr,"Example: %s qe0\n",argv[0]);
exit(1);}
/* Create a socket */
if ((s = socket(AF_INET,SOCK_DGRAM,0)) < 0) perror("socket");
strcpy(ifr.ifr_name, argv[1]);
/* Get the ethernet address */
if ( ioctl(s,SIOCRPHYSADDR,&ifr) < 0 )
perror("Error in ioctl");
printf("%2x:%2x:%2x:%2x:%2x:%2x, name=%s\n",
(u_char)ifr.current_pa[0],
(u_char)ifr.current_pa[1],(u_char)ifr.current_pa[2],
(u_char)ifr.current_pa[3],(u_char)ifr.current_pa[4],
(u_char)ifr.current_pa[5], ifr.ifr_name);
printf("%2x:%2x:%2x:%2x:%2x:%2x, name=%s\n",
(u_char)ifr.default_pa[0],
(u_char)ifr.default_pa[1],(u_char)ifr.default_pa[2],
(u_char)ifr.default_pa[3],(u_char)ifr.default_pa[4],
(u_char)ifr.default_pa[5], ifr.ifr_name);
}
Thanks to those who replied:
Andy Phillips <atp_at_mssly1.mssl.ucl.ac.uk>
Rick Beebe <BEEBE_at_BIOMED.MED.YALE.EDU>
Andrew Gallatin <gallatin_at_isds.Duke.EDU>
Herve DEMARTHE (CEA France) <demarthe_at_alpha.cad.cea.fr>
Stam Nicolis <nicolis_at_celfi.phys.univ-tours.fr>
"Andrew Brennan, Lackey-at-large" <BRENNAN_at_HAL.HAHNEMANN.EDU>
Helleb\x Knut <bgk1142_at_bggfu2.nho.hydro.com>
Saul Tannenbaum <stannenb_at_emerald.tufts.edu>
"Dr. Tom Blinn, 603-881-0646" <tpb_at_zk3.dec.com>
Steve Osselton <so_at_prismtech.co.uk>
alan_at_nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.)
"nagroM W sirdI" <im_at_uvo.dec.com>
simon_at_locus.com
"Doug McPherson (617) 441-4565" <DOUGM_at_delphi.com>
swr_at_unx.dec.com (Scott Ruch)
haskins_at_mipps.myapc.com (Robert D. Haskins)
Dave Otto <dave_at_marvin.jta.edd.ca.gov>
William Flett <will_at_dcs.rhbnc.ac.uk>
wendling_at_unidad.vbo.dec.com
"Alex M. George" <george_at_mms.water.ci.detroit.mi.us>
Ken Cline <cline_at_iipo.gtegsc.com>
anthony baxter <anthony.baxter_at_aaii.oz.au>
Keith Lewis <keithl_at_mukluk.cc.monash.edu.au>
Harald Lundberg <hl_at_tekla.fi>
Jari Tavi <jpt_at_rixrax.enet.dec.com>
micha_at_ekpux2.physik.uni-karlsruhe.de (Michael Schneider)
Arrigo Triulzi <a.triulzi_at_ic.ac.uk>
Kevin J Walters <k.j.walters_at_lpac.ac.uk>
Robert Drawsky <rdrawsky_at_hulk.sfsu.edu>
tim moore <tmoore_at_pa.dec.com>
Benoit Maillard - Digital France- dtn: 858-1243 / ext: 33 1 69 87 12 43 <"atyisa::maillard"_at_atyisa.enet.dec.com>
Leonard Vaughn <vaughn_at_rust.zso.dec.com>
===============================================================================
Craig Knudsen cknudsen_at_btg.com
http://www.btg.com/~cknudsen/
BTG, Inc.
http://www.btg.com/
===============================================================================
Received on Wed Apr 12 1995 - 12:03:15 NZST