xref: /freebsd/usr.sbin/rpc.statd/test.c (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 #ifndef lint
2 static const char rcsid[] =
3   "$FreeBSD$";
4 #endif /* not lint */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <rpc/rpc.h>
10 #include <rpcsvc/sm_inter.h>
11 
12 /* Default timeout can be changed using clnt_control() */
13 static struct timeval TIMEOUT = { 25, 0 };
14 
15 struct sm_stat_res *
16 sm_stat_1(argp, clnt)
17 	struct sm_name *argp;
18 	CLIENT *clnt;
19 {
20 	static struct sm_stat_res res;
21 
22 	bzero((char *)&res, sizeof(res));
23 	if (clnt_call(clnt, SM_STAT, (xdrproc_t)xdr_sm_name, argp,
24 	    (xdrproc_t)xdr_sm_stat_res, &res, TIMEOUT) != RPC_SUCCESS) {
25 		return (NULL);
26 	}
27 	return (&res);
28 }
29 
30 
31 struct sm_stat_res *
32 sm_mon_1(argp, clnt)
33 	struct mon *argp;
34 	CLIENT *clnt;
35 {
36 	static struct sm_stat_res res;
37 
38 	bzero((char *)&res, sizeof(res));
39 	if (clnt_call(clnt, SM_MON, (xdrproc_t)xdr_mon, argp,
40 	    (xdrproc_t)xdr_sm_stat_res, &res, TIMEOUT) != RPC_SUCCESS) {
41 		return (NULL);
42 	}
43 	return (&res);
44 }
45 
46 
47 struct sm_stat *
48 sm_unmon_1(argp, clnt)
49 	struct mon_id *argp;
50 	CLIENT *clnt;
51 {
52 	static struct sm_stat res;
53 
54 	bzero((char *)&res, sizeof(res));
55 	if (clnt_call(clnt, SM_UNMON, (xdrproc_t)xdr_mon_id, argp,
56 	    (xdrproc_t)xdr_sm_stat, &res, TIMEOUT) != RPC_SUCCESS) {
57 		return (NULL);
58 	}
59 	return (&res);
60 }
61 
62 
63 struct sm_stat *
64 sm_unmon_all_1(argp, clnt)
65 	struct my_id *argp;
66 	CLIENT *clnt;
67 {
68 	static struct sm_stat res;
69 
70 	bzero((char *)&res, sizeof(res));
71 	if (clnt_call(clnt, SM_UNMON_ALL, (xdrproc_t)xdr_my_id, argp,
72 	    (xdrproc_t)xdr_sm_stat, &res, TIMEOUT) != RPC_SUCCESS) {
73 		return (NULL);
74 	}
75 	return (&res);
76 }
77 
78 
79 void *
80 sm_simu_crash_1(argp, clnt)
81 	void *argp;
82 	CLIENT *clnt;
83 {
84 	static char res;
85 
86 	bzero((char *)&res, sizeof(res));
87 	if (clnt_call(clnt, SM_SIMU_CRASH, (xdrproc_t)xdr_void, argp,
88 	    (xdrproc_t)xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
89 		return (NULL);
90 	}
91 	return ((void *)&res);
92 }
93 
94 
95 int main(int argc, char **argv)
96 {
97   CLIENT *cli;
98   char dummy;
99   void *out;
100   struct mon mon;
101 
102   if (argc < 2)
103   {
104     fprintf(stderr, "usage: test <hostname> | crash\n");
105     fprintf(stderr, "always talks to statd at localhost\n");
106     exit(1);
107   }
108 
109   printf("Creating client for localhost\n" );
110   cli = clnt_create("localhost", SM_PROG, SM_VERS, "udp");
111   if (!cli)
112   {
113     printf("Failed to create client\n");
114     exit(1);
115   }
116 
117   mon.mon_id.mon_name = argv[1];
118   mon.mon_id.my_id.my_name = argv[1];
119   mon.mon_id.my_id.my_prog = SM_PROG;
120   mon.mon_id.my_id.my_vers = SM_VERS;
121   mon.mon_id.my_id.my_proc = 1;	/* have it call sm_stat() !!!	*/
122 
123   if (strcmp(argv[1], "crash"))
124   {
125     /* Hostname given		*/
126     struct sm_stat_res *res;
127 
128     res = sm_mon_1(&mon, cli);
129     if (res)
130       printf("Success!\n");
131     else
132       printf("Fail\n");
133   }
134   else
135   {
136     out = sm_simu_crash_1(&dummy, cli);
137     if (out)
138       printf("Success!\n");
139     else
140       printf("Fail\n");
141   }
142 
143   return 0;
144 }
145