emmerik@utrcu1.UUCP (Emmerik P.J.L. van) (12/12/90)
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@utwente.nl -- Pieter van Emmerik | Phone: +31-74-483059 Hollandse Signaalapparaten b.v. | FAX: +31-74-425936 P.O.box 42 | E-mail: emmerik@utwente.nl 7550 GD Hengelo, The Netherlands | hp4nl!utrcu1!emmerik
tih@barsoom.nhh.no (Tom Ivar Helbekkmo) (12/13/90)
emmerik@utrcu1.UUCP (Emmerik P.J.L. van) writes: >Wanted: a way of obtaining a unique identifier for a DEC > workstation from a program. The normal way to do this would be to use the 'hostid', I suppose. You set it from your /etc/rc.local at boot, normally using the internet address of the machine. Thus, I have: /bin/hostid 81b1260f in my /etc/rc.local. Then, I can use the gethostid() call from a program to get this value. The hostid is supposed to be a unique identifier for the machine 'among all Unix systems in existence'. -tih -- Tom Ivar Helbekkmo, NHH, Bergen, Norway. Telephone: +47-5-959205 tih@barsoom.nhh.no, thelbekk@norunit.bitnet, edb_tom@debet.nhh.no