* Copyright (c) 1993, John Brezak
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char rcsid
[] = "$Id: rusers.c,v 1.4 1993/08/02 17:55:46 mycroft Exp $";
#include <rpcsvc/rnusers.h>
#define MAX_INT 0x7fffffff
int search_host(struct in_addr addr
)
for (hp
= hosts
; hp
!= NULL
; hp
= hp
->next
) {
if (hp
->addr
.s_addr
== addr
.s_addr
)
void remember_host(struct in_addr addr
)
if (!(hp
= (struct host_list
*)malloc(sizeof(struct host_list
)))) {
fprintf(stderr
, "%s: no memory.\n", argv0
);
hp
->addr
.s_addr
= addr
.s_addr
;
rusers_reply(char *replyp
, struct sockaddr_in
*raddrp
)
char date
[32], idle_time
[64], remote
[64];
utmpidlearr
*up
= (utmpidlearr
*)replyp
;
int days
, hours
, minutes
, seconds
;
if (search_host(raddrp
->sin_addr
))
if (!allopt
&& !up
->utmpidlearr_len
)
hp
= gethostbyaddr((char *)&raddrp
->sin_addr
.s_addr
,
sizeof(struct in_addr
), AF_INET
);
host
= inet_ntoa(raddrp
->sin_addr
);
printf("%-*s ", HOST_WIDTH
, host
);
for (x
= 0; x
< up
->utmpidlearr_len
; x
++) {
&(ctime((time_t *)&(up
->utmpidlearr_val
[x
].ui_utmp
.ut_time
))[4]),
idle
= up
->utmpidlearr_val
[x
].ui_idle
;
sprintf(idle_time
, " :%02d", idle
);
days
= seconds
/(60*60*24);
sprintf(idle_time
, "%d:%02d",
sprintf(idle_time
, "%d:%02d:%02d",
hours
, minutes
, seconds
);
sprintf(idle_time
, "%d days, %d:%02d:%02d",
days
, hours
, minutes
, seconds
);
strncpy(remote
, up
->utmpidlearr_val
[x
].ui_utmp
.ut_host
, sizeof(remote
)-1);
sprintf(remote
, "(%.16s)", up
->utmpidlearr_val
[x
].ui_utmp
.ut_host
);
printf("%-8.8s %*s:%-*.*s %-12.12s %6s %.18s\n",
up
->utmpidlearr_val
[x
].ui_utmp
.ut_name
,
LINE_WIDTH
, LINE_WIDTH
, up
->utmpidlearr_val
[x
].ui_utmp
.ut_line
,
up
->utmpidlearr_val
[x
].ui_utmp
.ut_name
);
remember_host(raddrp
->sin_addr
);
hp
= gethostbyname(host
);
fprintf(stderr
, "%s: unknown host \"%s\"\n",
rusers_clnt
= clnt_create(host
, RUSERSPROG
, RUSERSVERS_IDLE
, "udp");
if (rusers_clnt
== NULL
) {
clnt_pcreateerror(argv0
);
bzero((char *)&up
, sizeof(up
));
if (clnt_call(rusers_clnt
, RUSERSPROC_NAMES
, xdr_void
, NULL
, xdr_utmpidlearr
, &up
, NULL
) != RPC_SUCCESS
) {
clnt_perror(rusers_clnt
, argv0
);
addr
.sin_addr
.s_addr
= *(int *)hp
->h_addr
;
rusers_reply((char *)&up
, &addr
);
enum clnt_stat clnt_stat
;
bzero((char *)&up
, sizeof(up
));
clnt_stat
= clnt_broadcast(RUSERSPROG
, RUSERSVERS_IDLE
, RUSERSPROC_NAMES
,
xdr_utmpidlearr
, &up
, rusers_reply
);
if (clnt_stat
!= RPC_SUCCESS
&& clnt_stat
!= RPC_TIMEDOUT
) {
fprintf(stderr
, "%s: %s\n", argv0
, clnt_sperrno(clnt_stat
));
fprintf(stderr
, "Usage: %s [-la] [hosts ...]\n", argv0
);
main(int argc
, char *argv
[])
if (!(argv0
= rindex(argv
[0], '/')))
while ((ch
= getopt(argc
, argv
, "al")) != -1)
for (; optind
< argc
; optind
++)
(void) onehost(argv
[optind
]);