On Wed, 28 Jun 2000, Rick Parker wrote: > How would I change the hostid for a Linux system? > For single process or completely? There is a solution attached for both, or change ethernet card :) > Do you know if it is the same with a SUN system? > Gosh I dont remember how to do it offially with SUN, but as an ELF system I would expect that attached tools work fine. :-) riku -- [ This .signature intentionally left blank ]
/* * $Id: hostid.c,v 1.1 1999/03/07 18:10:18 mesrik Exp $ */ #include <assert.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/utsname.h> int main(int argc, char *argv[]) { struct utsname u; char *p; unsigned id; if (p = strrchr (*argv, '/')) p++; else p = *argv; uname(&u); switch (argc) { case 2: if (sethostid((int)strtol(*++argv,NULL,0))) perror(p); break; case 1: if (id = gethostid()) printf ("%s %s hostid is %u (0x%x)\n", u.sysname, u.nodename, id, id); else printf ("%s %s hostid is unset%s\n", u.sysname, u.nodename, !geteuid() ? "" : " or you haven't got permission to read it"); break; default: printf ("Usage: %s [hostid value to set]\n",p); } return 0; } /* eof */
/* * $Id: fakeid.c,v 1.2 1999/08/24 15:17:18 mesrik Exp $ * * Linux, SunOS usage: # make hostid * # ./hostid * # gcc -shared fakeid.c -o fakeid.so * # HOSTID="0xbadbeef" LD_PRELOAD=./fakeid.so ./hostid * * * HP-UX usage: # make hostid * # ./hostid * # gcc -fPIC -shared -Wl,-E,-b fakeid.c -o fakeid.sl * * Dunno yet how to do preload on HP-UX :/ * */ #include <time.h> #include <limits.h> #include <stdlib.h> #include <unistd.h> long int gethostid(void) { static unsigned int id = 0; char *nptr; if ((nptr = getenv("HOSTID"))) { return strtol(nptr,NULL,0); } else { if (!id) { srand(getpid() * time(0)); id = 1+(int)(((float)(UINT_MAX))*rand()/(UINT_MAX+1.0)); } return id; } } /* eof */