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