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