• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <time.h>
31 #include <rpc/rpc.h>
32 
33 //Standard define
34 #define VERSNUM 1
35 #define PROCSIMPLEPING	1
36 #define SVCGETCALLTEST	2
37 
38 void rcp_service(register struct svc_req *rqstp, register SVCXPRT * transp);
39 char *simplePing(int inVar, SVCXPRT * transp);
40 
41 static int argument;
42 
43 //****************************************//
44 //***           Main Function          ***//
45 //****************************************//
main(int argn,char * argc[])46 int main(int argn, char *argc[])
47 {
48 	//Program parameters : argc[1] : HostName or Host IP
49 	//                                         argc[2] : Server Program Number
50 	//                                         other arguments depend on test case
51 
52 	//run_mode can switch into stand alone program or program launch by shell script
53 	//1 : stand alone, debug mode, more screen information
54 	//0 : launch by shell script as test case, only one printf -> result status
55 	int run_mode = 0;
56 	int progNum = atoi(argc[1]);
57 	SVCXPRT *transpUDP = NULL;
58 
59 	//Initialization
60 	pmap_unset(progNum, VERSNUM);
61 
62 	//registerrpc(progNum, VERSNUM, PROCSIMPLEPING,
63 	//                  simplePing, xdr_int, xdr_int);
64 	transpUDP = svcudp_create(RPC_ANYSOCK);
65 
66 	if (run_mode) {
67 		printf("SVC TCP : %p\n", transpUDP);
68 	}
69 
70 	if (!svc_register
71 	    (transpUDP, progNum, VERSNUM, (void *)rcp_service, IPPROTO_UDP)) {
72 		fprintf(stderr, "svc_register: error (TCP)\n");
73 	}
74 
75 	svc_run();
76 	fprintf(stderr, "Error: svc_run returned!\n");
77 	//Test has failed if we are here
78 	printf("1\n");
79 
80 	return 1;
81 }
82 
83 //****************************************//
84 //***        Remotes Procedures        ***//
85 //****************************************//
simplePing(int inVar,SVCXPRT * transp)86 char *simplePing(int inVar, SVCXPRT * transp)
87 {
88 	static int result;
89 	result = inVar;
90 	return (char *)&result;
91 }
92 
93 //****************************************//
94 //***       Dispatch Function          ***//
95 //****************************************//
rcp_service(register struct svc_req * rqstp,register SVCXPRT * transp)96 void rcp_service(register struct svc_req *rqstp, register SVCXPRT * transp)
97 {
98 	char *result;
99 	xdrproc_t xdr_argument;
100 	xdrproc_t xdr_result;
101 	char *(*proc) (int, SVCXPRT *);
102 	int test_status = 1;
103 
104 	switch (rqstp->rq_proc) {
105 	case PROCSIMPLEPING:
106 		{
107 			//printf("** in PROCPONG dispatch Func.\n");
108 			xdr_argument = (xdrproc_t) xdr_int;
109 			xdr_result = (xdrproc_t) xdr_int;
110 			proc = (char *(*)(int, SVCXPRT *))simplePing;
111 			break;
112 		}
113 	}
114 
115 	memset((char *)&argument, (int)0, sizeof(argument));
116 	if (svc_getargs(transp, xdr_argument, (char *)&argument) == FALSE) {
117 
118 	}
119 
120 	result = (char *)(*proc) (argument, transp);
121 
122 	if ((result != NULL)
123 	    && (svc_sendreply(transp, xdr_result, result) == FALSE)) {
124 		//Test has failed
125 		test_status = 1;
126 	} else {
127 		//Test succeeds
128 		test_status = 0;
129 	}
130 	if (svc_freeargs(transp, xdr_argument, (char *)&argument) == FALSE) {
131 
132 	}
133 	//This last printf gives the result status to the tests suite
134 	//normally should be 0: test has passed or 1: test has failed
135 	printf("%d\n", test_status);
136 
137 }
138