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