Standardize License information
[openafs.git] / src / libadmin / samples / cm_list_cells.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 /*
11  * This file contains sample code for the client admin interface 
12  */
13
14 #ifdef AFS_NT40_ENV
15 #include <winsock2.h>
16 #include <pthread.h>
17 #endif
18 #include <afs/afs_Admin.h>
19 #include <afs/afs_clientAdmin.h>
20 #include <afs/afs_utilAdmin.h>
21
22 void Usage()
23 {
24     fprintf(stderr,
25             "Usage: cm_list_cells <host> <port>\n");
26     exit(1);
27 }
28
29 void ParseArgs(
30     int argc,
31     char *argv[],
32     char **srvrName,
33     long *srvrPort)
34 {
35     char **argp = argv;
36
37     if (!*(++argp))
38         Usage();
39     *srvrName = *(argp++);
40     if (!*(argp))
41         Usage();
42     *srvrPort = strtol(*(argp++), NULL, 0);
43     if (*srvrPort <= 0 || *srvrPort >= 65536)
44         Usage();
45     if (*(argp))
46         Usage();
47 }
48
49 int main(int argc, char *argv[])
50 {
51     int rc;
52     afs_status_t st = 0;
53     struct rx_connection *conn;
54     char *srvrName;
55     long srvrPort;
56     void *cellHandle;
57     afs_CMListCell_t cellInfo;
58     void *iterator;
59     afs_uint32 taddr;
60     int i;
61
62     ParseArgs(argc, argv, &srvrName, &srvrPort);
63
64     rc = afsclient_Init(&st);
65     if (!rc) {
66         fprintf(stderr, "afsclient_Init, status %d\n", st);
67         exit(1);
68     }
69
70     rc = afsclient_NullCellOpen(&cellHandle, &st);
71     if (!rc) {
72         fprintf(stderr, "afsclient_NullCellsOpen, status %d\n", st);
73         exit(1);
74     }
75
76     rc = afsclient_CMStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st);
77     if (!rc) {
78         fprintf(stderr, "afsclient_CMStatOpenPort, status %d\n", st);
79         exit(1);
80     }
81
82     rc = util_CMListCellsBegin(conn, &iterator, &st);
83     if (!rc) {
84         fprintf(stderr, "util_CMListCellsBegin, status %d\n", st);
85         exit(1);
86     }
87
88     printf("\n");
89     while (util_CMListCellsNext(iterator, &cellInfo, &st)) {
90         printf("Cell %s on hosts", cellInfo.cellname);
91         for (i=0 ; i < UTIL_MAX_CELL_HOSTS && cellInfo.serverAddr[i] ; i++) {
92             taddr = cellInfo.serverAddr[i];
93             printf(" %d.%d.%d.%d",
94                    (taddr >> 24) & 0xff, (taddr >> 16) & 0xff,
95                    (taddr >> 8) & 0xff, taddr & 0xff);
96         }
97         printf("\n");
98     }
99     if (st != ADMITERATORDONE) {
100         fprintf(stderr, "util_CMListCellsNext, status %d\n", st);
101         exit(1);
102     }
103     printf("\n");
104
105     rc = util_CMListCellsDone(iterator, &st);
106     if (!rc) {
107         fprintf(stderr, "util_CMListCellsDone, status %d\n", st);
108         exit(1);
109     }
110
111     rc = afsclient_CMStatClose(conn, &st);
112     if (!rc) {
113         fprintf(stderr, "afsclient_CMStatClose, status %d\n", st);
114         exit(1);
115     }
116
117     rc = afsclient_CellClose(cellHandle, &st);
118     if (!rc) {
119         fprintf(stderr, "afsclient_CellClose, status %d\n", st);
120         exit(1);
121     }
122
123     exit(0);
124 }