/* * (c) spd@daphne.cps.unizar.es * * sid: a program which changes/restores hostid on little endian linux hosts * * change hostid: * sid 0xffffffff * restore original hostid: * sid */ #include #include #include #include #include #include #include #include #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif /* Real example: (Linux Red Hat 6.2) inet addr:155.210.152.24 hostid: 0xd29b1898 155 -> 9b 210 -> d2 152 -> 98 24 -> 18 */ int main(int argc, char **argv) { long int hostid; char hostname[256]; struct hostent *he; u_long add; if (argc != 1) { printf("current hostid: 0x%x\n", gethostid()); printf("sethostid: %ld %d\n", strtol( argv[1], (char **)NULL, 0 ), sethostid(strtol( argv[1], (char **)NULL, 0 ))); printf("current hostid: %x\n", gethostid()); } else { /* * We will get IP from hostname instead of querying network * interface. If you don't like it, edit below this line... */ if (gethostname(hostname,sizeof(hostname)) < 0) { perror("gethostname: who am I ?"); exit(1); } if ( (he=gethostbyname(hostname)) == NULL) { perror("gethostbyname: can't get an address"); exit(1); } add=htonl( ((struct in_addr *)(he->h_addr_list[0]))->s_addr ); hostid= ( ((add & 0xff000000)>>8)| ((add & 0x00ff0000)<<8)| ((add & 0x0000ff00)>>8)| ((add & 0x000000ff)<<8) ); printf("sethostid: 0x%lx %d\n", hostid, sethostid(hostid)); } return (0); }