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