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