macos103-20031024
[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 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_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     int i;
72
73     ParseArgs(argc, argv, &srvrName, &srvrPort);
74
75     rc = afsclient_Init(&st);
76     if (!rc) {
77         fprintf(stderr, "afsclient_Init, status %d\n", st);
78         exit(1);
79     }
80
81     rc = afsclient_RXDebugOpenPort(srvrName, srvrPort, &handle, &st);
82     if (!rc) {
83         fprintf(stderr, "afsclient_RXDebugOpenPort, status %d\n", st);
84         exit(1);
85     }
86
87     rc = util_RXDebugPeersBegin(handle, &iterator, &st);
88     if (!rc) {
89         fprintf(stderr, "util_RXDebugPeersBegin, status %d\n", st);
90         exit(1);
91     }
92
93     while (util_RXDebugPeersNext(iterator, &peer, &supportedValues, &st)) {
94         printf("\n");
95         printf("host:            %u.%u.%u.%u\n", (peer.host >> 24) & 0xff,
96                (peer.host >> 16) & 0xff, (peer.host >> 8) & 0xff,
97                peer.host & 0xff);
98         printf("port:            %u\n", peer.port);
99         printf("ifMTU:           %u\n", peer.ifMTU);
100         printf("idleWhen:        %u\n", peer.idleWhen);
101         printf("refCount:        %u\n", peer.refCount);
102         printf("burstSize:       %u\n", peer.burstSize);
103         printf("burst:           %u\n", peer.burst);
104         printf("burstWait:       %u\n", peer.burstWait);
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 }