xref: /freebsd/usr.sbin/rpc.lockd/test.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /*	$NetBSD: test.c,v 1.2 1997/10/18 04:01:21 lukem Exp $	*/
2 
3 #include <sys/cdefs.h>
4 #include <rpc/rpc.h>
5 #include <rpcsvc/nlm_prot.h>
6 
7 /* Default timeout can be changed using clnt_control() */
8 static struct timeval TIMEOUT = { 0, 0 };
9 
10 nlm_testres *
11 nlm_test_1(argp, clnt)
12 	struct nlm_testargs *argp;
13 	CLIENT *clnt;
14 {
15 	static nlm_testres res;
16 
17 	bzero((char *)&res, sizeof(res));
18 	if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres, &res, TIMEOUT) != RPC_SUCCESS) {
19 		return (NULL);
20 	}
21 	return (&res);
22 }
23 
24 
25 nlm_res *
26 nlm_lock_1(argp, clnt)
27 	struct nlm_lockargs *argp;
28 	CLIENT *clnt;
29 {
30 	enum clnt_stat st;
31 	static nlm_res res;
32 
33 	bzero((char *)&res, sizeof(res));
34 	if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
35 		printf("clnt_call returns %d\n", st);
36 		clnt_perror(clnt, "humbug");
37 		return (NULL);
38 	}
39 	return (&res);
40 }
41 
42 
43 nlm_res *
44 nlm_cancel_1(argp, clnt)
45 	struct nlm_cancargs *argp;
46 	CLIENT *clnt;
47 {
48 	static nlm_res res;
49 
50 	bzero((char *)&res, sizeof(res));
51 	if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
52 		return (NULL);
53 	}
54 	return (&res);
55 }
56 
57 
58 nlm_res *
59 nlm_unlock_1(argp, clnt)
60 	struct nlm_unlockargs *argp;
61 	CLIENT *clnt;
62 {
63 	static nlm_res res;
64 
65 	bzero((char *)&res, sizeof(res));
66 	if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
67 		return (NULL);
68 	}
69 	return (&res);
70 }
71 
72 
73 nlm_res *
74 nlm_granted_1(argp, clnt)
75 	struct nlm_testargs *argp;
76 	CLIENT *clnt;
77 {
78 	static nlm_res res;
79 
80 	bzero((char *)&res, sizeof(res));
81 	if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
82 		return (NULL);
83 	}
84 	return (&res);
85 }
86 
87 
88 void *
89 nlm_test_msg_1(argp, clnt)
90 	struct nlm_testargs *argp;
91 	CLIENT *clnt;
92 {
93 	static char res;
94 
95 	bzero((char *)&res, sizeof(res));
96 	if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
97 		return (NULL);
98 	}
99 	return ((void *)&res);
100 }
101 
102 
103 void *
104 nlm_lock_msg_1(argp, clnt)
105 	struct nlm_lockargs *argp;
106 	CLIENT *clnt;
107 {
108 	static char res;
109 
110 	bzero((char *)&res, sizeof(res));
111 	if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
112 		clnt_perror(clnt, "nlm_lock_msg_1");
113 		return (NULL);
114 	}
115 	return ((void *)&res);
116 }
117 
118 
119 void *
120 nlm_cancel_msg_1(argp, clnt)
121 	struct nlm_cancargs *argp;
122 	CLIENT *clnt;
123 {
124 	static char res;
125 
126 	bzero((char *)&res, sizeof(res));
127 	if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
128 		return (NULL);
129 	}
130 	return ((void *)&res);
131 }
132 
133 
134 void *
135 nlm_unlock_msg_1(argp, clnt)
136 	struct nlm_unlockargs *argp;
137 	CLIENT *clnt;
138 {
139 	static char res;
140 
141 	bzero((char *)&res, sizeof(res));
142 	if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
143 		return (NULL);
144 	}
145 	return ((void *)&res);
146 }
147 
148 
149 void *
150 nlm_granted_msg_1(argp, clnt)
151 	struct nlm_testargs *argp;
152 	CLIENT *clnt;
153 {
154 	static char res;
155 
156 	bzero((char *)&res, sizeof(res));
157 	if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
158 		return (NULL);
159 	}
160 	return ((void *)&res);
161 }
162 
163 
164 void *
165 nlm_test_res_1(argp, clnt)
166 	nlm_testres *argp;
167 	CLIENT *clnt;
168 {
169 	static char res;
170 
171 	bzero((char *)&res, sizeof(res));
172 	if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
173 		return (NULL);
174 	}
175 	return ((void *)&res);
176 }
177 
178 
179 void *
180 nlm_lock_res_1(argp, clnt)
181 	nlm_res *argp;
182 	CLIENT *clnt;
183 {
184 	static char res;
185 
186 	bzero((char *)&res, sizeof(res));
187 	if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
188 		return (NULL);
189 	}
190 	return ((void *)&res);
191 }
192 
193 
194 void *
195 nlm_cancel_res_1(argp, clnt)
196 	nlm_res *argp;
197 	CLIENT *clnt;
198 {
199 	static char res;
200 
201 	bzero((char *)&res, sizeof(res));
202 	if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
203 		return (NULL);
204 	}
205 	return ((void *)&res);
206 }
207 
208 
209 void *
210 nlm_unlock_res_1(argp, clnt)
211 	nlm_res *argp;
212 	CLIENT *clnt;
213 {
214 	static char res;
215 
216 	bzero((char *)&res, sizeof(res));
217 	if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
218 		return (NULL);
219 	}
220 	return ((void *)&res);
221 }
222 
223 
224 void *
225 nlm_granted_res_1(argp, clnt)
226 	nlm_res *argp;
227 	CLIENT *clnt;
228 {
229 	static char res;
230 
231 	bzero((char *)&res, sizeof(res));
232 	if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
233 		return (NULL);
234 	}
235 	return ((void *)&res);
236 }
237 
238 
239 nlm_shareres *
240 nlm_share_3(argp, clnt)
241 	nlm_shareargs *argp;
242 	CLIENT *clnt;
243 {
244 	static nlm_shareres res;
245 
246 	bzero((char *)&res, sizeof(res));
247 	if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
248 		return (NULL);
249 	}
250 	return (&res);
251 }
252 
253 
254 nlm_shareres *
255 nlm_unshare_3(argp, clnt)
256 	nlm_shareargs *argp;
257 	CLIENT *clnt;
258 {
259 	static nlm_shareres res;
260 
261 	bzero((char *)&res, sizeof(res));
262 	if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
263 		return (NULL);
264 	}
265 	return (&res);
266 }
267 
268 
269 nlm_res *
270 nlm_nm_lock_3(argp, clnt)
271 	nlm_lockargs *argp;
272 	CLIENT *clnt;
273 {
274 	static nlm_res res;
275 
276 	bzero((char *)&res, sizeof(res));
277 	if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
278 		return (NULL);
279 	}
280 	return (&res);
281 }
282 
283 
284 void *
285 nlm_free_all_3(argp, clnt)
286 	nlm_notify *argp;
287 	CLIENT *clnt;
288 {
289 	static char res;
290 
291 	bzero((char *)&res, sizeof(res));
292 	if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
293 		return (NULL);
294 	}
295 	return ((void *)&res);
296 }
297 
298 
299 int main(int argc, char **argv)
300 {
301 	CLIENT *cli;
302 	nlm_res res_block;
303 	nlm_res *out;
304 	nlm_lockargs arg;
305 	struct timeval tim;
306 
307 	printf("Creating client for host %s\n", argv[1]);
308 	cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
309 	if (!cli) {
310 		errx(1, "Failed to create client\n");
311 		/* NOTREACHED */
312 	}
313 	clnt_control(cli, CLGET_TIMEOUT, &tim);
314 	printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec);
315 	tim.tv_usec = -1;
316 	tim.tv_sec = -1;
317 	clnt_control(cli, CLSET_TIMEOUT, &tim);
318 	clnt_control(cli, CLGET_TIMEOUT, &tim);
319 	printf("timeout now %d.%d\n", tim.tv_sec, tim.tv_usec);
320 
321 
322 	arg.cookie.n_len = 4;
323 	arg.cookie.n_bytes = "hello";
324 	arg.block = 0;
325 	arg.exclusive = 0;
326 	arg.reclaim = 0;
327 	arg.state = 0x1234;
328 	arg.alock.caller_name = "localhost";
329 	arg.alock.fh.n_len = 32;
330 	arg.alock.fh.n_bytes = "\x04\x04\x02\x00\x01\x00\x00\x00\x0c\x00\x00\x00\xff\xff\xff\xd0\x16\x00\x00\x5b\x7c\xff\xff\xff\xec\x2f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x54\xef\xbf\xd7\x94";
331 	arg.alock.oh.n_len = 8;
332 	arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
333 	arg.alock.svid = 0x5678;
334 	arg.alock.l_offset = 0;
335 	arg.alock.l_len = 100;
336 
337 	res_block.stat.stat = nlm_granted;
338 	res_block.cookie.n_bytes = "hello";
339 	res_block.cookie.n_len = 5;
340 
341 #if 0
342 	if (nlm_lock_res_1(&res_block, cli))
343 		printf("Success!\n");
344 	else
345 		printf("Fail\n");
346 #else
347 	if (out = nlm_lock_msg_1(&arg, cli)) {
348 		printf("Success!\n");
349 		printf("out->stat = %d", out->stat);
350 	} else {
351 		printf("Fail\n");
352 	}
353 #endif
354 
355 	return 0;
356 }
357