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