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