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