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