1 /*
2 * Copyright (c) Bull S.A. 2007 All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * History:
24 * Created by: Cyril Lacabanne (Cyril.Lacabanne@bull.net)
25 *
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <time.h>
32 #include <rpc/rpc.h>
33
34 //Standard define
35 #define VERSNUM 1
36 #define PROCSIMPLEPING 1
37 #define SVCGETCALLTEST 2
38
39 void rcp_service(register struct svc_req *rqstp, register SVCXPRT * transp);
40 char *simplePing(int inVar, SVCXPRT * transp);
41
42 static int argument;
43
44 //****************************************//
45 //*** Main Function ***//
46 //****************************************//
main(int argn,char * argc[])47 int main(int argn, char *argc[])
48 {
49 //Program parameters : argc[1] : HostName or Host IP
50 // argc[2] : Server Program Number
51 // other arguments depend on test case
52
53 //run_mode can switch into stand alone program or program launch by shell script
54 //1 : stand alone, debug mode, more screen information
55 //0 : launch by shell script as test case, only one printf -> result status
56 int run_mode = 0;
57 int progNum = atoi(argc[1]);
58 SVCXPRT *transpUDP = NULL;
59
60 //Initialization
61 pmap_unset(progNum, VERSNUM);
62
63 //registerrpc(progNum, VERSNUM, PROCSIMPLEPING,
64 // simplePing, xdr_int, xdr_int);
65 transpUDP = svcudp_create(RPC_ANYSOCK);
66
67 if (run_mode) {
68 printf("SVC TCP : %p\n", transpUDP);
69 }
70
71 if (!svc_register
72 (transpUDP, progNum, VERSNUM, (void *)rcp_service, IPPROTO_UDP)) {
73 fprintf(stderr, "svc_register: error (TCP)\n");
74 }
75
76 svc_run();
77 fprintf(stderr, "Error: svc_run returned!\n");
78 //Test has failed if we are here
79 printf("1\n");
80
81 return 1;
82 }
83
84 //****************************************//
85 //*** Remotes Procedures ***//
86 //****************************************//
simplePing(int inVar,SVCXPRT * transp)87 char *simplePing(int inVar, SVCXPRT * transp)
88 {
89 static int result;
90 result = inVar;
91 return (char *)&result;
92 }
93
94 //****************************************//
95 //*** Dispatch Function ***//
96 //****************************************//
rcp_service(register struct svc_req * rqstp,register SVCXPRT * transp)97 void rcp_service(register struct svc_req *rqstp, register SVCXPRT * transp)
98 {
99 char *result;
100 xdrproc_t xdr_argument;
101 xdrproc_t xdr_result;
102 char *(*proc) (int, SVCXPRT *);
103 int test_status = 1;
104
105 switch (rqstp->rq_proc) {
106 case PROCSIMPLEPING:
107 {
108 //printf("** in PROCPONG dispatch Func.\n");
109 xdr_argument = (xdrproc_t) xdr_int;
110 xdr_result = (xdrproc_t) xdr_int;
111 proc = (char *(*)(int, SVCXPRT *))simplePing;
112 break;
113 }
114 }
115
116 memset((char *)&argument, (int)0, sizeof(argument));
117 if (svc_getargs(transp, xdr_argument, (char *)&argument) == FALSE) {
118
119 }
120
121 result = (char *)(*proc) (argument, transp);
122
123 if ((result != NULL)
124 && (svc_sendreply(transp, xdr_result, result) == FALSE)) {
125 //Test has failed
126 test_status = 1;
127 } else {
128 //Test succeeds
129 test_status = 0;
130 }
131 if (svc_freeargs(transp, xdr_argument, (char *)&argument) == FALSE) {
132
133 }
134 //This last printf gives the result status to the tests suite
135 //normally should be 0: test has passed or 1: test has failed
136 printf("%d\n", test_status);
137
138 }
139