1 /* $NetBSD: test.c,v 1.3 2002/07/20 08:40:20 grant Exp $ */
7 #include <rpcsvc/nlm_prot.h>
11 static char sccsid
[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
12 static char sccsid
[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";
14 __RCSID("$NetBSD: test.c,v 1.3 2002/07/20 08:40:20 grant Exp $");
18 /* Default timeout can be changed using clnt_control() */
19 static struct timeval TIMEOUT
= {0, 0};
22 nlm_test_1(struct nlm_testargs
*argp
, CLIENT
*clnt
)
24 static nlm_testres res
;
26 (void)memset(&res
, 0, sizeof(res
));
27 if (clnt_call(clnt
, NLM_TEST
, xdr_nlm_testargs
, argp
, xdr_nlm_testres
,
28 &res
, TIMEOUT
) != RPC_SUCCESS
)
35 nlm_lock_1(struct nlm_lockargs
*argp
, CLIENT
*clnt
)
40 (void)memset(&res
, 0, sizeof(res
));
41 if (st
= clnt_call(clnt
, NLM_LOCK
, xdr_nlm_lockargs
, argp
, xdr_nlm_res
,
42 &res
, TIMEOUT
) != RPC_SUCCESS
) {
43 printf("clnt_call returns %d\n", st
);
44 clnt_perror(clnt
, "humbug");
52 nlm_cancel_1(struct nlm_cancargs
*argp
, CLIENT
*clnt
)
56 (void)memset(&res
, 0, sizeof(res
));
57 if (clnt_call(clnt
, NLM_CANCEL
, xdr_nlm_cancargs
, argp
, xdr_nlm_res
,
58 &res
, TIMEOUT
) != RPC_SUCCESS
) {
66 nlm_unlock_1(struct nlm_unlockargs
*argp
, CLIENT
*clnt
)
70 (void)memset(&res
, 0, sizeof(res
));
71 if (clnt_call(clnt
, NLM_UNLOCK
, xdr_nlm_unlockargs
, argp
, xdr_nlm_res
,
72 &res
, TIMEOUT
) != RPC_SUCCESS
) {
80 nlm_granted_1(struct nlm_testargs
*argp
, CLIENT
*clnt
)
84 (void)memset(&res
, 0, sizeof(res
));
85 if (clnt_call(clnt
, NLM_GRANTED
, xdr_nlm_testargs
, argp
, xdr_nlm_res
,
86 &res
, TIMEOUT
) != RPC_SUCCESS
) {
94 nlm_test_msg_1(struct nlm_testargs
*argp
, CLIENT
*clnt
)
98 (void)memset(&res
, 0, sizeof(res
));
99 if (clnt_call(clnt
, NLM_TEST_MSG
, xdr_nlm_testargs
, argp
, xdr_void
,
100 &res
, TIMEOUT
) != RPC_SUCCESS
) {
108 nlm_lock_msg_1(struct nlm_lockargs
*argp
, CLIENT
*clnt
)
112 (void)memset(&res
, 0, sizeof(res
));
113 if (clnt_call(clnt
, NLM_LOCK_MSG
, xdr_nlm_lockargs
, argp
, xdr_void
,
114 NULL
, TIMEOUT
) != RPC_SUCCESS
) {
115 clnt_perror(clnt
, "nlm_lock_msg_1");
123 nlm_cancel_msg_1(struct nlm_cancargs
*argp
, CLIENT
*clnt
)
127 (void)memset(&res
, 0, sizeof(res
));
128 if (clnt_call(clnt
, NLM_CANCEL_MSG
, xdr_nlm_cancargs
, argp
, xdr_void
,
129 &res
, TIMEOUT
) != RPC_SUCCESS
) {
137 nlm_unlock_msg_1(struct nlm_unlockargs
*argp
, CLIENT
*clnt
)
141 (void)memset(&res
, 0, sizeof(res
));
142 if (clnt_call(clnt
, NLM_UNLOCK_MSG
, xdr_nlm_unlockargs
, argp
, xdr_void
,
143 &res
, TIMEOUT
) != RPC_SUCCESS
) {
151 nlm_granted_msg_1(struct nlm_testargs
*argp
, CLIENT
*clnt
)
155 (void)memset(&res
, 0, sizeof(res
));
156 if (clnt_call(clnt
, NLM_GRANTED_MSG
, xdr_nlm_testargs
, argp
, xdr_void
,
157 &res
, TIMEOUT
) != RPC_SUCCESS
) {
165 nlm_test_res_1(nlm_testres
*argp
, CLIENT
*clnt
)
169 (void)memset(&res
, 0, sizeof(res
));
170 if (clnt_call(clnt
, NLM_TEST_RES
, xdr_nlm_testres
, argp
, xdr_void
, &res
,
171 TIMEOUT
) != RPC_SUCCESS
) {
179 nlm_lock_res_1(nlm_res
*argp
, CLIENT
*clnt
)
183 (void)memset(&res
, 0, sizeof(res
));
184 if (clnt_call(clnt
, NLM_LOCK_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
,
185 TIMEOUT
) != RPC_SUCCESS
) {
193 nlm_cancel_res_1(nlm_res
*argp
, CLIENT
*clnt
)
197 (void)memset(&res
, 0, sizeof(res
));
198 if (clnt_call(clnt
, NLM_CANCEL_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
,
199 TIMEOUT
) != RPC_SUCCESS
) {
207 nlm_unlock_res_1(nlm_res
*argp
, CLIENT
*clnt
)
211 (void)memset(&res
, 0, sizeof(res
));
212 if (clnt_call(clnt
, NLM_UNLOCK_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
,
213 TIMEOUT
) != RPC_SUCCESS
) {
221 nlm_granted_res_1(nlm_res
*argp
, CLIENT
*clnt
)
225 (void)memset(&res
, 0, sizeof(res
));
226 if (clnt_call(clnt
, NLM_GRANTED_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
,
227 TIMEOUT
) != RPC_SUCCESS
) {
235 nlm_share_3(nlm_shareargs
*argp
, CLIENT
*clnt
)
237 static nlm_shareres res
;
239 (void)memset(&res
, 0, sizeof(res
));
240 if (clnt_call(clnt
, NLM_SHARE
, xdr_nlm_shareargs
, argp
,
241 xdr_nlm_shareres
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
249 nlm_unshare_3(nlm_shareargs
*argp
, CLIENT
*clnt
)
251 static nlm_shareres res
;
253 (void)memset(&res
, 0, sizeof(res
));
254 if (clnt_call(clnt
, NLM_UNSHARE
, xdr_nlm_shareargs
, argp
,
255 xdr_nlm_shareres
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
263 nlm_nm_lock_3(nlm_lockargs
*argp
, CLIENT
*clnt
)
267 (void)memset(&res
, 0, sizeof(res
));
268 if (clnt_call(clnt
, NLM_NM_LOCK
, xdr_nlm_lockargs
, argp
, xdr_nlm_res
,
269 &res
, TIMEOUT
) != RPC_SUCCESS
) {
277 nlm_free_all_3(nlm_notify
*argp
, CLIENT
*clnt
)
281 (void)memset(&res
, 0, sizeof(res
));
282 if (clnt_call(clnt
, NLM_FREE_ALL
, xdr_nlm_notify
, argp
, xdr_void
, &res
,
283 TIMEOUT
) != RPC_SUCCESS
) {
291 main(int argc
, char **argv
)
299 printf("Creating client for host %s\n", argv
[1]);
300 cli
= clnt_create(argv
[1], NLM_PROG
, NLM_VERS
, "udp");
302 errx(1, "Failed to create client");
305 clnt_control(cli
, CLGET_TIMEOUT
, (void *)&tim
);
306 printf("Default timeout was %d.%d\n", tim
.tv_sec
, tim
.tv_usec
);
309 clnt_control(cli
, CLSET_TIMEOUT
, (void *)&tim
);
310 clnt_control(cli
, CLGET_TIMEOUT
, (void *)&tim
);
311 printf("timeout now %d.%d\n", tim
.tv_sec
, tim
.tv_usec
);
314 arg
.cookie
.n_len
= 4;
315 arg
.cookie
.n_bytes
= "hello";
320 arg
.alock
.caller_name
= "localhost";
321 arg
.alock
.fh
.n_len
= 32;
322 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 arg
.alock
.oh
.n_len
= 8;
324 arg
.alock
.oh
.n_bytes
= "\x00\x00\x02\xff\xff\xff\xd3";
325 arg
.alock
.svid
= 0x5678;
326 arg
.alock
.l_offset
= 0;
327 arg
.alock
.l_len
= 100;
329 res_block
.stat
.stat
= nlm_granted
;
330 res_block
.cookie
.n_bytes
= "hello";
331 res_block
.cookie
.n_len
= 5;
334 if (nlm_lock_res_1(&res_block
, cli
))
335 printf("Success!\n");
339 if (out
= nlm_lock_msg_1(&arg
, cli
)) {
340 printf("Success!\n");
341 printf("out->stat = %d", out
->stat
);