summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rpc.lockd/test.c
blob: 8a6dce685d9c11e2ea6e755b9a930e59e474b90c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*	$OpenBSD: test.c,v 1.7 2015/09/05 09:38:23 jsg Exp $	*/

#include <rpc/rpc.h>
#include <rpcsvc/nlm_prot.h>

/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = {0, 0};

nlm_testres *
nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
{
	static nlm_testres res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


nlm_res *
nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
{
	enum clnt_stat st;
	static nlm_res res;

	bzero((char *) &res, sizeof(res));
	if ((st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
	    &res, TIMEOUT)) != RPC_SUCCESS) {
		printf("clnt_call returns %d\n", st);
		clnt_perror(clnt, "humbug");
		return (NULL);
	}
	return (&res);
}


nlm_res *
nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
{
	static nlm_res res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


nlm_res *
nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
{
	static nlm_res res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


nlm_res *
nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
{
	static nlm_res res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


void   *
nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
		clnt_perror(clnt, "nlm_lock_msg_1");
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


void   *
nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


nlm_shareres *
nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
{
	static nlm_shareres res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


nlm_shareres *
nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
{
	static nlm_shareres res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


nlm_res *
nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
{
	static nlm_res res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


void   *
nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
{
	static char res;

	bzero((char *) &res, sizeof(res));
	if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void,
	    &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *) &res);
}


int 
main(int argc, char **argv)
{
	CLIENT *cli;
	nlm_res res_block;
	nlm_res *out;
	nlm_lockargs arg;
	struct timeval tim;

	printf("Creating client for host %s\n", argv[1]);
	cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
	if (!cli) {
		printf("Failed to create client\n");
		exit(1);
	}
	clnt_control(cli, CLGET_TIMEOUT, &tim);
	printf("Default timeout was %lld.%ld\n", (long long)tim.tv_sec,
	    tim.tv_usec);
	tim.tv_usec = -1;
	tim.tv_sec = -1;
	clnt_control(cli, CLSET_TIMEOUT, &tim);
	clnt_control(cli, CLGET_TIMEOUT, &tim);
	printf("timeout now %lld.%ld\n", (long long)tim.tv_sec,
	    tim.tv_usec);

	arg.cookie.n_len = 4;
	arg.cookie.n_bytes = "hello";
	arg.block = 0;
	arg.exclusive = 0;
	arg.reclaim = 0;
	arg.state = 0x1234;
	arg.alock.caller_name = "localhost";
	arg.alock.fh.n_len = 32;
	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";
	arg.alock.oh.n_len = 8;
	arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
	arg.alock.svid = 0x5678;
	arg.alock.l_offset = 0;
	arg.alock.l_len = 100;

	res_block.stat.stat = nlm_granted;
	res_block.cookie.n_bytes = "hello";
	res_block.cookie.n_len = 5;

#if 0
	if (nlm_lock_res_1(&res_block, cli))
		printf("Success!\n");
	else
		printf("Fail\n");
#else
	if (out = nlm_lock_msg_1(&arg, cli)) {
		printf("Success!\n");
		printf("out->stat = %d", out->stat);
	} else {
		printf("Fail\n");
	}
#endif

	return 0;
}