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