Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / viced / check_sysid.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 /* check_sysid.c - Verify and display the sysid file. */
11 /* Date: 10/21/97 */
12 /* */
13 /* ********************************************************************* */
14
15 #include <afsconfig.h>
16 #include <afs/param.h>
17
18 #include <roken.h>
19
20 #include <afs/vldbint.h>
21 #include <opr/uuid.h>
22
23 #define SYSIDMAGIC 0x88aabbcc
24 #define SYSIDVERSION 1
25
26 struct versionStamp { /* Stolen from <afs/volume.h> */
27 int magic;
28 int version;
29 };
30
31 int
32 main(int argc, char **argv)
33 {
34 int fd, size, i;
35
36 struct versionStamp vs;
37 int code;
38 opr_uuid_t uuid;
39 int nentries;
40 int addr;
41 char *buffer = NULL;
42
43 if ((argc != 2) || (strcmp(argv[1], "-h") == 0)) {
44 printf("Usage: check_sysid <sysid_file>\n");
45 exit((argc != 2) ? 1 : 0);
46 }
47
48 fd = open(argv[1], O_RDONLY, 0);
49 if (fd < 0) {
50 printf("Unable to open file '%s'. Errno = %d\n", argv[1], errno);
51 exit(2);
52 }
53
54 /* Read the Version Stamp. The magic and version fields are stored
55 * in host byte order. */
56 size = read(fd, (char *)&vs, sizeof(vs));
57 if (size != sizeof(vs)) {
58 printf("Unable to read versionStamp. Size = %d. Errno = %d\n", size,
59 errno);
60 }
61 printf("versionStamp.magic = 0x%x %s\n", vs.magic,
62 (vs.magic == SYSIDMAGIC) ? "" : "(should be 0x88aabbc)");
63 printf("versionStamp.version = 0x%x %s\n", vs.version,
64 (vs.version == SYSIDVERSION) ? "" : "(should be 0x1)");
65
66 /* Read the uuid. Portions of the uuid are stored in network
67 * byte order. */
68 size = read(fd, (char *)&uuid, sizeof(uuid));
69 if (size != sizeof(uuid)) {
70 printf("Unable to read afsUUID. Size = %d. Errno = %d\n", size,
71 errno);
72 exit(3);
73 }
74
75 code = opr_uuid_toString(&uuid, &buffer);
76 if (code != 0) {
77 printf("Unable to format uuid string. code=%d\n", code);
78 exit(6);
79 }
80 printf("UUID = %s\n", buffer);
81 opr_uuid_freeString(buffer);
82
83 /* Read the number of addresses recorded in the sysid.
84 * nentries is stored in host byte order. */
85 size = read(fd, (char *)&nentries, sizeof(int));
86 if (size != sizeof(int)) {
87 printf("Unable to read nentries. Size = %d. Errno = %d\n", size,
88 errno);
89 exit(4);
90 }
91 printf("Number of addreses = %d (0x%x)\n", nentries, nentries);
92
93 /* Now read in each of the addresses.
94 * Each address is stored in network byte order. */
95 for (i = 0; i < nentries; i++) {
96 size = read(fd, (char *)&addr, sizeof(int));
97 if (size != sizeof(int)) {
98 printf("Unable to read IP Address %d. Size = %d. Errno = %d\n",
99 i + 1, size, errno);
100 exit(5);
101 }
102 addr = ntohl(addr);
103 printf("Address = %d.%d.%d.%d (0x%x)\n",
104 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
105 (addr) & 0xff, addr);
106 }
107
108 close(fd);
109 return 0;
110 }