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