2
* $Id: rsysinfo.c,v 1.4 2005/09/07 08:07:28 afm Exp $
3
* rsysinfo version 3.03 rpc ruptime client for use with rpc.rstatd 3.03
4
* Copyright (C) 1995 Adam Migus, Memorial University of Newfoundland
6
* Copyright (C) 2001 Andreas Klingler, University of Erlangen-Nuernberg
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 1, or (at your option)
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
* If you make modifications to the source, I would be happy to have
23
* them to include in future releases. Feel free to send them to:
28
**************************************************************************/
32
#include <sys/socket.h>
36
#include <netinet/in.h>
37
#include <arpa/inet.h>
45
static char *id = "@(#) $Id: rsysinfo.c,v 1.4 2005/09/07 08:07:28 afm Exp $";
46
static char *version0 = "@(#)rsysinfo version 3.06 (c) Andreas Klingler 3/5/2001 based on\n";
47
char *version = "@(#)rsysinfo version 3.03 Copyright (Adam Migus) 1/9/96\n";
50
int rsysinfo_answer_v3(struct statstime *replyp,
51
struct sockaddr_in *raddrp)
55
struct statstime *host_stat;
58
struct tm host_uptime;
62
host_stat = (statstime *)replyp;
64
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
65
sizeof(struct in_addr), AF_INET);
67
host = (char *)hp->h_name;
69
host = (char *)inet_ntoa(raddrp->sin_addr);
72
tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
73
host_time = *tmp_time;
75
host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
77
tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
78
host_uptime = *tmp_time;
81
if (host_uptime.tm_yday != 0)
82
sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
83
(host_uptime.tm_yday > 1) ? "s" : "");
87
if (host_uptime.tm_hour != 0)
88
sprintf(hours_buf, "%2d:%02d, ",
89
host_uptime.tm_hour, host_uptime.tm_min);
91
if (host_uptime.tm_min != 0)
92
sprintf(hours_buf, "%2d mins, ", host_uptime.tm_min);
97
printf("System Information for: %s\n",host);
98
printf("uptime: %s%sload average: %.2f %.2f %.2f\n",
99
days_buf, hours_buf, host_stat->avenrun[0]/256.0,
100
host_stat->avenrun[1]/256.0, host_stat->avenrun[2]/256.0);
102
printf("cpu usage (jiffies): user %d nice %d system %d idle %d\n",
103
host_stat->cp_time[0], host_stat->cp_time[1],
104
host_stat->cp_time[2], host_stat->cp_time[3]);
106
printf("page in: %d page out: %d swap in: %d swap out: %d\n",
107
host_stat->v_pgpgin, host_stat->v_pgpgout,
108
host_stat->v_pswpin, host_stat->v_pswpout);
109
printf("intr: %d context switches: %d\n",
110
host_stat->v_intr, host_stat->v_swtch);
111
printf ("disks: %d %d %d %d\n",
112
host_stat->dk_xfer[0], host_stat->dk_xfer[1],
113
host_stat->dk_xfer[2], host_stat->dk_xfer[3]);
114
printf("ethernet: rx: %u rx-err: %u\n"
115
" tx: %u tx-err: %u collisions: %u\n",
116
host_stat->if_ipackets, host_stat->if_ierrors,
117
host_stat->if_opackets, host_stat->if_oerrors,
118
host_stat->if_collisions);
123
int pointopoint_v3(server_addr)
124
struct sockaddr_in *server_addr;
126
struct statstime host_stat;
127
struct timeval pertry_timeout, total_timeout;
128
enum clnt_stat clnt_stat;
129
int sock=RPC_ANYSOCK;
132
pertry_timeout.tv_sec = 3;
133
pertry_timeout.tv_usec = 0;
134
total_timeout.tv_sec = 10;
135
total_timeout.tv_usec = 0;
137
if((client = clntudp_create(server_addr, RSTATPROG, RSTATVERS_TIME,
138
pertry_timeout, &sock)) == NULL) {
142
clnt_stat = clnt_call(client, RSTATPROC_STATS, (xdrproc_t) xdr_void, 0,
143
(xdrproc_t)xdr_statstime, (void *)&host_stat,
146
if(clnt_stat == RPC_SUCCESS) {
147
rsysinfo_answer_v3(&host_stat, server_addr);
148
clnt_destroy(client);
153
clnt_destroy(client);
161
printf("usage: %s \"host\" | -v\n"\
162
"\t-v\tprint version and exit\n", program_name);
165
int main(int argc, char **argv)
168
struct sockaddr_in server_addr;
171
program_name = rindex(argv[0],'/');
173
program_name = argv[0];
182
while((c = getopt(argc,argv,"h?v")) != EOF)
196
if((hp = gethostbyname(argv[1])) == NULL) {
197
fprintf(stderr,"%s: cannot get hostname %s\n",program_name,argv[1]);
201
bcopy(hp->h_addr,(caddr_t)&server_addr.sin_addr, hp->h_length);
202
server_addr.sin_family = AF_INET;
203
server_addr.sin_port = 0;
205
if(pointopoint_v3(&server_addr) == 1)
207
clnt_pcreateerror(program_name);