]>
git.saurik.com Git - apple/network_cmds.git/blob - rpc_lockd.tproj/test.c
1 /* $NetBSD: test.c,v 1.2 1997/10/18 04:01:21 lukem Exp $ */
5 #include <rpcsvc/nlm_prot.h>
8 static char sccsid
[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
9 static char sccsid
[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";
11 __RCSID("$NetBSD: test.c,v 1.2 1997/10/18 04:01:21 lukem Exp $");
12 static const char rcsid
[] = "$FreeBSD: src/usr.sbin/rpc.lockd/test.c,v 1.5 2001/03/19 12:50:09 alfred Exp $";
16 /* Default timeout can be changed using clnt_control() */
17 static struct timeval TIMEOUT
= { 0, 0 };
20 nlm_test_1(argp
, clnt
)
21 struct nlm_testargs
*argp
;
24 static nlm_testres res
;
26 bzero((char *)&res
, sizeof(res
));
27 if (clnt_call(clnt
, NLM_TEST
, xdr_nlm_testargs
, argp
, xdr_nlm_testres
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
35 nlm_lock_1(argp
, clnt
)
36 struct nlm_lockargs
*argp
;
42 bzero((char *)&res
, sizeof(res
));
43 if (st
= clnt_call(clnt
, NLM_LOCK
, xdr_nlm_lockargs
, argp
, xdr_nlm_res
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
44 printf("clnt_call returns %d\n", st
);
45 clnt_perror(clnt
, "humbug");
53 nlm_cancel_1(argp
, clnt
)
54 struct nlm_cancargs
*argp
;
59 bzero((char *)&res
, sizeof(res
));
60 if (clnt_call(clnt
, NLM_CANCEL
, xdr_nlm_cancargs
, argp
, xdr_nlm_res
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
68 nlm_unlock_1(argp
, clnt
)
69 struct nlm_unlockargs
*argp
;
74 bzero((char *)&res
, sizeof(res
));
75 if (clnt_call(clnt
, NLM_UNLOCK
, xdr_nlm_unlockargs
, argp
, xdr_nlm_res
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
83 nlm_granted_1(argp
, clnt
)
84 struct nlm_testargs
*argp
;
89 bzero((char *)&res
, sizeof(res
));
90 if (clnt_call(clnt
, NLM_GRANTED
, xdr_nlm_testargs
, argp
, xdr_nlm_res
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
98 nlm_test_msg_1(argp
, clnt
)
99 struct nlm_testargs
*argp
;
104 bzero((char *)&res
, sizeof(res
));
105 if (clnt_call(clnt
, NLM_TEST_MSG
, xdr_nlm_testargs
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
108 return ((void *)&res
);
113 nlm_lock_msg_1(argp
, clnt
)
114 struct nlm_lockargs
*argp
;
119 bzero((char *)&res
, sizeof(res
));
120 if (clnt_call(clnt
, NLM_LOCK_MSG
, xdr_nlm_lockargs
, argp
, xdr_void
, NULL
, TIMEOUT
) != RPC_SUCCESS
) {
121 clnt_perror(clnt
, "nlm_lock_msg_1");
124 return ((void *)&res
);
129 nlm_cancel_msg_1(argp
, clnt
)
130 struct nlm_cancargs
*argp
;
135 bzero((char *)&res
, sizeof(res
));
136 if (clnt_call(clnt
, NLM_CANCEL_MSG
, xdr_nlm_cancargs
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
139 return ((void *)&res
);
144 nlm_unlock_msg_1(argp
, clnt
)
145 struct nlm_unlockargs
*argp
;
150 bzero((char *)&res
, sizeof(res
));
151 if (clnt_call(clnt
, NLM_UNLOCK_MSG
, xdr_nlm_unlockargs
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
154 return ((void *)&res
);
159 nlm_granted_msg_1(argp
, clnt
)
160 struct nlm_testargs
*argp
;
165 bzero((char *)&res
, sizeof(res
));
166 if (clnt_call(clnt
, NLM_GRANTED_MSG
, xdr_nlm_testargs
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
169 return ((void *)&res
);
174 nlm_test_res_1(argp
, clnt
)
180 bzero((char *)&res
, sizeof(res
));
181 if (clnt_call(clnt
, NLM_TEST_RES
, xdr_nlm_testres
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
184 return ((void *)&res
);
189 nlm_lock_res_1(argp
, clnt
)
195 bzero((char *)&res
, sizeof(res
));
196 if (clnt_call(clnt
, NLM_LOCK_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
199 return ((void *)&res
);
204 nlm_cancel_res_1(argp
, clnt
)
210 bzero((char *)&res
, sizeof(res
));
211 if (clnt_call(clnt
, NLM_CANCEL_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
214 return ((void *)&res
);
219 nlm_unlock_res_1(argp
, clnt
)
225 bzero((char *)&res
, sizeof(res
));
226 if (clnt_call(clnt
, NLM_UNLOCK_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
229 return ((void *)&res
);
234 nlm_granted_res_1(argp
, clnt
)
240 bzero((char *)&res
, sizeof(res
));
241 if (clnt_call(clnt
, NLM_GRANTED_RES
, xdr_nlm_res
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
244 return ((void *)&res
);
249 nlm_share_3(argp
, clnt
)
253 static nlm_shareres res
;
255 bzero((char *)&res
, sizeof(res
));
256 if (clnt_call(clnt
, NLM_SHARE
, xdr_nlm_shareargs
, argp
, xdr_nlm_shareres
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
264 nlm_unshare_3(argp
, clnt
)
268 static nlm_shareres res
;
270 bzero((char *)&res
, sizeof(res
));
271 if (clnt_call(clnt
, NLM_UNSHARE
, xdr_nlm_shareargs
, argp
, xdr_nlm_shareres
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
279 nlm_nm_lock_3(argp
, clnt
)
285 bzero((char *)&res
, sizeof(res
));
286 if (clnt_call(clnt
, NLM_NM_LOCK
, xdr_nlm_lockargs
, argp
, xdr_nlm_res
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
294 nlm_free_all_3(argp
, clnt
)
300 bzero((char *)&res
, sizeof(res
));
301 if (clnt_call(clnt
, NLM_FREE_ALL
, xdr_nlm_notify
, argp
, xdr_void
, &res
, TIMEOUT
) != RPC_SUCCESS
) {
304 return ((void *)&res
);
308 int main(int argc
, char **argv
)
316 printf("Creating client for host %s\n", argv
[1]);
317 cli
= clnt_create(argv
[1], NLM_PROG
, NLM_VERS
, "udp");
319 errx(1, "Failed to create client\n");
322 clnt_control(cli
, CLGET_TIMEOUT
, &tim
);
323 printf("Default timeout was %d.%d\n", tim
.tv_sec
, tim
.tv_usec
);
326 clnt_control(cli
, CLSET_TIMEOUT
, &tim
);
327 clnt_control(cli
, CLGET_TIMEOUT
, &tim
);
328 printf("timeout now %d.%d\n", tim
.tv_sec
, tim
.tv_usec
);
331 arg
.cookie
.n_len
= 4;
332 arg
.cookie
.n_bytes
= "hello";
337 arg
.alock
.caller_name
= "localhost";
338 arg
.alock
.fh
.n_len
= 32;
339 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";
340 arg
.alock
.oh
.n_len
= 8;
341 arg
.alock
.oh
.n_bytes
= "\x00\x00\x02\xff\xff\xff\xd3";
342 arg
.alock
.svid
= 0x5678;
343 arg
.alock
.l_offset
= 0;
344 arg
.alock
.l_len
= 100;
346 res_block
.stat
.stat
= nlm_granted
;
347 res_block
.cookie
.n_bytes
= "hello";
348 res_block
.cookie
.n_len
= 5;
351 if (nlm_lock_res_1(&res_block
, cli
))
352 printf("Success!\n");
356 if (out
= nlm_lock_msg_1(&arg
, cli
)) {
357 printf("Success!\n");
358 printf("out->stat = %d", out
->stat
);