Home | History | Annotate | Line # | Download | only in rpc.lockd
test.c revision 1.4
      1 /*	$NetBSD: test.c,v 1.4 2007/11/04 23:12:50 christos Exp $	*/
      2 
      3 #include <stdio.h>
      4 #include <string.h>
      5 #include <sys/cdefs.h>
      6 #include <rpc/rpc.h>
      7 #include <rpcsvc/nlm_prot.h>
      8 
      9 #ifndef lint
     10 #if 0
     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";
     13 #else
     14 __RCSID("$NetBSD: test.c,v 1.4 2007/11/04 23:12:50 christos Exp $");
     15 #endif
     16 #endif				/* not lint */
     17 
     18 /* Default timeout can be changed using clnt_control() */
     19 static struct timeval TIMEOUT = {0, 0};
     20 
     21 nlm_testres *
     22 nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
     23 {
     24 	static nlm_testres res;
     25 
     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)
     29 		return NULL;
     30 	return &res;
     31 }
     32 
     33 
     34 nlm_res *
     35 nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
     36 {
     37 	enum clnt_stat st;
     38 	static nlm_res res;
     39 
     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");
     45 		return NULL;
     46 	}
     47 	return &res;
     48 }
     49 
     50 
     51 nlm_res *
     52 nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
     53 {
     54 	static nlm_res res;
     55 
     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) {
     59 		return NULL;
     60 	}
     61 	return &res;
     62 }
     63 
     64 
     65 nlm_res *
     66 nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
     67 {
     68 	static nlm_res res;
     69 
     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) {
     73 		return NULL;
     74 	}
     75 	return &res;
     76 }
     77 
     78 
     79 nlm_res *
     80 nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
     81 {
     82 	static nlm_res res;
     83 
     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) {
     87 		return NULL;
     88 	}
     89 	return &res;
     90 }
     91 
     92 
     93 void *
     94 nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
     95 {
     96 	static char res;
     97 
     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) {
    101 		return NULL;
    102 	}
    103 	return &res;
    104 }
    105 
    106 
    107 void *
    108 nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
    109 {
    110 	static char res;
    111 
    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");
    116 		return NULL;
    117 	}
    118 	return &res;
    119 }
    120 
    121 
    122 void *
    123 nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
    124 {
    125 	static char res;
    126 
    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) {
    130 		return NULL;
    131 	}
    132 	return &res;
    133 }
    134 
    135 
    136 void *
    137 nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
    138 {
    139 	static char res;
    140 
    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) {
    144 		return NULL;
    145 	}
    146 	return &res;
    147 }
    148 
    149 
    150 void *
    151 nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
    152 {
    153 	static char res;
    154 
    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) {
    158 		return NULL;
    159 	}
    160 	return &res;
    161 }
    162 
    163 
    164 void *
    165 nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
    166 {
    167 	static char res;
    168 
    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) {
    172 		return NULL;
    173 	}
    174 	return &res;
    175 }
    176 
    177 
    178 void *
    179 nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
    180 {
    181 	static char res;
    182 
    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) {
    186 		return NULL;
    187 	}
    188 	return &res;
    189 }
    190 
    191 
    192 void *
    193 nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
    194 {
    195 	static char res;
    196 
    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) {
    200 		return NULL;
    201 	}
    202 	return &res;
    203 }
    204 
    205 
    206 void *
    207 nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
    208 {
    209 	static char res;
    210 
    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) {
    214 		return NULL;
    215 	}
    216 	return &res;
    217 }
    218 
    219 
    220 void *
    221 nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
    222 {
    223 	static char res;
    224 
    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) {
    228 		return NULL;
    229 	}
    230 	return &res;
    231 }
    232 
    233 
    234 nlm_shareres *
    235 nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
    236 {
    237 	static nlm_shareres res;
    238 
    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) {
    242 		return NULL;
    243 	}
    244 	return &res;
    245 }
    246 
    247 
    248 nlm_shareres *
    249 nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
    250 {
    251 	static nlm_shareres res;
    252 
    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) {
    256 		return NULL;
    257 	}
    258 	return &res;
    259 }
    260 
    261 
    262 nlm_res *
    263 nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
    264 {
    265 	static nlm_res res;
    266 
    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) {
    270 		return NULL;
    271 	}
    272 	return &res;
    273 }
    274 
    275 
    276 void *
    277 nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
    278 {
    279 	static char res;
    280 
    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) {
    284 		return NULL;
    285 	}
    286 	return &res;
    287 }
    288 
    289 
    290 int
    291 main(int argc, char **argv)
    292 {
    293 	CLIENT *cli;
    294 	nlm_res res_block;
    295 	nlm_res *out;
    296 	nlm_lockargs arg;
    297 	struct timeval tim;
    298 
    299 	printf("Creating client for host %s\n", argv[1]);
    300 	cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
    301 	if (!cli) {
    302 		errx(1, "Failed to create client");
    303 		/* NOTREACHED */
    304 	}
    305 	clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
    306 	printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec);
    307 	tim.tv_usec = -1;
    308 	tim.tv_sec = -1;
    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);
    312 
    313 
    314 	arg.cookie.n_len = 4;
    315 	arg.cookie.n_bytes = "hello";
    316 	arg.block = 0;
    317 	arg.exclusive = 0;
    318 	arg.reclaim = 0;
    319 	arg.state = 0x1234;
    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;
    328 
    329 	res_block.stat.stat = nlm_granted;
    330 	res_block.cookie.n_bytes = "hello";
    331 	res_block.cookie.n_len = 5;
    332 
    333 #if 0
    334 	if (nlm_lock_res_1(&res_block, cli))
    335 		printf("Success!\n");
    336 	else
    337 		printf("Fail\n");
    338 #else
    339 	if (out = nlm_lock_msg_1(&arg, cli)) {
    340 		printf("Success!\n");
    341 		printf("out->stat = %d", out->stat);
    342 	} else {
    343 		printf("Fail\n");
    344 	}
    345 #endif
    346 
    347 	return 0;
    348 }
    349