Home | History | Annotate | Line # | Download | only in rpc.statd
      1  1.3   sevan /*	$NetBSD: test.c,v 1.3 2018/01/23 21:06:26 sevan Exp $	*/
      2  1.2   lukem 
      3  1.2   lukem #include <sys/cdefs.h>
      4  1.2   lukem #ifndef lint
      5  1.3   sevan __RCSID("$NetBSD: test.c,v 1.3 2018/01/23 21:06:26 sevan Exp $");
      6  1.2   lukem #endif
      7  1.1  scottr 
      8  1.1  scottr #include <stdio.h>
      9  1.1  scottr #include <rpc/rpc.h>
     10  1.1  scottr #include <rpcsvc/sm_inter.h>
     11  1.1  scottr 
     12  1.1  scottr 
     13  1.1  scottr /* Default timeout can be changed using clnt_control() */
     14  1.1  scottr static struct timeval TIMEOUT = {25, 0};
     15  1.1  scottr 
     16  1.1  scottr struct sm_stat_res *
     17  1.3   sevan sm_stat_1(struct sm_name *argp, CLIENT *clnt)
     18  1.1  scottr {
     19  1.1  scottr 	static struct sm_stat_res res;
     20  1.1  scottr 
     21  1.1  scottr 	bzero((char *) &res, sizeof(res));
     22  1.1  scottr 	if (clnt_call(clnt, SM_STAT, xdr_sm_name, argp, xdr_sm_stat_res,
     23  1.1  scottr 	    &res, TIMEOUT) != RPC_SUCCESS)
     24  1.1  scottr 		return (NULL);
     25  1.1  scottr 	return (&res);
     26  1.1  scottr }
     27  1.1  scottr 
     28  1.1  scottr 
     29  1.1  scottr struct sm_stat_res *
     30  1.3   sevan sm_mon_1(struct mon *argp, CLIENT *clnt)
     31  1.1  scottr {
     32  1.1  scottr 	static struct sm_stat_res res;
     33  1.1  scottr 
     34  1.1  scottr 	bzero((char *) &res, sizeof(res));
     35  1.1  scottr 	if (clnt_call(clnt, SM_MON, xdr_mon, argp, xdr_sm_stat_res,
     36  1.1  scottr 	    &res, TIMEOUT) != RPC_SUCCESS)
     37  1.1  scottr 		return (NULL);
     38  1.1  scottr 	return (&res);
     39  1.1  scottr }
     40  1.1  scottr 
     41  1.1  scottr 
     42  1.1  scottr struct sm_stat *
     43  1.3   sevan sm_unmon_1(struct mon_id *argp, CLIENT *clnt)
     44  1.1  scottr {
     45  1.1  scottr 	static struct sm_stat res;
     46  1.1  scottr 
     47  1.1  scottr 	bzero((char *) &res, sizeof(res));
     48  1.1  scottr 	if (clnt_call(clnt, SM_UNMON, xdr_mon_id, argp, xdr_sm_stat,
     49  1.1  scottr 	    &res, TIMEOUT) != RPC_SUCCESS)
     50  1.1  scottr 		return (NULL);
     51  1.1  scottr 	return (&res);
     52  1.1  scottr }
     53  1.1  scottr 
     54  1.1  scottr 
     55  1.1  scottr struct sm_stat *
     56  1.3   sevan sm_unmon_all_1(struct my_id *argp, CLIENT *clnt)
     57  1.1  scottr {
     58  1.1  scottr 	static struct sm_stat res;
     59  1.1  scottr 
     60  1.1  scottr 	bzero((char *) &res, sizeof(res));
     61  1.1  scottr 	if (clnt_call(clnt, SM_UNMON_ALL, xdr_my_id, argp, xdr_sm_stat,
     62  1.1  scottr 	    &res, TIMEOUT) != RPC_SUCCESS)
     63  1.1  scottr 		return (NULL);
     64  1.1  scottr 	return (&res);
     65  1.1  scottr }
     66  1.1  scottr 
     67  1.1  scottr 
     68  1.1  scottr void *
     69  1.3   sevan sm_simu_crash_1(void   *argp, CLIENT *clnt)
     70  1.1  scottr {
     71  1.1  scottr 	static char res;
     72  1.1  scottr 
     73  1.1  scottr 	bzero((char *) &res, sizeof(res));
     74  1.1  scottr 	if (clnt_call(clnt, SM_SIMU_CRASH, xdr_void, argp, xdr_void,
     75  1.1  scottr 	    &res, TIMEOUT) != RPC_SUCCESS)
     76  1.1  scottr 		return (NULL);
     77  1.1  scottr 	return ((void *) &res);
     78  1.1  scottr }
     79  1.1  scottr 
     80  1.1  scottr 
     81  1.1  scottr int
     82  1.3   sevan main(int argc, char *argv[])
     83  1.1  scottr {
     84  1.1  scottr 	CLIENT *cli;
     85  1.1  scottr 	char dummy;
     86  1.1  scottr 	void *out;
     87  1.1  scottr 	struct mon mon;
     88  1.1  scottr 
     89  1.1  scottr 	if (argc < 2) {
     90  1.1  scottr 		warnx("usage: test {<hostname> | crash}");
     91  1.1  scottr 		errx(1, "Always talks to statd at localhost");
     92  1.1  scottr 	}
     93  1.1  scottr 	printf("Creating client for localhost\n");
     94  1.1  scottr 	cli = clnt_create("localhost", SM_PROG, SM_VERS, "udp");
     95  1.1  scottr 	if (!cli) {
     96  1.1  scottr 		errx(1, "Failed to create client");
     97  1.1  scottr 	}
     98  1.1  scottr 	mon.mon_id.mon_name = argv[1];
     99  1.1  scottr 	mon.mon_id.my_id.my_name = argv[1];
    100  1.1  scottr 	mon.mon_id.my_id.my_prog = SM_PROG;
    101  1.1  scottr 	mon.mon_id.my_id.my_vers = SM_VERS;
    102  1.1  scottr 	mon.mon_id.my_id.my_proc = 1;	/* have it call sm_stat() !!! */
    103  1.1  scottr 
    104  1.1  scottr 	if (strcmp(argv[1], "crash")) {
    105  1.1  scottr 		/* Hostname given */
    106  1.1  scottr 		struct sm_stat_res *res;
    107  1.1  scottr 		if (res = sm_mon_1(&mon, cli))
    108  1.1  scottr 			printf("Success!\n");
    109  1.1  scottr 		else
    110  1.1  scottr 			printf("Fail\n");
    111  1.1  scottr 	} else {
    112  1.1  scottr 		if (out = sm_simu_crash_1(&dummy, cli))
    113  1.1  scottr 			printf("Success!\n");
    114  1.1  scottr 		else
    115  1.1  scottr 			printf("Fail\n");
    116  1.1  scottr 	}
    117  1.1  scottr 
    118  1.1  scottr 	return 0;
    119  1.1  scottr }
    120