No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / rpc.lockd / test.c
blobaa69dc8f7db910dc1afb88d99dafdff2188a9893
1 /* $NetBSD: test.c,v 1.3 2002/07/20 08:40:20 grant Exp $ */
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/cdefs.h>
6 #include <rpc/rpc.h>
7 #include <rpcsvc/nlm_prot.h>
9 #ifndef lint
10 #if 0
11 static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
12 static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";
13 #else
14 __RCSID("$NetBSD: test.c,v 1.3 2002/07/20 08:40:20 grant Exp $");
15 #endif
16 #endif /* not lint */
18 /* Default timeout can be changed using clnt_control() */
19 static struct timeval TIMEOUT = {0, 0};
21 nlm_testres *
22 nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
24 static nlm_testres res;
26 (void)memset(&res, 0, sizeof(res));
27 if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres,
28 &res, TIMEOUT) != RPC_SUCCESS)
29 return NULL;
30 return &res;
34 nlm_res *
35 nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
37 enum clnt_stat st;
38 static nlm_res res;
40 (void)memset(&res, 0, sizeof(res));
41 if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
42 &res, TIMEOUT) != RPC_SUCCESS) {
43 printf("clnt_call returns %d\n", st);
44 clnt_perror(clnt, "humbug");
45 return NULL;
47 return &res;
51 nlm_res *
52 nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
54 static nlm_res res;
56 (void)memset(&res, 0, sizeof(res));
57 if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res,
58 &res, TIMEOUT) != RPC_SUCCESS) {
59 return NULL;
61 return &res;
65 nlm_res *
66 nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
68 static nlm_res res;
70 (void)memset(&res, 0, sizeof(res));
71 if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res,
72 &res, TIMEOUT) != RPC_SUCCESS) {
73 return NULL;
75 return &res;
79 nlm_res *
80 nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
82 static nlm_res res;
84 (void)memset(&res, 0, sizeof(res));
85 if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res,
86 &res, TIMEOUT) != RPC_SUCCESS) {
87 return NULL;
89 return &res;
93 void *
94 nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
96 static char res;
98 (void)memset(&res, 0, sizeof(res));
99 if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void,
100 &res, TIMEOUT) != RPC_SUCCESS) {
101 return NULL;
103 return &res;
107 void *
108 nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
110 static char res;
112 (void)memset(&res, 0, sizeof(res));
113 if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void,
114 NULL, TIMEOUT) != RPC_SUCCESS) {
115 clnt_perror(clnt, "nlm_lock_msg_1");
116 return NULL;
118 return &res;
122 void *
123 nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
125 static char res;
127 (void)memset(&res, 0, sizeof(res));
128 if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void,
129 &res, TIMEOUT) != RPC_SUCCESS) {
130 return NULL;
132 return &res;
136 void *
137 nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
139 static char res;
141 (void)memset(&res, 0, sizeof(res));
142 if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void,
143 &res, TIMEOUT) != RPC_SUCCESS) {
144 return NULL;
146 return &res;
150 void *
151 nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
153 static char res;
155 (void)memset(&res, 0, sizeof(res));
156 if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void,
157 &res, TIMEOUT) != RPC_SUCCESS) {
158 return NULL;
160 return &res;
164 void *
165 nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
167 static char res;
169 (void)memset(&res, 0, sizeof(res));
170 if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res,
171 TIMEOUT) != RPC_SUCCESS) {
172 return NULL;
174 return &res;
178 void *
179 nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
181 static char res;
183 (void)memset(&res, 0, sizeof(res));
184 if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res,
185 TIMEOUT) != RPC_SUCCESS) {
186 return NULL;
188 return &res;
192 void *
193 nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
195 static char res;
197 (void)memset(&res, 0, sizeof(res));
198 if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res,
199 TIMEOUT) != RPC_SUCCESS) {
200 return NULL;
202 return &res;
206 void *
207 nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
209 static char res;
211 (void)memset(&res, 0, sizeof(res));
212 if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res,
213 TIMEOUT) != RPC_SUCCESS) {
214 return NULL;
216 return &res;
220 void *
221 nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
223 static char res;
225 (void)memset(&res, 0, sizeof(res));
226 if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res,
227 TIMEOUT) != RPC_SUCCESS) {
228 return NULL;
230 return &res;
234 nlm_shareres *
235 nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
237 static nlm_shareres res;
239 (void)memset(&res, 0, sizeof(res));
240 if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp,
241 xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
242 return NULL;
244 return &res;
248 nlm_shareres *
249 nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
251 static nlm_shareres res;
253 (void)memset(&res, 0, sizeof(res));
254 if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp,
255 xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
256 return NULL;
258 return &res;
262 nlm_res *
263 nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
265 static nlm_res res;
267 (void)memset(&res, 0, sizeof(res));
268 if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
269 &res, TIMEOUT) != RPC_SUCCESS) {
270 return NULL;
272 return &res;
276 void *
277 nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
279 static char res;
281 (void)memset(&res, 0, sizeof(res));
282 if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res,
283 TIMEOUT) != RPC_SUCCESS) {
284 return NULL;
286 return &res;
290 int
291 main(int argc, char **argv)
293 CLIENT *cli;
294 nlm_res res_block;
295 nlm_res *out;
296 nlm_lockargs arg;
297 struct timeval tim;
299 printf("Creating client for host %s\n", argv[1]);
300 cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
301 if (!cli) {
302 errx(1, "Failed to create client");
303 /* NOTREACHED */
305 clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
306 printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec);
307 tim.tv_usec = -1;
308 tim.tv_sec = -1;
309 clnt_control(cli, CLSET_TIMEOUT, (void *)&tim);
310 clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
311 printf("timeout now %d.%d\n", tim.tv_sec, tim.tv_usec);
314 arg.cookie.n_len = 4;
315 arg.cookie.n_bytes = "hello";
316 arg.block = 0;
317 arg.exclusive = 0;
318 arg.reclaim = 0;
319 arg.state = 0x1234;
320 arg.alock.caller_name = "localhost";
321 arg.alock.fh.n_len = 32;
322 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";
323 arg.alock.oh.n_len = 8;
324 arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
325 arg.alock.svid = 0x5678;
326 arg.alock.l_offset = 0;
327 arg.alock.l_len = 100;
329 res_block.stat.stat = nlm_granted;
330 res_block.cookie.n_bytes = "hello";
331 res_block.cookie.n_len = 5;
333 #if 0
334 if (nlm_lock_res_1(&res_block, cli))
335 printf("Success!\n");
336 else
337 printf("Fail\n");
338 #else
339 if (out = nlm_lock_msg_1(&arg, cli)) {
340 printf("Success!\n");
341 printf("out->stat = %d", out->stat);
342 } else {
343 printf("Fail\n");
345 #endif
347 return 0;