1*f7f1b834Skrw /* $OpenBSD: test.c,v 1.2 2017/01/21 08:33:51 krw Exp $ */
2b0c57e47Ssturm
3b0c57e47Ssturm #include <stdio.h>
4b0c57e47Ssturm #include <rpc/rpc.h>
5b0c57e47Ssturm #include <rpcsvc/sm_inter.h>
6b0c57e47Ssturm
7b0c57e47Ssturm
8b0c57e47Ssturm /* Default timeout can be changed using clnt_control() */
9b0c57e47Ssturm static struct timeval TIMEOUT = {25, 0};
10b0c57e47Ssturm
11b0c57e47Ssturm struct sm_stat_res *
sm_stat_1(argp,clnt)12b0c57e47Ssturm sm_stat_1(argp, clnt)
13b0c57e47Ssturm struct sm_name *argp;
14b0c57e47Ssturm CLIENT *clnt;
15b0c57e47Ssturm {
16b0c57e47Ssturm static struct sm_stat_res res;
17b0c57e47Ssturm
18b0c57e47Ssturm bzero((char *) &res, sizeof(res));
19b0c57e47Ssturm if (clnt_call(clnt, SM_STAT, xdr_sm_name, argp, xdr_sm_stat_res,
20b0c57e47Ssturm &res, TIMEOUT) != RPC_SUCCESS)
21b0c57e47Ssturm return (NULL);
22b0c57e47Ssturm return (&res);
23b0c57e47Ssturm }
24b0c57e47Ssturm
25b0c57e47Ssturm
26b0c57e47Ssturm struct sm_stat_res *
sm_mon_1(argp,clnt)27b0c57e47Ssturm sm_mon_1(argp, clnt)
28b0c57e47Ssturm struct mon *argp;
29b0c57e47Ssturm CLIENT *clnt;
30b0c57e47Ssturm {
31b0c57e47Ssturm static struct sm_stat_res res;
32b0c57e47Ssturm
33b0c57e47Ssturm bzero((char *) &res, sizeof(res));
34b0c57e47Ssturm if (clnt_call(clnt, SM_MON, xdr_mon, argp, xdr_sm_stat_res,
35b0c57e47Ssturm &res, TIMEOUT) != RPC_SUCCESS)
36b0c57e47Ssturm return (NULL);
37b0c57e47Ssturm return (&res);
38b0c57e47Ssturm }
39b0c57e47Ssturm
40b0c57e47Ssturm
41b0c57e47Ssturm struct sm_stat *
sm_unmon_1(argp,clnt)42b0c57e47Ssturm sm_unmon_1(argp, clnt)
43b0c57e47Ssturm struct mon_id *argp;
44b0c57e47Ssturm CLIENT *clnt;
45b0c57e47Ssturm {
46b0c57e47Ssturm static struct sm_stat res;
47b0c57e47Ssturm
48b0c57e47Ssturm bzero((char *) &res, sizeof(res));
49b0c57e47Ssturm if (clnt_call(clnt, SM_UNMON, xdr_mon_id, argp, xdr_sm_stat,
50b0c57e47Ssturm &res, TIMEOUT) != RPC_SUCCESS)
51b0c57e47Ssturm return (NULL);
52b0c57e47Ssturm return (&res);
53b0c57e47Ssturm }
54b0c57e47Ssturm
55b0c57e47Ssturm
56b0c57e47Ssturm struct sm_stat *
sm_unmon_all_1(argp,clnt)57b0c57e47Ssturm sm_unmon_all_1(argp, clnt)
58b0c57e47Ssturm struct my_id *argp;
59b0c57e47Ssturm CLIENT *clnt;
60b0c57e47Ssturm {
61b0c57e47Ssturm static struct sm_stat res;
62b0c57e47Ssturm
63b0c57e47Ssturm bzero((char *) &res, sizeof(res));
64b0c57e47Ssturm if (clnt_call(clnt, SM_UNMON_ALL, xdr_my_id, argp, xdr_sm_stat,
65b0c57e47Ssturm &res, TIMEOUT) != RPC_SUCCESS)
66b0c57e47Ssturm return (NULL);
67b0c57e47Ssturm return (&res);
68b0c57e47Ssturm }
69b0c57e47Ssturm
70b0c57e47Ssturm
71b0c57e47Ssturm void *
sm_simu_crash_1(argp,clnt)72b0c57e47Ssturm sm_simu_crash_1(argp, clnt)
73b0c57e47Ssturm void *argp;
74b0c57e47Ssturm CLIENT *clnt;
75b0c57e47Ssturm {
76b0c57e47Ssturm static char res;
77b0c57e47Ssturm
78b0c57e47Ssturm bzero((char *) &res, sizeof(res));
79b0c57e47Ssturm if (clnt_call(clnt, SM_SIMU_CRASH, xdr_void, argp, xdr_void,
80b0c57e47Ssturm &res, TIMEOUT) != RPC_SUCCESS)
81b0c57e47Ssturm return (NULL);
82b0c57e47Ssturm return ((void *) &res);
83b0c57e47Ssturm }
84b0c57e47Ssturm
85b0c57e47Ssturm
86b0c57e47Ssturm int
main(argc,argv)87b0c57e47Ssturm main(argc, argv)
88b0c57e47Ssturm int argc;
89b0c57e47Ssturm char **argv;
90b0c57e47Ssturm {
91b0c57e47Ssturm CLIENT *cli;
92b0c57e47Ssturm char dummy;
93b0c57e47Ssturm void *out;
94b0c57e47Ssturm struct mon mon;
95b0c57e47Ssturm
96b0c57e47Ssturm if (argc < 2) {
97b0c57e47Ssturm warnx("usage: test {<hostname> | crash}");
98b0c57e47Ssturm errx(1, "Always talks to statd at localhost");
99b0c57e47Ssturm }
100b0c57e47Ssturm printf("Creating client for localhost\n");
101b0c57e47Ssturm cli = clnt_create("localhost", SM_PROG, SM_VERS, "udp");
102b0c57e47Ssturm if (!cli) {
103b0c57e47Ssturm errx(1, "Failed to create client");
104b0c57e47Ssturm }
105b0c57e47Ssturm mon.mon_id.mon_name = argv[1];
106b0c57e47Ssturm mon.mon_id.my_id.my_name = argv[1];
107b0c57e47Ssturm mon.mon_id.my_id.my_prog = SM_PROG;
108b0c57e47Ssturm mon.mon_id.my_id.my_vers = SM_VERS;
109b0c57e47Ssturm mon.mon_id.my_id.my_proc = 1; /* have it call sm_stat() !!! */
110b0c57e47Ssturm
111b0c57e47Ssturm if (strcmp(argv[1], "crash")) {
112b0c57e47Ssturm /* Hostname given */
113b0c57e47Ssturm struct sm_stat_res *res;
114b0c57e47Ssturm if (res = sm_mon_1(&mon, cli))
115b0c57e47Ssturm printf("Success!\n");
116b0c57e47Ssturm else
117b0c57e47Ssturm printf("Fail\n");
118b0c57e47Ssturm } else {
119b0c57e47Ssturm if (out = sm_simu_crash_1(&dummy, cli))
120b0c57e47Ssturm printf("Success!\n");
121b0c57e47Ssturm else
122b0c57e47Ssturm printf("Fail\n");
123b0c57e47Ssturm }
124b0c57e47Ssturm
125b0c57e47Ssturm return 0;
126b0c57e47Ssturm }
127