macos103-20031024
[openafs.git] / src / libadmin / samples / rxdebug_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 RCSID
20     ("$Header$");
21
22 #ifdef AFS_NT40_ENV
23 #include <winsock2.h>
24 #include <pthread.h>
25 #endif
26 #include <afs/afs_Admin.h>
27 #include <afs/afs_clientAdmin.h>
28 #include <afs/afs_utilAdmin.h>
29
30 #ifdef AFS_DARWIN_ENV
31 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
32 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
33 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
34 #endif /* AFS_DARWIN_ENV */
35
36 void
37 Usage()
38 {
39     fprintf(stderr, "Usage: rxdebug_version <host> <port>\n");
40     exit(1);
41 }
42
43 void
44 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
45 {
46     char **argp = argv;
47
48     if (!*(++argp))
49         Usage();
50     *srvrName = *(argp++);
51     if (!*(argp))
52         Usage();
53     *srvrPort = strtol(*(argp++), NULL, 0);
54     if (*srvrPort <= 0 || *srvrPort >= 65536)
55         Usage();
56     if (*(argp))
57         Usage();
58 }
59
60 int
61 main(int argc, char *argv[])
62 {
63     int rc;
64     afs_status_t st = 0;
65     rxdebugHandle_p handle;
66     char *srvrName;
67     long srvrPort;
68     rxdebugVersion_t version;
69
70     ParseArgs(argc, argv, &srvrName, &srvrPort);
71
72     rc = afsclient_Init(&st);
73     if (!rc) {
74         fprintf(stderr, "afsclient_Init, status %d\n", st);
75         exit(1);
76     }
77
78     rc = afsclient_RXDebugOpenPort(srvrName, srvrPort, &handle, &st);
79     if (!rc) {
80         fprintf(stderr, "afsclient_RXDebugOpenPort, status %d\n", st);
81         exit(1);
82     }
83
84     rc = util_RXDebugVersion(handle, version, &st);
85     if (!rc) {
86         fprintf(stderr, "util_RXDebugVersion, status %d\n", st);
87         exit(1);
88     }
89
90     rc = afsclient_RXDebugClose(handle, &st);
91     if (!rc) {
92         fprintf(stderr, "afsclient_RXDebugClose, status %d\n", st);
93         exit(1);
94     }
95
96     printf("\n");
97     printf("AFS Version: '%s'\n", version);
98     printf("\n");
99
100     exit(0);
101 }