Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / rpc.statd / test.c
blob7383fc838fc46577672ab7940f78f648e1e3bf99
1 /* $NetBSD: test.c,v 1.1 1997/03/10 06:28:32 scottr Exp $ */
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: statd.c,v 1.4 1997/10/17 13:21:06 lukem Exp $");
6 #endif
8 #include <stdio.h>
9 #include <rpc/rpc.h>
10 #include <rpcsvc/sm_inter.h>
13 /* Default timeout can be changed using clnt_control() */
14 static struct timeval TIMEOUT = {25, 0};
16 struct sm_stat_res *
17 sm_stat_1(argp, clnt)
18 struct sm_name *argp;
19 CLIENT *clnt;
21 static struct sm_stat_res res;
23 bzero((char *) &res, sizeof(res));
24 if (clnt_call(clnt, SM_STAT, xdr_sm_name, argp, xdr_sm_stat_res,
25 &res, TIMEOUT) != RPC_SUCCESS)
26 return (NULL);
27 return (&res);
31 struct sm_stat_res *
32 sm_mon_1(argp, clnt)
33 struct mon *argp;
34 CLIENT *clnt;
36 static struct sm_stat_res res;
38 bzero((char *) &res, sizeof(res));
39 if (clnt_call(clnt, SM_MON, xdr_mon, argp, xdr_sm_stat_res,
40 &res, TIMEOUT) != RPC_SUCCESS)
41 return (NULL);
42 return (&res);
46 struct sm_stat *
47 sm_unmon_1(argp, clnt)
48 struct mon_id *argp;
49 CLIENT *clnt;
51 static struct sm_stat res;
53 bzero((char *) &res, sizeof(res));
54 if (clnt_call(clnt, SM_UNMON, xdr_mon_id, argp, xdr_sm_stat,
55 &res, TIMEOUT) != RPC_SUCCESS)
56 return (NULL);
57 return (&res);
61 struct sm_stat *
62 sm_unmon_all_1(argp, clnt)
63 struct my_id *argp;
64 CLIENT *clnt;
66 static struct sm_stat res;
68 bzero((char *) &res, sizeof(res));
69 if (clnt_call(clnt, SM_UNMON_ALL, xdr_my_id, argp, xdr_sm_stat,
70 &res, TIMEOUT) != RPC_SUCCESS)
71 return (NULL);
72 return (&res);
76 void *
77 sm_simu_crash_1(argp, clnt)
78 void *argp;
79 CLIENT *clnt;
81 static char res;
83 bzero((char *) &res, sizeof(res));
84 if (clnt_call(clnt, SM_SIMU_CRASH, xdr_void, argp, xdr_void,
85 &res, TIMEOUT) != RPC_SUCCESS)
86 return (NULL);
87 return ((void *) &res);
91 int
92 main(argc, argv)
93 int argc;
94 char **argv;
96 CLIENT *cli;
97 char dummy;
98 void *out;
99 struct mon mon;
101 if (argc < 2) {
102 warnx("usage: test {<hostname> | crash}");
103 errx(1, "Always talks to statd at localhost");
105 printf("Creating client for localhost\n");
106 cli = clnt_create("localhost", SM_PROG, SM_VERS, "udp");
107 if (!cli) {
108 errx(1, "Failed to create client");
110 mon.mon_id.mon_name = argv[1];
111 mon.mon_id.my_id.my_name = argv[1];
112 mon.mon_id.my_id.my_prog = SM_PROG;
113 mon.mon_id.my_id.my_vers = SM_VERS;
114 mon.mon_id.my_id.my_proc = 1; /* have it call sm_stat() !!! */
116 if (strcmp(argv[1], "crash")) {
117 /* Hostname given */
118 struct sm_stat_res *res;
119 if (res = sm_mon_1(&mon, cli))
120 printf("Success!\n");
121 else
122 printf("Fail\n");
123 } else {
124 if (out = sm_simu_crash_1(&dummy, cli))
125 printf("Success!\n");
126 else
127 printf("Fail\n");
130 return 0;