1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 char copyright[] = 9 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 10 All rights reserved.\n"; 11 #endif not lint 12 13 #ifndef lint 14 static char sccsid[] = "@(#)hostid.c 5.1 (Berkeley) 04/30/85"; 15 #endif not lint 16 17 #include <stdio.h> 18 19 extern char *index(); 20 extern unsigned long inet_addr(); 21 22 main(argc, argv) 23 int argc; 24 char **argv; 25 { 26 register char *id; 27 int hostid; 28 29 if (argc < 2) { 30 printf("%#x\n", gethostid()); 31 exit(0); 32 } 33 id = argv[1]; 34 35 if (index(id, '.') != NULL) 36 hostid = (int) inet_addr(id); 37 else { 38 if (*id == '0' && (id[1] == 'x' || id[1] == 'X')) 39 id += 2; 40 if (sscanf(id, "%x", &hostid) != 1) { 41 fprintf(stderr, "usage: %s [hexnum or internet address]\n", argv[0]); 42 exit(1); 43 } 44 } 45 46 if (sethostid(hostid) < 0) { 47 perror("sethostid"); 48 exit(1); 49 } 50 51 exit(0); 52 } 53