Import Upstream version 1.8.5
[hcoop/debian/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 #include <roken.h>
20
21 #ifdef IGNORE_SOME_GCC_WARNINGS
22 # pragma GCC diagnostic warning "-Wformat"
23 #endif
24
25 #ifdef AFS_NT40_ENV
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 void
37 Usage(void)
38 {
39 fprintf(stderr, "Usage: rxdebug_peers <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 void *iterator;
69 struct rx_debugPeer peer;
70 afs_uint32 supportedValues;
71
72 ParseArgs(argc, argv, &srvrName, &srvrPort);
73
74 rc = afsclient_Init(&st);
75 if (!rc) {
76 fprintf(stderr, "afsclient_Init, status %d\n", st);
77 exit(1);
78 }
79
80 rc = afsclient_RXDebugOpenPort(srvrName, srvrPort, &handle, &st);
81 if (!rc) {
82 fprintf(stderr, "afsclient_RXDebugOpenPort, status %d\n", st);
83 exit(1);
84 }
85
86 rc = util_RXDebugPeersBegin(handle, &iterator, &st);
87 if (!rc) {
88 fprintf(stderr, "util_RXDebugPeersBegin, status %d\n", st);
89 exit(1);
90 }
91
92 while (util_RXDebugPeersNext(iterator, &peer, &supportedValues, &st)) {
93 printf("\n");
94 printf("host: %u.%u.%u.%u\n", (peer.host >> 24) & 0xff,
95 (peer.host >> 16) & 0xff, (peer.host >> 8) & 0xff,
96 peer.host & 0xff);
97 printf("port: %u\n", peer.port);
98 printf("ifMTU: %u\n", peer.ifMTU);
99 printf("idleWhen: %u\n", peer.idleWhen);
100 printf("refCount: %u\n", peer.refCount);
101 printf("burstSize: %u\n", peer.burstSize);
102 printf("burst: %u\n", peer.burst);
103 printf("burstWait: %u.%06u\n", peer.burstWait.sec,
104 peer.burstWait.usec);
105 printf("rtt: %u\n", peer.rtt);
106 printf("rtt_dev: %u\n", peer.rtt_dev);
107 printf("timeout: %u.%06u\n", peer.timeout.sec,
108 peer.timeout.usec);
109 printf("nSent: %u\n", peer.nSent);
110 printf("reSends: %u\n", peer.reSends);
111 printf("inPacketSkew: %u\n", peer.inPacketSkew);
112 printf("outPacketSkew: %u\n", peer.outPacketSkew);
113 printf("rateFlag: %u\n", peer.rateFlag);
114 printf("natMTU: %u\n", peer.natMTU);
115 printf("maxMTU: %u\n", peer.maxMTU);
116 printf("maxDgramPackets: %u\n", peer.maxDgramPackets);
117 printf("ifDgramPackets: %u\n", peer.ifDgramPackets);
118 printf("MTU: %u\n", peer.MTU);
119 printf("cwind: %u\n", peer.cwind);
120 printf("nDgramPackets: %u\n", peer.nDgramPackets);
121 printf("congestSeq: %u\n", peer.congestSeq);
122 printf("bytesSent: (%u.%u)\n", hgethi(peer.bytesSent),
123 hgetlo(peer.bytesSent));
124 printf("bytesReceived: (%u.%u)\n", hgethi(peer.bytesReceived),
125 hgetlo(peer.bytesReceived));
126 }
127 if (st != ADMITERATORDONE) {
128 fprintf(stderr, "util_RXDebugPeersNext, status %d\n", st);
129 exit(1);
130 }
131 printf("\n");
132
133 rc = util_RXDebugPeersDone(iterator, &st);
134 if (!rc) {
135 fprintf(stderr, "util_RXDebugPeersDone, status %d\n", st);
136 exit(1);
137 }
138
139 rc = afsclient_RXDebugClose(handle, &st);
140 if (!rc) {
141 fprintf(stderr, "afsclient_RXDebugClose, status %d\n", st);
142 exit(1);
143 }
144
145 exit(0);
146 }