Commit | Line | Data |
---|---|---|
805e021f CE |
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 <rx/rx.h> | |
26 | #include <rx/rxstat.h> | |
27 | ||
28 | #include <afs/afs_Admin.h> | |
29 | #include <afs/afs_clientAdmin.h> | |
30 | #include <afs/afs_utilAdmin.h> | |
31 | ||
32 | void | |
33 | Usage(void) | |
34 | { | |
35 | fprintf(stderr, "Usage: cm_server_prefs <host> <port>\n"); | |
36 | exit(1); | |
37 | } | |
38 | ||
39 | void | |
40 | ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort) | |
41 | { | |
42 | char **argp = argv; | |
43 | ||
44 | if (!*(++argp)) | |
45 | Usage(); | |
46 | *srvrName = *(argp++); | |
47 | if (!*(argp)) | |
48 | Usage(); | |
49 | *srvrPort = strtol(*(argp++), NULL, 0); | |
50 | if (*srvrPort <= 0 || *srvrPort >= 65536) | |
51 | Usage(); | |
52 | if (*(argp)) | |
53 | Usage(); | |
54 | } | |
55 | ||
56 | int | |
57 | main(int argc, char *argv[]) | |
58 | { | |
59 | int rc; | |
60 | afs_status_t st = 0; | |
61 | struct rx_connection *conn; | |
62 | char *srvrName; | |
63 | long srvrPort; | |
64 | void *cellHandle; | |
65 | afs_CMServerPref_t prefs; | |
66 | void *iterator; | |
67 | afs_uint32 taddr; | |
68 | ||
69 | ParseArgs(argc, argv, &srvrName, &srvrPort); | |
70 | ||
71 | rc = afsclient_Init(&st); | |
72 | if (!rc) { | |
73 | fprintf(stderr, "afsclient_Init, status %d\n", st); | |
74 | exit(1); | |
75 | } | |
76 | ||
77 | rc = afsclient_NullCellOpen(&cellHandle, &st); | |
78 | if (!rc) { | |
79 | fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st); | |
80 | exit(1); | |
81 | } | |
82 | ||
83 | rc = afsclient_CMStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st); | |
84 | if (!rc) { | |
85 | fprintf(stderr, "afsclient_CMStatOpenPort, status %d\n", st); | |
86 | exit(1); | |
87 | } | |
88 | ||
89 | rc = util_CMGetServerPrefsBegin(conn, &iterator, &st); | |
90 | if (!rc) { | |
91 | fprintf(stderr, "util_CMGetServerPrefsBegin, status %d\n", st); | |
92 | exit(1); | |
93 | } | |
94 | ||
95 | printf("\n"); | |
96 | while (util_CMGetServerPrefsNext(iterator, &prefs, &st)) { | |
97 | taddr = prefs.ipAddr; | |
98 | printf("%d.%d.%d.%d\t\t\t%d\n", (taddr >> 24) & 0xff, | |
99 | (taddr >> 16) & 0xff, (taddr >> 8) & 0xff, taddr & 0xff, | |
100 | prefs.ipRank); | |
101 | } | |
102 | if (st != ADMITERATORDONE) { | |
103 | fprintf(stderr, "util_CMGetServerPrefsNext, status %d\n", st); | |
104 | exit(1); | |
105 | } | |
106 | printf("\n"); | |
107 | ||
108 | rc = util_CMGetServerPrefsDone(iterator, &st); | |
109 | if (!rc) { | |
110 | fprintf(stderr, "util_CMGetServerPrefsDone, status %d\n", st); | |
111 | exit(1); | |
112 | } | |
113 | ||
114 | rc = afsclient_CMStatClose(conn, &st); | |
115 | if (!rc) { | |
116 | fprintf(stderr, "afsclient_CMStatClose, status %d\n", st); | |
117 | exit(1); | |
118 | } | |
119 | ||
120 | rc = afsclient_CellClose(cellHandle, &st); | |
121 | if (!rc) { | |
122 | fprintf(stderr, "afsclient_CellClose, status %d\n", st); | |
123 | exit(1); | |
124 | } | |
125 | ||
126 | exit(0); | |
127 | } |