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