de-ansify

format better, now readable in most cases on 80-char wide screens
and it looks pretty.
This commit is contained in:
deraadt 1993-11-10 04:19:03 +00:00
parent b52aae9d1e
commit 85889786ad
1 changed files with 135 additions and 123 deletions

View File

@ -32,7 +32,7 @@
*/
#ifndef lint
static char rcsid[] = "$Id: rusers.c,v 1.4 1993/08/02 17:55:46 mycroft Exp $";
static char rcsid[] = "$Id: rusers.c,v 1.5 1993/11/10 04:19:03 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
@ -47,7 +47,7 @@ static char rcsid[] = "$Id: rusers.c,v 1.4 1993/08/02 17:55:46 mycroft Exp $";
#define MAX_INT 0x7fffffff
#define HOST_WIDTH 20
#define LINE_WIDTH 15
#define LINE_WIDTH 8
char *argv0;
int longopt;
@ -58,7 +58,9 @@ struct host_list {
struct in_addr addr;
} *hosts;
int search_host(struct in_addr addr)
int
search_host(addr)
struct in_addr addr;
{
struct host_list *hp;
@ -72,7 +74,9 @@ int search_host(struct in_addr addr)
return(0);
}
void remember_host(struct in_addr addr)
void
remember_host(addr)
struct in_addr addr;
{
struct host_list *hp;
@ -85,123 +89,129 @@ void remember_host(struct in_addr addr)
hosts = hp;
}
rusers_reply(char *replyp, struct sockaddr_in *raddrp)
rusers_reply(replyp, raddrp)
char *replyp;
struct sockaddr_in *raddrp;
{
int x, idle;
char date[32], idle_time[64], remote[64];
struct hostent *hp;
utmpidlearr *up = (utmpidlearr *)replyp;
char *host;
int days, hours, minutes, seconds;
int x, idle;
char date[32], idle_time[64], remote[64];
struct hostent *hp;
utmpidlearr *up = (utmpidlearr *)replyp;
char *host;
int days, hours, minutes, seconds;
if (search_host(raddrp->sin_addr))
return(0);
if (!allopt && !up->utmpidlearr_len)
return(0);
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
sizeof(struct in_addr), AF_INET);
if (hp)
host = hp->h_name;
else
host = inet_ntoa(raddrp->sin_addr);
if (!longopt)
printf("%-*s ", HOST_WIDTH, host);
for (x = 0; x < up->utmpidlearr_len; x++) {
strncpy(date,
&(ctime((time_t *)&(up->utmpidlearr_val[x].ui_utmp.ut_time))[4]),
sizeof(date)-1);
if (!allopt && !up->utmpidlearr_len)
return(0);
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
sizeof(struct in_addr), AF_INET);
if (hp)
host = hp->h_name;
else
host = inet_ntoa(raddrp->sin_addr);
if (!longopt)
printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host);
for (x = 0; x < up->utmpidlearr_len; x++) {
strncpy(date,
&(ctime((time_t *)&(up->utmpidlearr_val[x].ui_utmp.ut_time))[4]),
sizeof(date)-1);
idle = up->utmpidlearr_val[x].ui_idle;
sprintf(idle_time, " :%02d", idle);
if (idle == MAX_INT)
strcpy(idle_time, "??");
else if (idle == 0)
strcpy(idle_time, "");
else {
seconds = idle;
days = seconds/(60*60*24);
seconds %= (60*60*24);
hours = seconds/(60*60);
seconds %= (60*60);
minutes = seconds/60;
seconds %= 60;
if (idle > 60)
sprintf(idle_time, "%d:%02d",
minutes, seconds);
if (idle >= (60*60))
sprintf(idle_time, "%d:%02d:%02d",
hours, minutes, seconds);
if (idle >= (24*60*60))
sprintf(idle_time, "%d days, %d:%02d:%02d",
days, hours, minutes, seconds);
}
idle = up->utmpidlearr_val[x].ui_idle;
sprintf(idle_time, " :%02d", idle);
if (idle == MAX_INT)
strcpy(idle_time, "??");
else if (idle == 0)
strcpy(idle_time, "");
else {
seconds = idle;
days = seconds/(60*60*24);
seconds %= (60*60*24);
hours = seconds/(60*60);
seconds %= (60*60);
minutes = seconds/60;
seconds %= 60;
if (idle > 60)
sprintf(idle_time, "%2d:%02d",
minutes, seconds);
if (idle >= (60*60))
sprintf(idle_time, "%2d:%02d:%02d",
hours, minutes, seconds);
if (idle >= (24*60*60))
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);
if (strlen(remote) != 0)
sprintf(remote, "(%.16s)", up->utmpidlearr_val[x].ui_utmp.ut_host);
strncpy(remote, up->utmpidlearr_val[x].ui_utmp.ut_host,
sizeof(remote)-1);
if (strlen(remote) != 0)
sprintf(remote, "(%.16s)",
up->utmpidlearr_val[x].ui_utmp.ut_host);
if (longopt)
printf("%-8.8s %*s:%-*.*s %-12.12s %6s %.18s\n",
up->utmpidlearr_val[x].ui_utmp.ut_name,
HOST_WIDTH, host,
LINE_WIDTH, LINE_WIDTH, up->utmpidlearr_val[x].ui_utmp.ut_line,
date,
idle_time,
remote
);
else
printf("%s ",
up->utmpidlearr_val[x].ui_utmp.ut_name);
}
if (!longopt)
putchar('\n');
if (longopt)
printf("%-8.8s %-*.*s:%-*.*s %-12.12s %8s %.18s\n",
up->utmpidlearr_val[x].ui_utmp.ut_name,
HOST_WIDTH, HOST_WIDTH, host,
LINE_WIDTH, LINE_WIDTH,
up->utmpidlearr_val[x].ui_utmp.ut_line,
date,
idle_time,
remote);
else
printf("%s ",
up->utmpidlearr_val[x].ui_utmp.ut_name);
}
if (!longopt)
putchar('\n');
remember_host(raddrp->sin_addr);
return(0);
}
onehost(char *host)
onehost(host)
char *host;
{
utmpidlearr up;
CLIENT *rusers_clnt;
struct sockaddr_in addr;
struct hostent *hp;
hp = gethostbyname(host);
if (hp == NULL) {
fprintf(stderr, "%s: unknown host \"%s\"\n",
argv0, host);
exit(1);
}
utmpidlearr up;
CLIENT *rusers_clnt;
struct sockaddr_in addr;
struct hostent *hp;
hp = gethostbyname(host);
if (hp == NULL) {
fprintf(stderr, "%s: unknown host \"%s\"\n",
argv0, host);
exit(1);
}
rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
if (rusers_clnt == NULL) {
clnt_pcreateerror(argv0);
exit(1);
}
rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
if (rusers_clnt == NULL) {
clnt_pcreateerror(argv0);
exit(1);
}
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);
exit(1);
}
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rusers_reply((char *)&up, &addr);
if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL,
xdr_utmpidlearr, &up, NULL) != RPC_SUCCESS) {
clnt_perror(rusers_clnt, argv0);
exit(1);
}
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rusers_reply((char *)&up, &addr);
}
allhosts()
{
utmpidlearr up;
utmpidlearr up;
enum clnt_stat clnt_stat;
bzero((char *)&up, sizeof(up));
clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES,
xdr_void, NULL,
xdr_utmpidlearr, &up, rusers_reply);
clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE,
RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr,
&up, rusers_reply);
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
exit(1);
@ -210,40 +220,42 @@ allhosts()
usage()
{
fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
exit(1);
fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
exit(1);
}
main(int argc, char *argv[])
main(argc, argv)
int argc;
char *argv[];
{
int ch;
extern int optind;
if (!(argv0 = rindex(argv[0], '/')))
argv0 = argv[0];
else
argv0++;
int ch;
extern int optind;
if (!(argv0 = rindex(argv[0], '/')))
argv0 = argv[0];
else
argv0++;
while ((ch = getopt(argc, argv, "al")) != -1)
switch (ch) {
case 'a':
allopt++;
break;
case 'l':
longopt++;
break;
default:
usage();
/*NOTREACHED*/
}
while ((ch = getopt(argc, argv, "al")) != -1)
switch (ch) {
case 'a':
allopt++;
break;
case 'l':
longopt++;
break;
default:
usage();
/*NOTREACHED*/
}
setlinebuf(stdout);
setlinebuf(stdout);
if (argc == optind)
allhosts();
else {
for (; optind < argc; optind++)
(void) onehost(argv[optind]);
}
exit(0);
exit(0);
}