summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rpc.statd/test.c
blob: 6df15011db3b3a7ba41e6aa26fd776a5b12f15fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

#ifndef lint
static const char rcsid[] =
  "$FreeBSD$";
#endif /* not lint */

#include <stdio.h>
#include <rpc/rpc.h>
#include <rpcsvc/sm_inter.h>


/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };

struct sm_stat_res *
sm_stat_1(argp, clnt)
	struct sm_name *argp;
	CLIENT *clnt;
{
	static struct sm_stat_res res;

	bzero((char *)&res, sizeof(res));
	if (clnt_call(clnt, SM_STAT, xdr_sm_name, argp, xdr_sm_stat_res, &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


struct sm_stat_res *
sm_mon_1(argp, clnt)
	struct mon *argp;
	CLIENT *clnt;
{
	static struct sm_stat_res res;

	bzero((char *)&res, sizeof(res));
	if (clnt_call(clnt, SM_MON, xdr_mon, argp, xdr_sm_stat_res, &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


struct sm_stat *
sm_unmon_1(argp, clnt)
	struct mon_id *argp;
	CLIENT *clnt;
{
	static struct sm_stat res;

	bzero((char *)&res, sizeof(res));
	if (clnt_call(clnt, SM_UNMON, xdr_mon_id, argp, xdr_sm_stat, &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


struct sm_stat *
sm_unmon_all_1(argp, clnt)
	struct my_id *argp;
	CLIENT *clnt;
{
	static struct sm_stat res;

	bzero((char *)&res, sizeof(res));
	if (clnt_call(clnt, SM_UNMON_ALL, xdr_my_id, argp, xdr_sm_stat, &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return (&res);
}


void *
sm_simu_crash_1(argp, clnt)
	void *argp;
	CLIENT *clnt;
{
	static char res;

	bzero((char *)&res, sizeof(res));
	if (clnt_call(clnt, SM_SIMU_CRASH, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
		return (NULL);
	}
	return ((void *)&res);
}


int main(int argc, char **argv)
{
  CLIENT *cli;
  char dummy;
  void *out;
  struct mon mon;

  if (argc < 2)
  {
    fprintf(stderr, "usage: test <hostname> | crash\n");
    fprintf(stderr, "always talks to statd at localhost\n");
    exit(1);
  }

  printf("Creating client for localhost\n" );
  cli = clnt_create("localhost", SM_PROG, SM_VERS, "udp");
  if (!cli)
  {
    printf("Failed to create client\n");
    exit(1);
  }

  mon.mon_id.mon_name = argv[1];
  mon.mon_id.my_id.my_name = argv[1];
  mon.mon_id.my_id.my_prog = SM_PROG;
  mon.mon_id.my_id.my_vers = SM_VERS;
  mon.mon_id.my_id.my_proc = 1;	/* have it call sm_stat() !!!	*/

  if (strcmp(argv[1], "crash"))
  {
    /* Hostname given		*/
    struct sm_stat_res *res;
    if (res = sm_mon_1(&mon, cli))
    {
      printf("Success!\n");
    }
    else
    {
      printf("Fail\n");  
    }
  }
  else
  {
    if (out = sm_simu_crash_1(&dummy, cli))
    {
      printf("Success!\n");
    }
    else
    {
      printf("Fail\n");  
    }
  }

  return 0;
}
OpenPOWER on IntegriCloud