Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / libadmin / samples / rxstat_get_version.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 rxstats 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 #include <afs/afs_Admin.h>
28 #include <afs/afs_clientAdmin.h>
29 #include <afs/afs_utilAdmin.h>
30
31 void
32 Usage(void)
33 {
34 fprintf(stderr, "Usage: rxstat_get_version <host> <port>\n");
35 exit(1);
36 }
37
38 void
39 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
40 {
41 char **argp = argv;
42
43 if (!*(++argp))
44 Usage();
45 *srvrName = *(argp++);
46 if (!*(argp))
47 Usage();
48 *srvrPort = strtol(*(argp++), NULL, 0);
49 if (*srvrPort <= 0 || *srvrPort >= 65536)
50 Usage();
51 if (*(argp))
52 Usage();
53 }
54
55 int
56 main(int argc, char *argv[])
57 {
58 int rc;
59 afs_status_t st = 0;
60 struct rx_connection *conn;
61 char *srvrName;
62 long srvrPort;
63 void *cellHandle;
64 afs_RPCStatsVersion_t version;
65
66 ParseArgs(argc, argv, &srvrName, &srvrPort);
67
68 rc = afsclient_Init(&st);
69 if (!rc) {
70 fprintf(stderr, "afsclient_Init, status %d\n", st);
71 exit(1);
72 }
73
74 rc = afsclient_NullCellOpen(&cellHandle, &st);
75 if (!rc) {
76 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
77 exit(1);
78 }
79
80 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
81 &st);
82 if (!rc) {
83 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
84 exit(1);
85 }
86
87 rc = util_RPCStatsVersionGet(conn, &version, &st);
88 if (!rc) {
89 fprintf(stderr, "util_RPCStatsVersionGet, status %d\n", st);
90 exit(1);
91 }
92
93 rc = afsclient_RPCStatClose(conn, &st);
94 if (!rc) {
95 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
96 exit(1);
97 }
98
99 rc = afsclient_CellClose(cellHandle, &st);
100 if (!rc) {
101 fprintf(stderr, "afsclient_CellClose, status %d\n", st);
102 exit(1);
103 }
104
105 printf("\n");
106 printf("RPC stats are version %d\n", (int)version);
107 printf("\n");
108
109 exit(0);
110 }