1/*-
2 * Copyright (c) 1993, John Brezak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 18 unchanged lines hidden (view full) ---
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char rcsid[] = "$Id$";
36#endif /* not lint */
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <time.h>
42#include <sys/param.h>
43#include <sys/socket.h>
44#include <netdb.h>
45#include <rpc/rpc.h>
46#include <arpa/inet.h>
47
48#undef FSHIFT /* Use protocol's shift and scale values */
49#undef FSCALE
50#include <rpcsvc/rstat.h>
51
52#define HOST_WIDTH 15
53
54char *argv0;
55
56struct host_list {
57 struct host_list *next;
58 struct in_addr addr;
59} *hosts;
60
61int search_host(struct in_addr addr)
62{
63 struct host_list *hp;
--- 7 unchanged lines hidden (view full) ---
71 }
72 return(0);
73}
74
75void remember_host(struct in_addr addr)
76{
77 struct host_list *hp;
78
79 if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
80 fprintf(stderr, "%s: no memory.\n", argv0);
81 exit(1);
82 }
83 hp->addr.s_addr = addr.s_addr;
84 hp->next = hosts;
85 hosts = hp;
86}
87
88rstat_reply(char *replyp, struct sockaddr_in *raddrp)
89{
90 struct tm *tmp_time;
91 struct tm host_time;
92 struct tm host_uptime;
93 char days_buf[16];
94 char hours_buf[16];
95 struct hostent *hp;
--- 49 unchanged lines hidden (view full) ---
145 (double)host_stat->avenrun[0]/FSCALE,
146 (double)host_stat->avenrun[1]/FSCALE,
147 (double)host_stat->avenrun[2]/FSCALE);
148
149 remember_host(raddrp->sin_addr);
150 return(0);
151}
152
153onehost(char *host)
154{
155 CLIENT *rstat_clnt;
156 statstime host_stat;
157 struct sockaddr_in addr;
158 struct hostent *hp;
159 struct timeval tv;
160
161 hp = gethostbyname(host);
162 if (hp == NULL) {
163 fprintf(stderr, "%s: unknown host \"%s\"\n",
164 argv0, host);
165 return(-1);
166 }
167
168 rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
169 if (rstat_clnt == NULL) {
170 fprintf(stderr, "%s: %s %s", argv0, host, clnt_spcreateerror(""));
171 return(-1);
172 }
173
174 bzero((char *)&host_stat, sizeof(host_stat));
175 tv.tv_sec = 15; /* XXX ??? */
176 tv.tv_usec = 0;
177 if (clnt_call(rstat_clnt, RSTATPROC_STATS, xdr_void, NULL, xdr_statstime, &host_stat, tv) != RPC_SUCCESS) {
178 fprintf(stderr, "%s: %s: %s\n", argv0, host, clnt_sperror(rstat_clnt, host));
179 return(-1);
180 }
181
182 addr.sin_addr.s_addr = *(int *)hp->h_addr;
183 rstat_reply((char *)&host_stat, &addr);
184}
185
186allhosts()
187{
188 statstime host_stat;
189 enum clnt_stat clnt_stat;
190
191 clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS,
192 xdr_void, NULL,
193 xdr_statstime, &host_stat, rstat_reply);
194 if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
195 fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
196 exit(1);
197 }
198}
199
200usage()
201{
202 fprintf(stderr, "Usage: %s [hosts ...]\n", argv0);
203 exit(1);
204}
205
206main(int argc, char *argv[])
207{
208 int ch;
209 extern int optind;
210
211 if (!(argv0 = rindex(argv[0], '/')))
212 argv0 = argv[0];
213 else
214 argv0++;
215
216 while ((ch = getopt(argc, argv, "?")) != -1)
217 switch (ch) {
218 default:
219 usage();
220 /*NOTREACHED*/
221 }
222
223 setlinebuf(stdout);
224 if (argc == optind)
225 allhosts();
226 else {
227 for (; optind < argc; optind++)
228 (void) onehost(argv[optind]);
229 }
230 exit(0);
231}
2 * Copyright (c) 1993, John Brezak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 18 unchanged lines hidden (view full) ---
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char rcsid[] = "$Id$";
36#endif /* not lint */
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <time.h>
42#include <sys/param.h>
43#include <sys/socket.h>
44#include <netdb.h>
45#include <rpc/rpc.h>
46#include <arpa/inet.h>
47
48#undef FSHIFT /* Use protocol's shift and scale values */
49#undef FSCALE
50#include <rpcsvc/rstat.h>
51
52#define HOST_WIDTH 15
53
54char *argv0;
55
56struct host_list {
57 struct host_list *next;
58 struct in_addr addr;
59} *hosts;
60
61int search_host(struct in_addr addr)
62{
63 struct host_list *hp;
--- 7 unchanged lines hidden (view full) ---
71 }
72 return(0);
73}
74
75void remember_host(struct in_addr addr)
76{
77 struct host_list *hp;
78
79 if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
80 fprintf(stderr, "%s: no memory.\n", argv0);
81 exit(1);
82 }
83 hp->addr.s_addr = addr.s_addr;
84 hp->next = hosts;
85 hosts = hp;
86}
87
88rstat_reply(char *replyp, struct sockaddr_in *raddrp)
89{
90 struct tm *tmp_time;
91 struct tm host_time;
92 struct tm host_uptime;
93 char days_buf[16];
94 char hours_buf[16];
95 struct hostent *hp;
--- 49 unchanged lines hidden (view full) ---
145 (double)host_stat->avenrun[0]/FSCALE,
146 (double)host_stat->avenrun[1]/FSCALE,
147 (double)host_stat->avenrun[2]/FSCALE);
148
149 remember_host(raddrp->sin_addr);
150 return(0);
151}
152
153onehost(char *host)
154{
155 CLIENT *rstat_clnt;
156 statstime host_stat;
157 struct sockaddr_in addr;
158 struct hostent *hp;
159 struct timeval tv;
160
161 hp = gethostbyname(host);
162 if (hp == NULL) {
163 fprintf(stderr, "%s: unknown host \"%s\"\n",
164 argv0, host);
165 return(-1);
166 }
167
168 rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
169 if (rstat_clnt == NULL) {
170 fprintf(stderr, "%s: %s %s", argv0, host, clnt_spcreateerror(""));
171 return(-1);
172 }
173
174 bzero((char *)&host_stat, sizeof(host_stat));
175 tv.tv_sec = 15; /* XXX ??? */
176 tv.tv_usec = 0;
177 if (clnt_call(rstat_clnt, RSTATPROC_STATS, xdr_void, NULL, xdr_statstime, &host_stat, tv) != RPC_SUCCESS) {
178 fprintf(stderr, "%s: %s: %s\n", argv0, host, clnt_sperror(rstat_clnt, host));
179 return(-1);
180 }
181
182 addr.sin_addr.s_addr = *(int *)hp->h_addr;
183 rstat_reply((char *)&host_stat, &addr);
184}
185
186allhosts()
187{
188 statstime host_stat;
189 enum clnt_stat clnt_stat;
190
191 clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS,
192 xdr_void, NULL,
193 xdr_statstime, &host_stat, rstat_reply);
194 if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
195 fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
196 exit(1);
197 }
198}
199
200usage()
201{
202 fprintf(stderr, "Usage: %s [hosts ...]\n", argv0);
203 exit(1);
204}
205
206main(int argc, char *argv[])
207{
208 int ch;
209 extern int optind;
210
211 if (!(argv0 = rindex(argv[0], '/')))
212 argv0 = argv[0];
213 else
214 argv0++;
215
216 while ((ch = getopt(argc, argv, "?")) != -1)
217 switch (ch) {
218 default:
219 usage();
220 /*NOTREACHED*/
221 }
222
223 setlinebuf(stdout);
224 if (argc == optind)
225 allhosts();
226 else {
227 for (; optind < argc; optind++)
228 (void) onehost(argv[optind]);
229 }
230 exit(0);
231}