1*666bec36Sdholland /* $NetBSD: test.c,v 1.8 2016/03/12 02:07:44 dholland Exp $ */
2a6fdc939Sscottr
35488f4aaSdholland #include <sys/cdefs.h>
4ceaa3a4fSchristos #include <stdio.h>
5ceaa3a4fSchristos #include <string.h>
65488f4aaSdholland #include <err.h>
7a6fdc939Sscottr #include <rpc/rpc.h>
8a6fdc939Sscottr #include <rpcsvc/nlm_prot.h>
9ceaa3a4fSchristos
10a6fdc939Sscottr #ifndef lint
111b318768Slukem #if 0
121b318768Slukem static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
131b318768Slukem static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";
141b318768Slukem #else
15*666bec36Sdholland __RCSID("$NetBSD: test.c,v 1.8 2016/03/12 02:07:44 dholland Exp $");
161b318768Slukem #endif
17a6fdc939Sscottr #endif /* not lint */
18a6fdc939Sscottr
19a6fdc939Sscottr /* Default timeout can be changed using clnt_control() */
20a6fdc939Sscottr static struct timeval TIMEOUT = {0, 0};
21a6fdc939Sscottr
22a6fdc939Sscottr nlm_testres *
nlm_test_1(struct nlm_testargs * argp,CLIENT * clnt)23ceaa3a4fSchristos nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
24a6fdc939Sscottr {
2549f907c5Sdholland enum clnt_stat st;
26a6fdc939Sscottr static nlm_testres res;
27a6fdc939Sscottr
28ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
2949f907c5Sdholland st = clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres,
3049f907c5Sdholland &res, TIMEOUT);
3149f907c5Sdholland if (st != RPC_SUCCESS)
32ceaa3a4fSchristos return NULL;
33ceaa3a4fSchristos return &res;
34a6fdc939Sscottr }
35a6fdc939Sscottr
36a6fdc939Sscottr
37a6fdc939Sscottr nlm_res *
nlm_lock_1(struct nlm_lockargs * argp,CLIENT * clnt)38ceaa3a4fSchristos nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
39a6fdc939Sscottr {
40a6fdc939Sscottr enum clnt_stat st;
41a6fdc939Sscottr static nlm_res res;
42a6fdc939Sscottr
43ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
4449f907c5Sdholland st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
4549f907c5Sdholland &res, TIMEOUT);
4649f907c5Sdholland if (st != RPC_SUCCESS) {
47a6fdc939Sscottr printf("clnt_call returns %d\n", st);
48a6fdc939Sscottr clnt_perror(clnt, "humbug");
49ceaa3a4fSchristos return NULL;
50a6fdc939Sscottr }
51ceaa3a4fSchristos return &res;
52a6fdc939Sscottr }
53a6fdc939Sscottr
54a6fdc939Sscottr
55a6fdc939Sscottr nlm_res *
nlm_cancel_1(struct nlm_cancargs * argp,CLIENT * clnt)56ceaa3a4fSchristos nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
57a6fdc939Sscottr {
5849f907c5Sdholland enum clnt_stat st;
59a6fdc939Sscottr static nlm_res res;
60a6fdc939Sscottr
61ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
6249f907c5Sdholland st = clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res,
6349f907c5Sdholland &res, TIMEOUT);
6449f907c5Sdholland if (st != RPC_SUCCESS) {
65ceaa3a4fSchristos return NULL;
66a6fdc939Sscottr }
67ceaa3a4fSchristos return &res;
68a6fdc939Sscottr }
69a6fdc939Sscottr
70a6fdc939Sscottr
71a6fdc939Sscottr nlm_res *
nlm_unlock_1(struct nlm_unlockargs * argp,CLIENT * clnt)72ceaa3a4fSchristos nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
73a6fdc939Sscottr {
7449f907c5Sdholland enum clnt_stat st;
75a6fdc939Sscottr static nlm_res res;
76a6fdc939Sscottr
77ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
7849f907c5Sdholland st = clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res,
7949f907c5Sdholland &res, TIMEOUT);
8049f907c5Sdholland if (st != RPC_SUCCESS) {
81ceaa3a4fSchristos return NULL;
82a6fdc939Sscottr }
83ceaa3a4fSchristos return &res;
84a6fdc939Sscottr }
85a6fdc939Sscottr
86a6fdc939Sscottr
87a6fdc939Sscottr nlm_res *
nlm_granted_1(struct nlm_testargs * argp,CLIENT * clnt)88ceaa3a4fSchristos nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
89a6fdc939Sscottr {
9049f907c5Sdholland enum clnt_stat st;
91a6fdc939Sscottr static nlm_res res;
92a6fdc939Sscottr
93ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
9449f907c5Sdholland st = clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res,
9549f907c5Sdholland &res, TIMEOUT);
9649f907c5Sdholland if (st != RPC_SUCCESS) {
97ceaa3a4fSchristos return NULL;
98a6fdc939Sscottr }
99ceaa3a4fSchristos return &res;
100a6fdc939Sscottr }
101a6fdc939Sscottr
102a6fdc939Sscottr
103a6fdc939Sscottr void *
nlm_test_msg_1(struct nlm_testargs * argp,CLIENT * clnt)104ceaa3a4fSchristos nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
105a6fdc939Sscottr {
10649f907c5Sdholland enum clnt_stat st;
107a6fdc939Sscottr static char res;
108a6fdc939Sscottr
109ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
11049f907c5Sdholland st = clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void,
11149f907c5Sdholland &res, TIMEOUT);
11249f907c5Sdholland if (st != RPC_SUCCESS) {
113ceaa3a4fSchristos return NULL;
114a6fdc939Sscottr }
115ceaa3a4fSchristos return &res;
116a6fdc939Sscottr }
117a6fdc939Sscottr
118a6fdc939Sscottr
119a6fdc939Sscottr void *
nlm_lock_msg_1(struct nlm_lockargs * argp,CLIENT * clnt)120ceaa3a4fSchristos nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
121a6fdc939Sscottr {
12249f907c5Sdholland enum clnt_stat st;
123a6fdc939Sscottr static char res;
124a6fdc939Sscottr
125ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
12649f907c5Sdholland st = clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void,
12749f907c5Sdholland NULL, TIMEOUT);
12849f907c5Sdholland if (st != RPC_SUCCESS) {
129a6fdc939Sscottr clnt_perror(clnt, "nlm_lock_msg_1");
130ceaa3a4fSchristos return NULL;
131a6fdc939Sscottr }
132ceaa3a4fSchristos return &res;
133a6fdc939Sscottr }
134a6fdc939Sscottr
135a6fdc939Sscottr
136a6fdc939Sscottr void *
nlm_cancel_msg_1(struct nlm_cancargs * argp,CLIENT * clnt)137ceaa3a4fSchristos nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
138a6fdc939Sscottr {
13949f907c5Sdholland enum clnt_stat st;
140a6fdc939Sscottr static char res;
141a6fdc939Sscottr
142ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
14349f907c5Sdholland st = clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void,
14449f907c5Sdholland &res, TIMEOUT);
14549f907c5Sdholland if (st != RPC_SUCCESS) {
146ceaa3a4fSchristos return NULL;
147a6fdc939Sscottr }
148ceaa3a4fSchristos return &res;
149a6fdc939Sscottr }
150a6fdc939Sscottr
151a6fdc939Sscottr
152a6fdc939Sscottr void *
nlm_unlock_msg_1(struct nlm_unlockargs * argp,CLIENT * clnt)153ceaa3a4fSchristos nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
154a6fdc939Sscottr {
15549f907c5Sdholland enum clnt_stat st;
156a6fdc939Sscottr static char res;
157a6fdc939Sscottr
158ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
15949f907c5Sdholland st = clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void,
16049f907c5Sdholland &res, TIMEOUT);
16149f907c5Sdholland if (st != RPC_SUCCESS) {
162ceaa3a4fSchristos return NULL;
163a6fdc939Sscottr }
164ceaa3a4fSchristos return &res;
165a6fdc939Sscottr }
166a6fdc939Sscottr
167a6fdc939Sscottr
168a6fdc939Sscottr void *
nlm_granted_msg_1(struct nlm_testargs * argp,CLIENT * clnt)169ceaa3a4fSchristos nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
170a6fdc939Sscottr {
17149f907c5Sdholland enum clnt_stat st;
172a6fdc939Sscottr static char res;
173a6fdc939Sscottr
174ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
17549f907c5Sdholland st = clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void,
17649f907c5Sdholland &res, TIMEOUT);
17749f907c5Sdholland if (st != RPC_SUCCESS) {
178ceaa3a4fSchristos return NULL;
179a6fdc939Sscottr }
180ceaa3a4fSchristos return &res;
181a6fdc939Sscottr }
182a6fdc939Sscottr
183a6fdc939Sscottr
184a6fdc939Sscottr void *
nlm_test_res_1(nlm_testres * argp,CLIENT * clnt)185ceaa3a4fSchristos nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
186a6fdc939Sscottr {
18749f907c5Sdholland enum clnt_stat st;
188a6fdc939Sscottr static char res;
189a6fdc939Sscottr
190ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
19149f907c5Sdholland st = clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void,
19249f907c5Sdholland &res, TIMEOUT);
19349f907c5Sdholland if (st != RPC_SUCCESS) {
194ceaa3a4fSchristos return NULL;
195a6fdc939Sscottr }
196ceaa3a4fSchristos return &res;
197a6fdc939Sscottr }
198a6fdc939Sscottr
199a6fdc939Sscottr
200a6fdc939Sscottr void *
nlm_lock_res_1(nlm_res * argp,CLIENT * clnt)201ceaa3a4fSchristos nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
202a6fdc939Sscottr {
20349f907c5Sdholland enum clnt_stat st;
204a6fdc939Sscottr static char res;
205a6fdc939Sscottr
206ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
20749f907c5Sdholland st = clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void,
20849f907c5Sdholland &res, TIMEOUT);
20949f907c5Sdholland if (st != RPC_SUCCESS) {
210ceaa3a4fSchristos return NULL;
211a6fdc939Sscottr }
212ceaa3a4fSchristos return &res;
213a6fdc939Sscottr }
214a6fdc939Sscottr
215a6fdc939Sscottr
216a6fdc939Sscottr void *
nlm_cancel_res_1(nlm_res * argp,CLIENT * clnt)217ceaa3a4fSchristos nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
218a6fdc939Sscottr {
21949f907c5Sdholland enum clnt_stat st;
220a6fdc939Sscottr static char res;
221a6fdc939Sscottr
222ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
22349f907c5Sdholland st = clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void,
22449f907c5Sdholland &res, TIMEOUT);
22549f907c5Sdholland if (st != RPC_SUCCESS) {
226ceaa3a4fSchristos return NULL;
227a6fdc939Sscottr }
228ceaa3a4fSchristos return &res;
229a6fdc939Sscottr }
230a6fdc939Sscottr
231a6fdc939Sscottr
232a6fdc939Sscottr void *
nlm_unlock_res_1(nlm_res * argp,CLIENT * clnt)233ceaa3a4fSchristos nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
234a6fdc939Sscottr {
23549f907c5Sdholland enum clnt_stat st;
236a6fdc939Sscottr static char res;
237a6fdc939Sscottr
238ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
23949f907c5Sdholland st = clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void,
24049f907c5Sdholland &res, TIMEOUT);
24149f907c5Sdholland if (st != RPC_SUCCESS) {
242ceaa3a4fSchristos return NULL;
243a6fdc939Sscottr }
244ceaa3a4fSchristos return &res;
245a6fdc939Sscottr }
246a6fdc939Sscottr
247a6fdc939Sscottr
248a6fdc939Sscottr void *
nlm_granted_res_1(nlm_res * argp,CLIENT * clnt)249ceaa3a4fSchristos nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
250a6fdc939Sscottr {
25149f907c5Sdholland enum clnt_stat st;
252a6fdc939Sscottr static char res;
253a6fdc939Sscottr
254ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
25549f907c5Sdholland st = clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void,
25649f907c5Sdholland &res, TIMEOUT);
25749f907c5Sdholland if (st != RPC_SUCCESS) {
258ceaa3a4fSchristos return NULL;
259a6fdc939Sscottr }
260ceaa3a4fSchristos return &res;
261a6fdc939Sscottr }
262a6fdc939Sscottr
263a6fdc939Sscottr
264a6fdc939Sscottr nlm_shareres *
nlm_share_3(nlm_shareargs * argp,CLIENT * clnt)265ceaa3a4fSchristos nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
266a6fdc939Sscottr {
26749f907c5Sdholland enum clnt_stat st;
268a6fdc939Sscottr static nlm_shareres res;
269a6fdc939Sscottr
270ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
27149f907c5Sdholland st = clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp,
27249f907c5Sdholland xdr_nlm_shareres, &res, TIMEOUT);
27349f907c5Sdholland if (st != RPC_SUCCESS) {
274ceaa3a4fSchristos return NULL;
275a6fdc939Sscottr }
276ceaa3a4fSchristos return &res;
277a6fdc939Sscottr }
278a6fdc939Sscottr
279a6fdc939Sscottr
280a6fdc939Sscottr nlm_shareres *
nlm_unshare_3(nlm_shareargs * argp,CLIENT * clnt)281ceaa3a4fSchristos nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
282a6fdc939Sscottr {
28349f907c5Sdholland enum clnt_stat st;
284a6fdc939Sscottr static nlm_shareres res;
285a6fdc939Sscottr
286ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
28749f907c5Sdholland st = clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp,
28849f907c5Sdholland xdr_nlm_shareres, &res, TIMEOUT);
28949f907c5Sdholland if (st != RPC_SUCCESS) {
290ceaa3a4fSchristos return NULL;
291a6fdc939Sscottr }
292ceaa3a4fSchristos return &res;
293a6fdc939Sscottr }
294a6fdc939Sscottr
295a6fdc939Sscottr
296a6fdc939Sscottr nlm_res *
nlm_nm_lock_3(nlm_lockargs * argp,CLIENT * clnt)297ceaa3a4fSchristos nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
298a6fdc939Sscottr {
29949f907c5Sdholland enum clnt_stat st;
300a6fdc939Sscottr static nlm_res res;
301a6fdc939Sscottr
302ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
30349f907c5Sdholland st = clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
30449f907c5Sdholland &res, TIMEOUT);
30549f907c5Sdholland if (st != RPC_SUCCESS) {
306ceaa3a4fSchristos return NULL;
307a6fdc939Sscottr }
308ceaa3a4fSchristos return &res;
309a6fdc939Sscottr }
310a6fdc939Sscottr
311a6fdc939Sscottr
312a6fdc939Sscottr void *
nlm_free_all_3(nlm_notify * argp,CLIENT * clnt)313ceaa3a4fSchristos nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
314a6fdc939Sscottr {
31549f907c5Sdholland enum clnt_stat st;
316a6fdc939Sscottr static char res;
317a6fdc939Sscottr
318ceaa3a4fSchristos (void)memset(&res, 0, sizeof(res));
31949f907c5Sdholland st = clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void,
32049f907c5Sdholland &res, TIMEOUT);
32149f907c5Sdholland if (st != RPC_SUCCESS) {
322ceaa3a4fSchristos return NULL;
323a6fdc939Sscottr }
324ceaa3a4fSchristos return &res;
325a6fdc939Sscottr }
326a6fdc939Sscottr
327a6fdc939Sscottr
328a6fdc939Sscottr int
main(int argc,char ** argv)329a6fdc939Sscottr main(int argc, char **argv)
330a6fdc939Sscottr {
331a6fdc939Sscottr CLIENT *cli;
332a6fdc939Sscottr nlm_res res_block;
333a6fdc939Sscottr nlm_res *out;
334a6fdc939Sscottr nlm_lockargs arg;
335a6fdc939Sscottr struct timeval tim;
336a6fdc939Sscottr
3375488f4aaSdholland if (argc != 2) {
3385488f4aaSdholland errx(1, "usage: %s host", argv[0]);
3395488f4aaSdholland }
3405488f4aaSdholland
341a6fdc939Sscottr printf("Creating client for host %s\n", argv[1]);
342a6fdc939Sscottr cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
343a6fdc939Sscottr if (!cli) {
344eda9e509Sgrant errx(1, "Failed to create client");
345a6fdc939Sscottr /* NOTREACHED */
346a6fdc939Sscottr }
347ceaa3a4fSchristos clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
3485488f4aaSdholland printf("Default timeout was %lld.%d\n",
3495488f4aaSdholland (long long)tim.tv_sec, tim.tv_usec);
350a6fdc939Sscottr tim.tv_usec = -1;
351a6fdc939Sscottr tim.tv_sec = -1;
352ceaa3a4fSchristos clnt_control(cli, CLSET_TIMEOUT, (void *)&tim);
353ceaa3a4fSchristos clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
3545488f4aaSdholland printf("timeout now %lld.%u\n", (long long)tim.tv_sec, tim.tv_usec);
355a6fdc939Sscottr
356a6fdc939Sscottr
357a6fdc939Sscottr arg.cookie.n_len = 4;
358a6fdc939Sscottr arg.cookie.n_bytes = "hello";
359a6fdc939Sscottr arg.block = 0;
360a6fdc939Sscottr arg.exclusive = 0;
361a6fdc939Sscottr arg.reclaim = 0;
362a6fdc939Sscottr arg.state = 0x1234;
363a6fdc939Sscottr arg.alock.caller_name = "localhost";
364a6fdc939Sscottr arg.alock.fh.n_len = 32;
365a6fdc939Sscottr 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";
366a6fdc939Sscottr arg.alock.oh.n_len = 8;
367a6fdc939Sscottr arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
368a6fdc939Sscottr arg.alock.svid = 0x5678;
369a6fdc939Sscottr arg.alock.l_offset = 0;
370a6fdc939Sscottr arg.alock.l_len = 100;
371a6fdc939Sscottr
372a6fdc939Sscottr res_block.stat.stat = nlm_granted;
373a6fdc939Sscottr res_block.cookie.n_bytes = "hello";
374a6fdc939Sscottr res_block.cookie.n_len = 5;
375a6fdc939Sscottr
376a6fdc939Sscottr #if 0
377a6fdc939Sscottr if (nlm_lock_res_1(&res_block, cli))
378a6fdc939Sscottr printf("Success!\n");
379a6fdc939Sscottr else
380a6fdc939Sscottr printf("Fail\n");
381a6fdc939Sscottr #else
3825488f4aaSdholland (void)res_block;
3835488f4aaSdholland
384*666bec36Sdholland out = nlm_lock_msg_1(&arg, cli);
385*666bec36Sdholland if (out != NULL) {
386a6fdc939Sscottr printf("Success!\n");
3875488f4aaSdholland printf("out->stat = %d", out->stat.stat);
388a6fdc939Sscottr } else {
389a6fdc939Sscottr printf("Fail\n");
390a6fdc939Sscottr }
391a6fdc939Sscottr #endif
392a6fdc939Sscottr
393a6fdc939Sscottr return 0;
394a6fdc939Sscottr }
395