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