Warning cleanup for the libadmin directory
[openafs.git] / src / libadmin / samples / rxdebug_peers.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
20 #ifdef AFS_NT40_ENV
21 #include <winsock2.h>
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 #ifdef AFS_DARWIN_ENV
33 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
34 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
35 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
36 #endif /* AFS_DARWIN_ENV */
37
38 void
39 Usage(void)
40 {
41     fprintf(stderr, "Usage: rxdebug_peers <host> <port>\n");
42     exit(1);
43 }
44
45 void
46 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
47 {
48     char **argp = argv;
49
50     if (!*(++argp))
51         Usage();
52     *srvrName = *(argp++);
53     if (!*(argp))
54         Usage();
55     *srvrPort = strtol(*(argp++), NULL, 0);
56     if (*srvrPort <= 0 || *srvrPort >= 65536)
57         Usage();
58     if (*(argp))
59         Usage();
60 }
61
62 int
63 main(int argc, char *argv[])
64 {
65     int rc;
66     afs_status_t st = 0;
67     rxdebugHandle_p handle;
68     char *srvrName;
69     long srvrPort;
70     void *iterator;
71     struct rx_debugPeer peer;
72     afs_uint32 supportedValues;
73
74     ParseArgs(argc, argv, &srvrName, &srvrPort);
75
76     rc = afsclient_Init(&st);
77     if (!rc) {
78         fprintf(stderr, "afsclient_Init, status %d\n", st);
79         exit(1);
80     }
81
82     rc = afsclient_RXDebugOpenPort(srvrName, srvrPort, &handle, &st);
83     if (!rc) {
84         fprintf(stderr, "afsclient_RXDebugOpenPort, status %d\n", st);
85         exit(1);
86     }
87
88     rc = util_RXDebugPeersBegin(handle, &iterator, &st);
89     if (!rc) {
90         fprintf(stderr, "util_RXDebugPeersBegin, status %d\n", st);
91         exit(1);
92     }
93
94     while (util_RXDebugPeersNext(iterator, &peer, &supportedValues, &st)) {
95         printf("\n");
96         printf("host:            %u.%u.%u.%u\n", (peer.host >> 24) & 0xff,
97                (peer.host >> 16) & 0xff, (peer.host >> 8) & 0xff,
98                peer.host & 0xff);
99         printf("port:            %u\n", peer.port);
100         printf("ifMTU:           %u\n", peer.ifMTU);
101         printf("idleWhen:        %u\n", peer.idleWhen);
102         printf("refCount:        %u\n", peer.refCount);
103         printf("burstSize:       %u\n", peer.burstSize);
104         printf("burst:           %u\n", peer.burst);
105         printf("burstWait:       %u\n", peer.burstWait);
106         printf("rtt:             %u\n", peer.rtt);
107         printf("rtt_dev:         %u\n", peer.rtt_dev);
108         printf("timeout:         %u.%06u\n", peer.timeout.sec,
109                peer.timeout.usec);
110         printf("nSent:           %u\n", peer.nSent);
111         printf("reSends:         %u\n", peer.reSends);
112         printf("inPacketSkew:    %u\n", peer.inPacketSkew);
113         printf("outPacketSkew:   %u\n", peer.outPacketSkew);
114         printf("rateFlag:        %u\n", peer.rateFlag);
115         printf("natMTU:          %u\n", peer.natMTU);
116         printf("maxMTU:          %u\n", peer.maxMTU);
117         printf("maxDgramPackets: %u\n", peer.maxDgramPackets);
118         printf("ifDgramPackets:  %u\n", peer.ifDgramPackets);
119         printf("MTU:             %u\n", peer.MTU);
120         printf("cwind:           %u\n", peer.cwind);
121         printf("nDgramPackets:   %u\n", peer.nDgramPackets);
122         printf("congestSeq:      %u\n", peer.congestSeq);
123         printf("bytesSent:       (%u.%u)\n", hgethi(peer.bytesSent),
124                hgetlo(peer.bytesSent));
125         printf("bytesReceived:   (%u.%u)\n", hgethi(peer.bytesReceived),
126                hgetlo(peer.bytesReceived));
127     }
128     if (st != ADMITERATORDONE) {
129         fprintf(stderr, "util_RXDebugPeersNext, status %d\n", st);
130         exit(1);
131     }
132     printf("\n");
133
134     rc = util_RXDebugPeersDone(iterator, &st);
135     if (!rc) {
136         fprintf(stderr, "util_RXDebugPeersDone, status %d\n", st);
137         exit(1);
138     }
139
140     rc = afsclient_RXDebugClose(handle, &st);
141     if (!rc) {
142         fprintf(stderr, "afsclient_RXDebugClose, status %d\n", st);
143         exit(1);
144     }
145
146     exit(0);
147 }