viced: Tidy header includes
[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
22 #define SYSIDMAGIC      0x88aabbcc
23 #define SYSIDVERSION    1
24
25 struct versionStamp {           /* Stolen from <afs/volume.h> */
26     int magic;
27     int version;
28 };
29
30 int
31 main(int argc, char **argv)
32 {
33     int fd, size, i;
34
35     struct versionStamp vs;
36     afsUUID uuid;
37     int nentries;
38     int addr;
39
40     if ((argc != 2) || (strcmp(argv[1], "-h") == 0)) {
41         printf("Usage: check_sysid <sysid_file>\n");
42         exit((argc != 2) ? 1 : 0);
43     }
44
45     fd = open(argv[1], O_RDONLY, 0);
46     if (fd < 0) {
47         printf("Unable to open file '%s'. Errno = %d\n", argv[1], errno);
48         exit(2);
49     }
50
51     /* Read the Version Stamp */
52     size = read(fd, (char *)&vs, sizeof(vs));
53     if (size != sizeof(vs)) {
54         printf("Unable to read versionStamp. Size = %d. Errno = %d\n", size,
55                errno);
56     }
57     printf("versionStamp.magic   = 0x%x %s\n", vs.magic,
58            (vs.magic == SYSIDMAGIC) ? "" : "(should be 0x88aabbc)");
59     printf("versionStamp.version = 0x%x %s\n", vs.version,
60            (vs.version == SYSIDVERSION) ? "" : "(should be 0x1)");
61
62     /* Read the uuid.
63      * Look at util/uuid.c afs_uuid_create() to see how it is created.
64      */
65     size = read(fd, (char *)&uuid, sizeof(uuid));
66     if (size != sizeof(uuid)) {
67         printf("Unable to read afsUUID. Size = %d. Errno = %d\n", size,
68                errno);
69         exit(3);
70     }
71     printf("UUID.time(hi.mid.low)= 0x%03x.%04x.%08x\n",
72            uuid.time_hi_and_version & 0x0fff, uuid.time_mid & 0xffff,
73            uuid.time_low);
74     printf("UUID.version         = %d (0x%01x)\n",
75            (uuid.time_hi_and_version >> 12) & 0xf,
76            (uuid.time_hi_and_version >> 12) & 0xf);
77     printf("UUID.clock(hi.low)   = 0x%02x.%02x\n",
78            uuid.clock_seq_hi_and_reserved & 0x3f, uuid.clock_seq_low & 0xff);
79     printf("UUID.reserved        = %d (0x%02x)\n",
80            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3,
81            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3);
82     printf("UUID.node            = %02x.%02x.%02x.%02x.%02x.%02x\n",
83            uuid.node[0] & 0xff, uuid.node[1] & 0xff, uuid.node[2] & 0xff,
84            uuid.node[3] & 0xff, uuid.node[4] & 0xff, uuid.node[5] & 0xff);
85
86     /* Read the number of addresses recorded in the sysid */
87     size = read(fd, (char *)&nentries, sizeof(int));
88     if (size != sizeof(int)) {
89         printf("Unable to read nentries. Size = %d. Errno = %d\n", size,
90                errno);
91         exit(4);
92     }
93     printf("Number of addreses   = %d (0x%x)\n", nentries, nentries);
94
95     /* Now read in each of the addresses */
96     for (i = 0; i < nentries; i++) {
97         size = read(fd, (char *)&addr, sizeof(int));
98         if (size != sizeof(int)) {
99             printf("Unable to read IP Address %d. Size = %d. Errno = %d\n",
100                    i + 1, size, errno);
101             exit(5);
102         }
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 }