Src
|
|
1 /*
2 * Module: arguments.x
3 * msg.x: Remote message printing
4 */
5
6 #ifndef BUF
7 # define BUF 256
8 #endif
9
10 typedef char StringT<BUF>; /* string */
11 struct Date { /* hh:mm:ss */
12 int sec;
13 int h;
14 int m;
15 };
16
17 typedef Date DateT; /* structure */
18
19 program ARGS {
20 version PRINT_VERS_1 {
21 int PRINTMESSAGE(StringT) = 1;
22 DateT GETDATE() = 2;
23 } = 1; /* version 1 */
24
25 version PRINT_VERS_2 {
26 int PRINTMESSAGE(StringT) = 1;
27 DateT GETDATE() = 2;
28 StringT GETHOST() = 3;
29 } = 2; /* version 2 */
30 } = 0x2000000;
% ls print.x % rpcgen -a print.x % ls makefile.print print.x print_clnt.c print_svc.c print.h print_client.c print_server.c print_xdr.c % mv makefile.print makefile
... 24 CFLAGS += -g 25 CFLAGS += -g -DRPC_SVC_FG # -Wall --> many Warnings ...
...
13 void
14 args_1(host)
15 char *host;
16 {
...
33 result_1 = printmessage_1(&printmessage_1_arg, clnt);
34 if (result_1 == (int *) NULL) {
35 clnt_perror(clnt, "call failed");
36 }
37 result_2 = getdate_1((void *)&getdate_1_arg, clnt);
38 if (result_2 == (DateT *) NULL) {
39 clnt_perror(clnt, "call failed");
40 }
...
49 void
50 args_2(host)
51 char *host;
52 {
53 int *result_1;
54 StringT printmessage_2_arg;
55 DateT *result_2;
56 char * getdate_2_arg;
57 StringT *result_3;
58 char * gethost_2_arg;
59 char * my_message = "HELP";
...
72 printf("client: call printmessage_2(%s)\n", my_message);
73 printmessage_2_arg.StringT_val = my_message;
74 printmessage_2_arg.StringT_len = strlen(my_message);
75 result_1 = printmessage_2(&printmessage_2_arg, clnt);
76 if (result_1 == (int *) NULL) {
77 clnt_perror(clnt, "call failed");
78 } else {
79 printf("client: call printmessage_2(%s) done.\n",
80 my_message);
81 printf("client: result = %d.\n\n", *result_1);
82 }
83
84 printf("client: call getdate_2()\n");
85 result_2 = getdate_2((void *)&getdate_2_arg, clnt);
86 if (result_2 == (DateT *) NULL) {
87 clnt_perror(clnt, "call failed");
88 } else {
89 printf("client: call getdate_2() done.\n");
90 printf("client: hh = %d\n", result_2->h);
91 printf("client: mm = %d\n", result_2->m);
92 printf("client: ss = %d\n\n", result_2->sec);
93 }
94
95
96
97
98 printf("client: call get_host_2(%s)\n", my_message);
99 result_3 = gethost_2((void *)&gethost_2_arg, clnt);
100 if (result_3 == (StringT *) NULL) {
101 clnt_perror(clnt, "call failed");
102 } else {
103 printf("client: call gethost_2() done.\n");
104 printf("client: result_3 = -%s-\n",
105 result_3->StringT_val);
106 }
...
115 main(argc, argv)
116 int argc;
117 char *argv[];
118 {
119 char *host;
120
121 if (argc < 2) {
122 printf("usage: %s server_host\n", argv[0]);
123 exit(1);
124 }
125 host = argv[1];
126 /* args_1(host); */
127 args_2(host);
128 }
...
1 /*
2 * This is sample code generated by rpcgen.
3 * These are only templates and you can use them
4 * as a guideline for developing your own functions.
5 */
6
7 #include "print.h"
8 #include <stdio.h>
9 #include <stdlib.h> /* getenv, exit */
10 #include <signal.h>
11 #include <sys/types.h> // added
12 #include <time.h> // added
13
14
15 int *
16 printmessage_1(argp, rqstp)
17 StringT *argp;
18 struct svc_req *rqstp;
19 {
20 static int result;
21
22 printf("server: printmessage_1(%d)\n",
23 argp->StringT_len);
24 printf("server: printmessage_1(%s)\n",
25 argp->StringT_val);
26 result = 11;
27
28 return (&result);
29 }
30
31 DateT *
32 getdate_1(argp, rqstp)
33 void *argp;
34 struct svc_req *rqstp;
35 {
36 static DateT result;
37 printf("server: getdate_1\n");
38 return (&result);
39 }
40
41 int *
42 printmessage_2(argp, rqstp)
43 StringT *argp;
44 struct svc_req *rqstp;
45 {
46 static int result;
47
48 argp->StringT_val[argp->StringT_len] = '\0';
49 printf("server: printmessage_2(%s)\n",
50 argp->StringT_val);
51 printf("server: printmessage_2(len = %d)\n",
52 argp->StringT_len);
53
54 result = 21;
55 return (&result);
56 }
57
58 DateT *
59 getdate_2(argp, rqstp)
60 void *argp;
61 struct svc_req *rqstp;
62 { struct tm * lt;
63 time_t time_res;
64 static DateT result;
65
66 printf("server: getdate_2\n");
67 time_res = time( NULL );
68 printf("%s \n", ctime( &time_res ) );
69 lt = localtime( &time_res );
70
71 result.h = lt->tm_hour;
72 result.m = lt->tm_min;
73 result.sec = lt->tm_sec;
74 return (&result);
75 }
76
77 StringT *
78 gethost_2(argp, rqstp)
79 void *argp;
80 struct svc_req *rqstp;
81 { char name[1024];
82 static StringT result;
83 printf("server: gethost_2\n");
84
85 if ( -1 == gethostname(name, sizeof(name) ) )
86 strcpy(name, "no name available :-( ");
87
88 result.StringT_val = name;
89 result.StringT_len = strlen(name);
90
91 return (&result);
92 }
Result (server):
% print_server server: printmessage_2(HELP) server: printmessage_2(len = 4) server: getdate_2 Tue Feb 17 13:52:33 1998 server: gethost_2
Result (client):
% print_client gee client: call printmessage_2(HELP) client: call printmessage_2(HELP) done. client: result = 21. client: call getdate_2() client: call getdate_2() done. client: hh = 13 client: mm = 52 client: ss = 33 client: call get_host_2(HELP) client: call gethost_2() done. client: result_3 = -gee -
Src
|
|
Last modified: 08/May/98 (11:53)