test.c revision 74462
174462Salfred/* $NetBSD: test.c,v 1.2 1997/10/18 04:01:21 lukem Exp $ */ 274462Salfred 374462Salfred#include <sys/cdefs.h> 474462Salfred#include <rpc/rpc.h> 574462Salfred#include <rpcsvc/nlm_prot.h> 614123Speter#ifndef lint 730376Scharnier#if 0 830376Scharnierstatic char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro"; 930376Scharnierstatic char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC"; 1074462Salfred#else 1174462Salfred__RCSID("$NetBSD: test.c,v 1.2 1997/10/18 04:01:21 lukem Exp $"); 1274462Salfredstatic const char rcsid[] = "$FreeBSD: head/usr.sbin/rpc.lockd/test.c 74462 2001-03-19 12:50:13Z alfred $"; 1330376Scharnier#endif 1474462Salfred#endif /* not lint */ 1514123Speter 1614123Speter/* Default timeout can be changed using clnt_control() */ 1714123Speterstatic struct timeval TIMEOUT = { 0, 0 }; 1814123Speter 1914123Speternlm_testres * 2014123Speternlm_test_1(argp, clnt) 2114123Speter struct nlm_testargs *argp; 2214123Speter CLIENT *clnt; 2314123Speter{ 2414123Speter static nlm_testres res; 2514123Speter 2614123Speter bzero((char *)&res, sizeof(res)); 2714123Speter if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres, &res, TIMEOUT) != RPC_SUCCESS) { 2814123Speter return (NULL); 2914123Speter } 3014123Speter return (&res); 3114123Speter} 3214123Speter 3314123Speter 3414123Speternlm_res * 3514123Speternlm_lock_1(argp, clnt) 3614123Speter struct nlm_lockargs *argp; 3714123Speter CLIENT *clnt; 3814123Speter{ 3914123Speter enum clnt_stat st; 4014123Speter static nlm_res res; 4114123Speter 4214123Speter bzero((char *)&res, sizeof(res)); 4314123Speter if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) { 4414123Speter printf("clnt_call returns %d\n", st); 4514123Speter clnt_perror(clnt, "humbug"); 4614123Speter return (NULL); 4714123Speter } 4814123Speter return (&res); 4914123Speter} 5014123Speter 5114123Speter 5214123Speternlm_res * 5314123Speternlm_cancel_1(argp, clnt) 5414123Speter struct nlm_cancargs *argp; 5514123Speter CLIENT *clnt; 5614123Speter{ 5714123Speter static nlm_res res; 5814123Speter 5914123Speter bzero((char *)&res, sizeof(res)); 6014123Speter if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) { 6114123Speter return (NULL); 6214123Speter } 6314123Speter return (&res); 6414123Speter} 6514123Speter 6614123Speter 6714123Speternlm_res * 6814123Speternlm_unlock_1(argp, clnt) 6914123Speter struct nlm_unlockargs *argp; 7014123Speter CLIENT *clnt; 7114123Speter{ 7214123Speter static nlm_res res; 7314123Speter 7414123Speter bzero((char *)&res, sizeof(res)); 7514123Speter if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) { 7614123Speter return (NULL); 7714123Speter } 7814123Speter return (&res); 7914123Speter} 8014123Speter 8114123Speter 8214123Speternlm_res * 8314123Speternlm_granted_1(argp, clnt) 8414123Speter struct nlm_testargs *argp; 8514123Speter CLIENT *clnt; 8614123Speter{ 8714123Speter static nlm_res res; 8814123Speter 8914123Speter bzero((char *)&res, sizeof(res)); 9014123Speter if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) { 9114123Speter return (NULL); 9214123Speter } 9314123Speter return (&res); 9414123Speter} 9514123Speter 9614123Speter 9714123Spetervoid * 9814123Speternlm_test_msg_1(argp, clnt) 9914123Speter struct nlm_testargs *argp; 10014123Speter CLIENT *clnt; 10114123Speter{ 10214123Speter static char res; 10314123Speter 10414123Speter bzero((char *)&res, sizeof(res)); 10514123Speter if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 10614123Speter return (NULL); 10714123Speter } 10814123Speter return ((void *)&res); 10914123Speter} 11014123Speter 11114123Speter 11214123Spetervoid * 11314123Speternlm_lock_msg_1(argp, clnt) 11414123Speter struct nlm_lockargs *argp; 11514123Speter CLIENT *clnt; 11614123Speter{ 11714123Speter static char res; 11814123Speter 11914123Speter bzero((char *)&res, sizeof(res)); 12014123Speter if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) { 12114123Speter clnt_perror(clnt, "nlm_lock_msg_1"); 12214123Speter return (NULL); 12314123Speter } 12414123Speter return ((void *)&res); 12514123Speter} 12614123Speter 12714123Speter 12814123Spetervoid * 12914123Speternlm_cancel_msg_1(argp, clnt) 13014123Speter struct nlm_cancargs *argp; 13114123Speter CLIENT *clnt; 13214123Speter{ 13314123Speter static char res; 13414123Speter 13514123Speter bzero((char *)&res, sizeof(res)); 13614123Speter if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 13714123Speter return (NULL); 13814123Speter } 13914123Speter return ((void *)&res); 14014123Speter} 14114123Speter 14214123Speter 14314123Spetervoid * 14414123Speternlm_unlock_msg_1(argp, clnt) 14514123Speter struct nlm_unlockargs *argp; 14614123Speter CLIENT *clnt; 14714123Speter{ 14814123Speter static char res; 14914123Speter 15014123Speter bzero((char *)&res, sizeof(res)); 15114123Speter if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 15214123Speter return (NULL); 15314123Speter } 15414123Speter return ((void *)&res); 15514123Speter} 15614123Speter 15714123Speter 15814123Spetervoid * 15914123Speternlm_granted_msg_1(argp, clnt) 16014123Speter struct nlm_testargs *argp; 16114123Speter CLIENT *clnt; 16214123Speter{ 16314123Speter static char res; 16414123Speter 16514123Speter bzero((char *)&res, sizeof(res)); 16614123Speter if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 16714123Speter return (NULL); 16814123Speter } 16914123Speter return ((void *)&res); 17014123Speter} 17114123Speter 17214123Speter 17314123Spetervoid * 17414123Speternlm_test_res_1(argp, clnt) 17514123Speter nlm_testres *argp; 17614123Speter CLIENT *clnt; 17714123Speter{ 17814123Speter static char res; 17914123Speter 18014123Speter bzero((char *)&res, sizeof(res)); 18114123Speter if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 18214123Speter return (NULL); 18314123Speter } 18414123Speter return ((void *)&res); 18514123Speter} 18614123Speter 18714123Speter 18814123Spetervoid * 18914123Speternlm_lock_res_1(argp, clnt) 19014123Speter nlm_res *argp; 19114123Speter CLIENT *clnt; 19214123Speter{ 19314123Speter static char res; 19414123Speter 19514123Speter bzero((char *)&res, sizeof(res)); 19614123Speter if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 19714123Speter return (NULL); 19814123Speter } 19914123Speter return ((void *)&res); 20014123Speter} 20114123Speter 20214123Speter 20314123Spetervoid * 20414123Speternlm_cancel_res_1(argp, clnt) 20514123Speter nlm_res *argp; 20614123Speter CLIENT *clnt; 20714123Speter{ 20814123Speter static char res; 20914123Speter 21014123Speter bzero((char *)&res, sizeof(res)); 21114123Speter if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 21214123Speter return (NULL); 21314123Speter } 21414123Speter return ((void *)&res); 21514123Speter} 21614123Speter 21714123Speter 21814123Spetervoid * 21914123Speternlm_unlock_res_1(argp, clnt) 22014123Speter nlm_res *argp; 22114123Speter CLIENT *clnt; 22214123Speter{ 22314123Speter static char res; 22414123Speter 22514123Speter bzero((char *)&res, sizeof(res)); 22614123Speter if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 22714123Speter return (NULL); 22814123Speter } 22914123Speter return ((void *)&res); 23014123Speter} 23114123Speter 23214123Speter 23314123Spetervoid * 23414123Speternlm_granted_res_1(argp, clnt) 23514123Speter nlm_res *argp; 23614123Speter CLIENT *clnt; 23714123Speter{ 23814123Speter static char res; 23914123Speter 24014123Speter bzero((char *)&res, sizeof(res)); 24114123Speter if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 24214123Speter return (NULL); 24314123Speter } 24414123Speter return ((void *)&res); 24514123Speter} 24614123Speter 24714123Speter 24814123Speternlm_shareres * 24914123Speternlm_share_3(argp, clnt) 25014123Speter nlm_shareargs *argp; 25114123Speter CLIENT *clnt; 25214123Speter{ 25314123Speter static nlm_shareres res; 25414123Speter 25514123Speter bzero((char *)&res, sizeof(res)); 25614123Speter if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) { 25714123Speter return (NULL); 25814123Speter } 25914123Speter return (&res); 26014123Speter} 26114123Speter 26214123Speter 26314123Speternlm_shareres * 26414123Speternlm_unshare_3(argp, clnt) 26514123Speter nlm_shareargs *argp; 26614123Speter CLIENT *clnt; 26714123Speter{ 26814123Speter static nlm_shareres res; 26914123Speter 27014123Speter bzero((char *)&res, sizeof(res)); 27114123Speter if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) { 27214123Speter return (NULL); 27314123Speter } 27414123Speter return (&res); 27514123Speter} 27614123Speter 27714123Speter 27814123Speternlm_res * 27914123Speternlm_nm_lock_3(argp, clnt) 28014123Speter nlm_lockargs *argp; 28114123Speter CLIENT *clnt; 28214123Speter{ 28314123Speter static nlm_res res; 28414123Speter 28514123Speter bzero((char *)&res, sizeof(res)); 28614123Speter if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) { 28714123Speter return (NULL); 28814123Speter } 28914123Speter return (&res); 29014123Speter} 29114123Speter 29214123Speter 29314123Spetervoid * 29414123Speternlm_free_all_3(argp, clnt) 29514123Speter nlm_notify *argp; 29614123Speter CLIENT *clnt; 29714123Speter{ 29814123Speter static char res; 29914123Speter 30014123Speter bzero((char *)&res, sizeof(res)); 30114123Speter if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { 30214123Speter return (NULL); 30314123Speter } 30414123Speter return ((void *)&res); 30514123Speter} 30614123Speter 30714123Speter 30814123Speterint main(int argc, char **argv) 30914123Speter{ 31074462Salfred CLIENT *cli; 31174462Salfred nlm_res res_block; 31274462Salfred nlm_res *out; 31374462Salfred nlm_lockargs arg; 31474462Salfred struct timeval tim; 31514123Speter 31674462Salfred printf("Creating client for host %s\n", argv[1]); 31774462Salfred cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp"); 31874462Salfred if (!cli) { 31974462Salfred errx(1, "Failed to create client\n"); 32074462Salfred /* NOTREACHED */ 32174462Salfred } 32274462Salfred clnt_control(cli, CLGET_TIMEOUT, &tim); 32374462Salfred printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec); 32474462Salfred tim.tv_usec = -1; 32574462Salfred tim.tv_sec = -1; 32674462Salfred clnt_control(cli, CLSET_TIMEOUT, &tim); 32774462Salfred clnt_control(cli, CLGET_TIMEOUT, &tim); 32874462Salfred printf("timeout now %d.%d\n", tim.tv_sec, tim.tv_usec); 32914123Speter 33014981Speter 33174462Salfred arg.cookie.n_len = 4; 33274462Salfred arg.cookie.n_bytes = "hello"; 33374462Salfred arg.block = 0; 33474462Salfred arg.exclusive = 0; 33574462Salfred arg.reclaim = 0; 33674462Salfred arg.state = 0x1234; 33774462Salfred arg.alock.caller_name = "localhost"; 33874462Salfred arg.alock.fh.n_len = 32; 33974462Salfred 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"; 34074462Salfred arg.alock.oh.n_len = 8; 34174462Salfred arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3"; 34274462Salfred arg.alock.svid = 0x5678; 34374462Salfred arg.alock.l_offset = 0; 34474462Salfred arg.alock.l_len = 100; 34514123Speter 34674462Salfred res_block.stat.stat = nlm_granted; 34774462Salfred res_block.cookie.n_bytes = "hello"; 34874462Salfred res_block.cookie.n_len = 5; 34914123Speter 35014123Speter#if 0 35174462Salfred if (nlm_lock_res_1(&res_block, cli)) 35274462Salfred printf("Success!\n"); 35374462Salfred else 35474462Salfred printf("Fail\n"); 35514123Speter#else 35674462Salfred if (out = nlm_lock_msg_1(&arg, cli)) { 35774462Salfred printf("Success!\n"); 35874462Salfred printf("out->stat = %d", out->stat); 35974462Salfred } else { 36074462Salfred printf("Fail\n"); 36174462Salfred } 36214123Speter#endif 36314123Speter 36474462Salfred return 0; 36514123Speter} 366