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