date and time created 85/05/23 14:06:03 by miriam
[unix-history] / usr / src / old / hostid / hostid.c
CommitLineData
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
8char 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
bcf1365c
DF
14static char sccsid[] = "@(#)hostid.c 5.1 (Berkeley) %G%";
15#endif not lint
ca4eabba 16
55b0d21e
RC
17#include <stdio.h>
18
19extern char *index();
20extern unsigned long inet_addr();
21
ca4eabba
SL
22main(argc, argv)
23 int argc;
24 char **argv;
25{
55b0d21e
RC
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 }
ca4eabba 50
55b0d21e 51 exit(0);
ca4eabba 52}