reindent-20030715
[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 RCSID
19     ("$Header$");
20
21 #include <fcntl.h>
22 #include <errno.h>
23 #include <afs/vldbint.h>
24
25 #define SYSIDMAGIC      0x88aabbcc
26 #define SYSIDVERSION    1
27
28 struct versionStamp {           /* Stolen from <afs/volume.h> */
29     int magic;
30     int version;
31 };
32
33 int
34 main(int argc, char **argv)
35 {
36     int fd, size, i;
37
38     struct versionStamp vs;
39     afsUUID uuid;
40     int nentries;
41     int addr;
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 */
55     size = read(fd, (char *)&vs, sizeof(vs));
56     if (size != sizeof(vs)) {
57         printf("Unable to read versionStamp. Size = %d. Errno = %d\n", size,
58                errno);
59     }
60     printf("versionStamp.magic   = 0x%x %s\n", vs.magic,
61            (vs.magic == SYSIDMAGIC) ? "" : "(should be 0x88aabbc)");
62     printf("versionStamp.version = 0x%x %s\n", vs.version,
63            (vs.version == SYSIDVERSION) ? "" : "(should be 0x1)");
64
65     /* Read the uuid.
66      * Look at util/uuid.c afs_uuid_create() to see how it is created.
67      */
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     printf("UUID.time(hi.mid.low)= 0x%03x.%04x.%08x\n",
75            uuid.time_hi_and_version & 0x0fff, uuid.time_mid & 0xffff,
76            uuid.time_low);
77     printf("UUID.version         = %d (0x%01x)\n",
78            (uuid.time_hi_and_version >> 12) & 0xf,
79            (uuid.time_hi_and_version >> 12) & 0xf);
80     printf("UUID.clock(hi.low)   = 0x%02x.%02x\n",
81            uuid.clock_seq_hi_and_reserved & 0x3f, uuid.clock_seq_low & 0xff);
82     printf("UUID.reserved        = %d (0x%02x)\n",
83            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3,
84            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3);
85     printf("UUID.node            = %02x.%02x.%02x.%02x.%02x.%02x\n",
86            uuid.node[0] & 0xff, uuid.node[1] & 0xff, uuid.node[2] & 0xff,
87            uuid.node[3] & 0xff, uuid.node[4] & 0xff, uuid.node[5] & 0xff);
88
89     /* Read the number of addresses recorded in the sysid */
90     size = read(fd, (char *)&nentries, sizeof(int));
91     if (size != sizeof(int)) {
92         printf("Unable to read nentries. Size = %d. Errno = %d\n", size,
93                errno);
94         exit(4);
95     }
96     printf("Number of addreses   = %d (0x%x)\n", nentries, nentries);
97
98     /* Now read in each of the addresses */
99     for (i = 0; i < nentries; i++) {
100         size = read(fd, (char *)&addr, sizeof(int));
101         if (size != sizeof(int)) {
102             printf("Unable to read IP Address %d. Size = %d. Errno = %d\n",
103                    i + 1, size, errno);
104             exit(5);
105         }
106         printf("Address              = %d.%d.%d.%d (0x%x)\n",
107                (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
108                (addr) & 0xff, addr);
109     }
110
111     close(fd);
112 }