summaryrefslogtreecommitdiffstats
path: root/usr.bin/rusers/rusers.c
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-08 12:12:54 +0000
committercharnier <charnier@FreeBSD.org>1997-08-08 12:12:54 +0000
commit45f7e3616631e5268fbcd09c8f5a5b1c883442fd (patch)
treeadc769210cd1852ac9c5ed17c68d0f673a73b753 /usr.bin/rusers/rusers.c
parent2ae4bfe0cf7c10b991b2c8c56db256ed69aedfb8 (diff)
downloadFreeBSD-src-45f7e3616631e5268fbcd09c8f5a5b1c883442fd.zip
FreeBSD-src-45f7e3616631e5268fbcd09c8f5a5b1c883442fd.tar.gz
Remove argv0, cosmetic in usage(), use err(3), add Xr to rwho(1) and users(1).
Diffstat (limited to 'usr.bin/rusers/rusers.c')
-rw-r--r--usr.bin/rusers/rusers.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c
index 3d7b9a5..a3de952 100644
--- a/usr.bin/rusers/rusers.c
+++ b/usr.bin/rusers/rusers.c
@@ -32,23 +32,27 @@
*/
#ifndef lint
-static char rcsid[] = "$Id$";
+static const char rcsid[] =
+ "$Id: rusers.c,v 1.5 1997/02/22 19:56:52 peter Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
+#include <err.h>
#include <netdb.h>
#include <stdio.h>
+#include <stdlib.h>
#include <strings.h>
+#include <unistd.h>
#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
#include <arpa/inet.h>
#include <rpcsvc/rnusers.h>
#define MAX_INT 0x7fffffff
#define HOST_WIDTH 20
#define LINE_WIDTH 15
-char *argv0;
int longopt;
int allopt;
@@ -58,7 +62,8 @@ struct host_list {
struct in_addr addr;
} *hosts;
-int search_host(struct in_addr addr)
+int
+search_host(struct in_addr addr)
{
struct host_list *hp;
@@ -72,19 +77,19 @@ int search_host(struct in_addr addr)
return(0);
}
-void remember_host(struct in_addr addr)
+void
+remember_host(struct in_addr addr)
{
struct host_list *hp;
- if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
- fprintf(stderr, "%s: no memory.\n", argv0);
- exit(1);
- }
+ if (!(hp = (struct host_list *)malloc(sizeof(struct host_list))))
+ errx(1, "no memory");
hp->addr.s_addr = addr.s_addr;
hp->next = hosts;
hosts = hp;
}
+int
rusers_reply(char *replyp, struct sockaddr_in *raddrp)
{
int x, idle;
@@ -164,69 +169,57 @@ rusers_reply(char *replyp, struct sockaddr_in *raddrp)
return(0);
}
+void
onehost(char *host)
{
utmpidlearr up;
CLIENT *rusers_clnt;
struct sockaddr_in addr;
struct hostent *hp;
- struct timeval tv;
+ struct timeval tv;
hp = gethostbyname(host);
- if (hp == NULL) {
- fprintf(stderr, "%s: unknown host \"%s\"\n",
- argv0, host);
- exit(1);
- }
+ if (hp == NULL)
+ errx(1, "unknown host \"%s\"", host);
rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
- if (rusers_clnt == NULL) {
- clnt_pcreateerror(argv0);
- exit(1);
- }
+ if (rusers_clnt == NULL)
+ errx(1, "%s", clnt_spcreateerror(""));
bzero((char *)&up, sizeof(up));
tv.tv_sec = 15; /* XXX ?? */
tv.tv_usec = 0;
- if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, tv) != RPC_SUCCESS) {
- clnt_perror(rusers_clnt, argv0);
- exit(1);
- }
+ if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, tv) != RPC_SUCCESS)
+ errx(1, "%s", clnt_sperror(rusers_clnt, ""));
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rusers_reply((char *)&up, &addr);
}
+void
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);
- if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
- fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
- exit(1);
- }
+ if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
+ errx(1, "%s", clnt_sperrno(clnt_stat));
}
+static void
usage()
{
- fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
+ fprintf(stderr, "usage: rusers [-la] [hosts ...]\n");
exit(1);
}
+int
main(int argc, char *argv[])
{
int ch;
- extern int optind;
-
- if (!(argv0 = rindex(argv[0], '/')))
- argv0 = argv[0];
- else
- argv0++;
-
while ((ch = getopt(argc, argv, "al")) != -1)
switch (ch) {
OpenPOWER on IntegriCloud