Commit | Line | Data |
---|---|---|
bcf1365c DF |
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 | ||
205a2d85 | 13 | #ifndef lint |
95f51977 | 14 | static char sccsid[] = "@(#)hostid.c 5.4 (Berkeley) 5/19/86"; |
bcf1365c | 15 | #endif not lint |
ca4eabba | 16 | |
ad771da0 | 17 | #include <sys/types.h> |
55b0d21e | 18 | #include <stdio.h> |
ad771da0 MK |
19 | #include <ctype.h> |
20 | #include <netdb.h> | |
55b0d21e RC |
21 | |
22 | extern char *index(); | |
23 | extern unsigned long inet_addr(); | |
f7cdd19f | 24 | extern long gethostid(); |
55b0d21e | 25 | |
ca4eabba SL |
26 | main(argc, argv) |
27 | int argc; | |
28 | char **argv; | |
29 | { | |
55b0d21e | 30 | register char *id; |
ad771da0 | 31 | u_long addr; |
f7cdd19f | 32 | long hostid; |
ad771da0 | 33 | struct hostent *hp; |
55b0d21e RC |
34 | |
35 | if (argc < 2) { | |
36 | printf("%#x\n", gethostid()); | |
37 | exit(0); | |
38 | } | |
55b0d21e | 39 | |
3b723ccd MK |
40 | id = argv[1]; |
41 | if (hp = gethostbyname(id)) { | |
42 | bcopy(hp->h_addr, &addr, sizeof(addr)); | |
43 | hostid = addr; | |
44 | } else if (index(id, '.')) { | |
45 | if ((hostid = inet_addr(id)) == -1) | |
46 | goto usage; | |
47 | } else { | |
48 | if (id[0] == '0' && (id[1] == 'x' || id[1] == 'X')) | |
55b0d21e RC |
49 | id += 2; |
50 | if (sscanf(id, "%x", &hostid) != 1) { | |
3b723ccd MK |
51 | usage: |
52 | fprintf(stderr, | |
53 | "usage: %s [hexnum or internet address]\n", | |
54 | argv[0]); | |
55 | exit(1); | |
55b0d21e RC |
56 | } |
57 | } | |
58 | ||
59 | if (sethostid(hostid) < 0) { | |
60 | perror("sethostid"); | |
61 | exit(1); | |
62 | } | |
ca4eabba | 63 | |
55b0d21e | 64 | exit(0); |
ca4eabba | 65 | } |