2 * @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro
3 * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC
4 * $FreeBSD: src/usr.sbin/rpc.lockd/test.c,v 1.4.2.1 2001/08/01 06:39:36 alfred Exp $
5 * $DragonFly: src/usr.sbin/rpc.lockd/test.c,v 1.2 2003/06/17 04:30:02 dillon Exp $
9 #include <rpcsvc/nlm_prot.h>
11 /* Default timeout can be changed using clnt_control() */
12 static struct timeval TIMEOUT = { 0, 0 };
15 nlm_test_1(argp, clnt)
16 struct nlm_testargs *argp;
19 static nlm_testres res;
21 bzero((char *)&res, sizeof(res));
22 if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres, &res, TIMEOUT) != RPC_SUCCESS) {
30 nlm_lock_1(argp, clnt)
31 struct nlm_lockargs *argp;
37 bzero((char *)&res, sizeof(res));
38 if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
39 printf("clnt_call returns %d\n", st);
40 clnt_perror(clnt, "humbug");
48 nlm_cancel_1(argp, clnt)
49 struct nlm_cancargs *argp;
54 bzero((char *)&res, sizeof(res));
55 if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
63 nlm_unlock_1(argp, clnt)
64 struct nlm_unlockargs *argp;
69 bzero((char *)&res, sizeof(res));
70 if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
78 nlm_granted_1(argp, clnt)
79 struct nlm_testargs *argp;
84 bzero((char *)&res, sizeof(res));
85 if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
93 nlm_test_msg_1(argp, clnt)
94 struct nlm_testargs *argp;
99 bzero((char *)&res, sizeof(res));
100 if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
103 return ((void *)&res);
108 nlm_lock_msg_1(argp, clnt)
109 struct nlm_lockargs *argp;
114 bzero((char *)&res, sizeof(res));
115 if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
116 clnt_perror(clnt, "nlm_lock_msg_1");
119 return ((void *)&res);
124 nlm_cancel_msg_1(argp, clnt)
125 struct nlm_cancargs *argp;
130 bzero((char *)&res, sizeof(res));
131 if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
134 return ((void *)&res);
139 nlm_unlock_msg_1(argp, clnt)
140 struct nlm_unlockargs *argp;
145 bzero((char *)&res, sizeof(res));
146 if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
149 return ((void *)&res);
154 nlm_granted_msg_1(argp, clnt)
155 struct nlm_testargs *argp;
160 bzero((char *)&res, sizeof(res));
161 if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
164 return ((void *)&res);
169 nlm_test_res_1(argp, clnt)
175 bzero((char *)&res, sizeof(res));
176 if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
179 return ((void *)&res);
184 nlm_lock_res_1(argp, clnt)
190 bzero((char *)&res, sizeof(res));
191 if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
194 return ((void *)&res);
199 nlm_cancel_res_1(argp, clnt)
205 bzero((char *)&res, sizeof(res));
206 if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
209 return ((void *)&res);
214 nlm_unlock_res_1(argp, clnt)
220 bzero((char *)&res, sizeof(res));
221 if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
224 return ((void *)&res);
229 nlm_granted_res_1(argp, clnt)
235 bzero((char *)&res, sizeof(res));
236 if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
239 return ((void *)&res);
244 nlm_share_3(argp, clnt)
248 static nlm_shareres res;
250 bzero((char *)&res, sizeof(res));
251 if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
259 nlm_unshare_3(argp, clnt)
263 static nlm_shareres res;
265 bzero((char *)&res, sizeof(res));
266 if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
274 nlm_nm_lock_3(argp, clnt)
280 bzero((char *)&res, sizeof(res));
281 if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
289 nlm_free_all_3(argp, clnt)
295 bzero((char *)&res, sizeof(res));
296 if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
299 return ((void *)&res);
303 int main(int argc, char **argv)
313 printf("usage: %s <lockd hostname>\n", argv[0]);
318 printf("Creating client for host %s\n", argv[1]);
319 cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
322 printf("Failed to create client\n");
327 clnt_control(cli, CLGET_TIMEOUT, &tim);
328 printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec);
331 clnt_control(cli, CLSET_TIMEOUT, &tim);
332 clnt_control(cli, CLGET_TIMEOUT, &tim);
333 printf("timeout now %d.%d\n", tim.tv_sec, tim.tv_usec);
336 arg.cookie.n_len = 4;
337 arg.cookie.n_bytes = "hello";
342 arg.alock.caller_name = "localhost";
343 arg.alock.fh.n_len = 32;
344 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";
345 arg.alock.oh.n_len = 8;
346 arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
347 arg.alock.svid = 0x5678;
348 arg.alock.l_offset = 0;
349 arg.alock.l_len = 100;
351 res_block.stat.stat = nlm_granted;
352 res_block.cookie.n_bytes = "hello";
353 res_block.cookie.n_len = 5;
356 if (nlm_lock_res_1(&res_block, cli)) printf("Success!\n");
357 else printf("Fail\n");
359 if (out = nlm_lock_msg_1(&arg, cli))
361 printf("Success!\n");
362 printf("out->stat = %d", out->stat);