-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_client.c
74 lines (66 loc) · 1.37 KB
/
math_client.c
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
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "math.h"
void
math_prog_1(char *host, int x, int y, int z)
{
CLIENT *clnt;
int *result_1;
numbers add_1_arg;
int *result_2;
int sqr_1_arg;
#ifndef DEBUG
clnt = clnt_create (host, MATH_PROG, ADO_VERS, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
if(y != NULL && z != NULL){
add_1_arg.a=x;
add_1_arg.b=y;
add_1_arg.c=z;
result_1 = add_1(&add_1_arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
else
{
printf("Add(%d,%d,%d):%d\n",x,y,z,*result_1);
}
}else{
sqr_1_arg = x;
result_2 = sqr_1(&sqr_1_arg, clnt);
if (result_2 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
else
{
printf("Sqr(%d):%d\n",x,*result_2);
}
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
if (argc == 3) {
host = argv[1];
math_prog_1 (host, atoi(argv[2]),NULL,NULL);
} else if (argc == 5){
host = argv[1];
math_prog_1 (host, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
}
else {
printf ("usage:\nSqr Syntax: %s server_host number\n", argv[0]);
printf ("Add Syntax: %s server_host number number number\n", argv[0]);
exit (1);
}
exit (0);
}