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