WANTED: ethernet address or other unique ID for DEC-station

Emmerik P.J.L. van emmerik at utrcu1.UUCP
Wed Dec 12 18:47:24 AEST 1990


Repost: Sorry, in the original posting i asked only for a solution for
        a SUN workstation, where i realy wanted a solution for both SUN
        and DEC (RISK) workstations.
        I have already received a solution for SUN, use gethostid(2).

Wanted: a way of obtaining a unique identifier for a DEC
        workstation from a program.

On some systems we use the ethernet address of a workstation as a unique
identifier, but on some, like SUN Sparcstations and DEC-stations running
Ultrix this does not seem to work.
The method we use works as follows:

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_arp.h>

   int sock, st;
   struct sock_addr_in sin, *parp_pa;
   struct arpreq arpreq;
   struct hostent *hp;
   char chxx[200];

/* Create a socket */
   sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
/* Set the Internet address for the request */
   parp_pa = (struct sockaddr_in *)&arpreq.arp_pa;
   parp_pa->sin_family = AF_INET;
   parp_pa->sin_port = 0;
   gethostname( chxx, 199 );
   hp = gethostbyname( chxx );
   parp_pa->sin_addr.s_addr = *(u_long *)hp->hp_addr;

/* Set the type of the requested address */
   arpreq.arp_ha.sa_family = AF_UNSPEC;

/* Get the ethernet address */
   st = ioctl( sock, SIOCGARP, (caddr_t)&arpreq )
   if ( st< 0 )
   {
      perror( "ioctl" );
   }
   close( sock );
}

I have left some details, like error handling out.
This program will result in a message from perror:
  ioctl: No such device or address
i.e. ERRNO = 6

Two questions:
- am i doing something wrong, if so what should i do?
- is there maybe another way of obtaining a uniqiue identifier,
  e.g. a SUN specific routine to get a CPU-id?

Pleace send responces to emmerik at utwente.nl

-- 
Pieter van Emmerik                    | Phone:  +31-74-483059
Hollandse Signaalapparaten b.v.       | FAX:    +31-74-425936
P.O.box 42                            | E-mail: emmerik at utwente.nl
7550 GD  Hengelo, The Netherlands     |         hp4nl!utrcu1!emmerik



More information about the Comp.unix.programmer mailing list