xref: /freebsd/usr.sbin/rpc.lockd/test.c (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
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 #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.2 1997/10/18 04:01:21 lukem Exp $");
12 static const char rcsid[] = "$FreeBSD$";
13 #endif
14 #endif				/* not lint */
15 
16 /* Default timeout can be changed using clnt_control() */
17 static struct timeval TIMEOUT = { 0, 0 };
18 
19 nlm_testres *
20 nlm_test_1(argp, clnt)
21 	struct nlm_testargs *argp;
22 	CLIENT *clnt;
23 {
24 	static nlm_testres res;
25 
26 	bzero((char *)&res, sizeof(res));
27 	if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres, &res, TIMEOUT) != RPC_SUCCESS) {
28 		return (NULL);
29 	}
30 	return (&res);
31 }
32 
33 
34 nlm_res *
35 nlm_lock_1(argp, clnt)
36 	struct nlm_lockargs *argp;
37 	CLIENT *clnt;
38 {
39 	enum clnt_stat st;
40 	static nlm_res res;
41 
42 	bzero((char *)&res, sizeof(res));
43 	if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
44 		printf("clnt_call returns %d\n", st);
45 		clnt_perror(clnt, "humbug");
46 		return (NULL);
47 	}
48 	return (&res);
49 }
50 
51 
52 nlm_res *
53 nlm_cancel_1(argp, clnt)
54 	struct nlm_cancargs *argp;
55 	CLIENT *clnt;
56 {
57 	static nlm_res res;
58 
59 	bzero((char *)&res, sizeof(res));
60 	if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
61 		return (NULL);
62 	}
63 	return (&res);
64 }
65 
66 
67 nlm_res *
68 nlm_unlock_1(argp, clnt)
69 	struct nlm_unlockargs *argp;
70 	CLIENT *clnt;
71 {
72 	static nlm_res res;
73 
74 	bzero((char *)&res, sizeof(res));
75 	if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
76 		return (NULL);
77 	}
78 	return (&res);
79 }
80 
81 
82 nlm_res *
83 nlm_granted_1(argp, clnt)
84 	struct nlm_testargs *argp;
85 	CLIENT *clnt;
86 {
87 	static nlm_res res;
88 
89 	bzero((char *)&res, sizeof(res));
90 	if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
91 		return (NULL);
92 	}
93 	return (&res);
94 }
95 
96 
97 void *
98 nlm_test_msg_1(argp, clnt)
99 	struct nlm_testargs *argp;
100 	CLIENT *clnt;
101 {
102 	static char res;
103 
104 	bzero((char *)&res, sizeof(res));
105 	if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
106 		return (NULL);
107 	}
108 	return ((void *)&res);
109 }
110 
111 
112 void *
113 nlm_lock_msg_1(argp, clnt)
114 	struct nlm_lockargs *argp;
115 	CLIENT *clnt;
116 {
117 	static char res;
118 
119 	bzero((char *)&res, sizeof(res));
120 	if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
121 		clnt_perror(clnt, "nlm_lock_msg_1");
122 		return (NULL);
123 	}
124 	return ((void *)&res);
125 }
126 
127 
128 void *
129 nlm_cancel_msg_1(argp, clnt)
130 	struct nlm_cancargs *argp;
131 	CLIENT *clnt;
132 {
133 	static char res;
134 
135 	bzero((char *)&res, sizeof(res));
136 	if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
137 		return (NULL);
138 	}
139 	return ((void *)&res);
140 }
141 
142 
143 void *
144 nlm_unlock_msg_1(argp, clnt)
145 	struct nlm_unlockargs *argp;
146 	CLIENT *clnt;
147 {
148 	static char res;
149 
150 	bzero((char *)&res, sizeof(res));
151 	if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
152 		return (NULL);
153 	}
154 	return ((void *)&res);
155 }
156 
157 
158 void *
159 nlm_granted_msg_1(argp, clnt)
160 	struct nlm_testargs *argp;
161 	CLIENT *clnt;
162 {
163 	static char res;
164 
165 	bzero((char *)&res, sizeof(res));
166 	if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
167 		return (NULL);
168 	}
169 	return ((void *)&res);
170 }
171 
172 
173 void *
174 nlm_test_res_1(argp, clnt)
175 	nlm_testres *argp;
176 	CLIENT *clnt;
177 {
178 	static char res;
179 
180 	bzero((char *)&res, sizeof(res));
181 	if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
182 		return (NULL);
183 	}
184 	return ((void *)&res);
185 }
186 
187 
188 void *
189 nlm_lock_res_1(argp, clnt)
190 	nlm_res *argp;
191 	CLIENT *clnt;
192 {
193 	static char res;
194 
195 	bzero((char *)&res, sizeof(res));
196 	if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
197 		return (NULL);
198 	}
199 	return ((void *)&res);
200 }
201 
202 
203 void *
204 nlm_cancel_res_1(argp, clnt)
205 	nlm_res *argp;
206 	CLIENT *clnt;
207 {
208 	static char res;
209 
210 	bzero((char *)&res, sizeof(res));
211 	if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
212 		return (NULL);
213 	}
214 	return ((void *)&res);
215 }
216 
217 
218 void *
219 nlm_unlock_res_1(argp, clnt)
220 	nlm_res *argp;
221 	CLIENT *clnt;
222 {
223 	static char res;
224 
225 	bzero((char *)&res, sizeof(res));
226 	if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
227 		return (NULL);
228 	}
229 	return ((void *)&res);
230 }
231 
232 
233 void *
234 nlm_granted_res_1(argp, clnt)
235 	nlm_res *argp;
236 	CLIENT *clnt;
237 {
238 	static char res;
239 
240 	bzero((char *)&res, sizeof(res));
241 	if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
242 		return (NULL);
243 	}
244 	return ((void *)&res);
245 }
246 
247 
248 nlm_shareres *
249 nlm_share_3(argp, clnt)
250 	nlm_shareargs *argp;
251 	CLIENT *clnt;
252 {
253 	static nlm_shareres res;
254 
255 	bzero((char *)&res, sizeof(res));
256 	if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
257 		return (NULL);
258 	}
259 	return (&res);
260 }
261 
262 
263 nlm_shareres *
264 nlm_unshare_3(argp, clnt)
265 	nlm_shareargs *argp;
266 	CLIENT *clnt;
267 {
268 	static nlm_shareres res;
269 
270 	bzero((char *)&res, sizeof(res));
271 	if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
272 		return (NULL);
273 	}
274 	return (&res);
275 }
276 
277 
278 nlm_res *
279 nlm_nm_lock_3(argp, clnt)
280 	nlm_lockargs *argp;
281 	CLIENT *clnt;
282 {
283 	static nlm_res res;
284 
285 	bzero((char *)&res, sizeof(res));
286 	if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
287 		return (NULL);
288 	}
289 	return (&res);
290 }
291 
292 
293 void *
294 nlm_free_all_3(argp, clnt)
295 	nlm_notify *argp;
296 	CLIENT *clnt;
297 {
298 	static char res;
299 
300 	bzero((char *)&res, sizeof(res));
301 	if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
302 		return (NULL);
303 	}
304 	return ((void *)&res);
305 }
306 
307 
308 int 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\n");
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