emmerik@utrcu1.UUCP (Emmerik P.J.L. van) (12/11/90)
Wanted: a way of obtaining a unique identifier for a SUN-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
mjr@hussar.dco.dec.com (Marcus J. Ranum) (12/11/90)
In article <747@utrcu1.UUCP> emmerik@utrcu1.UUCP (Emmerik P.J.L. van) writes: > >Wanted: a way of obtaining a unique identifier for a SUN-workstation > from a program. > >On some systems we use the ethernet address of a workstation as a unique >identifier The Sun has a unique host id#, unless I'm mistaken. Take a look at the man page on "hostid" or something like that. Using the ethernet address as a unique identifier is questionably unique, since it can be changed with ioctl()s on some machines (which is what DECnet does). At least it guarantees that only one machine at a time on a local network will use that number, though. mjr. -- I'd trade all the CASE tools in the world for one real programmer. [From the programming notebooks of a heretic, 1990]
paquette@cs-sun-fsd.cpsc.ucalgary.ca (Trevor Paquette) (12/12/90)
Try using the hostid, gethostid(2). -- ______________________________________/Through the darkness, the future past, Trevor Paquette ICBM:51'03"N/114'05"W|The magician longs to see. {ubc-cs,utai,alberta}!calgary!paquette|One chants out, between two worlds, paquette@cpsc.ucalgary.ca |"Fire, walk with me."
cliffs@sunrock.East.Sun.COM (Clifford C. Skolnick) (12/14/90)
In article <747@utrcu1.UUCP> emmerik@utrcu1.UUCP (Emmerik P.J.L. van) writes: > >Wanted: a way of obtaining a unique identifier for a SUN-workstation > from a program. gethostid() will do the trick you want. Cliff -- Cliff Skolnick | "You give me the reason, you give me control. cliffs@sun.com | I gave you my purity, my purity you stole. Am I (716) 385-5049 | just too stupid to realize stale incense old sweat I think. I am. | and lies lies lies." -- Nine Inch Nails