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
|
/*
* 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 "phonebook.h"
#include <stdio.h>
void
phonebook_1(char *host)
{
CLIENT *clnt;
int *result_1;
int input;
phonebookEntry add_1_arg;
str_number *result_2;
str_name search_1_arg;
#ifndef DEBUG
clnt = clnt_create (host, Phonebook, ONE, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
do
{
printf("1 add entry\n");
printf("2 search entry\n");
printf("0 exit\n");
scanf("%d",&input);
switch(input)
{
case 1: {
printf("Add Entry\n");
printf("Please enter name: ");
scanf("%s",&add_1_arg.name);
printf("Please enter number: ");
scanf("%s",&add_1_arg.number);
result_1 = add_1(&add_1_arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
break;
}
case 2: {
printf("Search Entry\n");
printf("Enter name to search: ");
scanf("%s",&search_1_arg.name);
result_2 = search_1(&search_1_arg, clnt);
printf("Found: %s\n", result_2->number);
if (result_2 == (str_number *) NULL) {
clnt_perror (clnt, "call failed");
}
break;
}
default: break;
}
} while (input != 0);
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf ("usage: %s server_host\n", argv[0]);
exit (1);
}
host = argv[1];
phonebook_1 (host);
exit (0);
}
|