🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #31

SUN RPC vers problem(long)

#31
From: Pragnesh Sampat
Date: Fri, 30 Oct 1992 17:38
188 lines
6233 bytes
Hello

	I am trying to run a simple server to test out how to run two
versions of a program. The two machines are : a CDC risc machine running
EP/IX ( sysv and bsd43 ) and a NeXT machine ( mach kernel and bsd ). The
RPC lib is version 4.0 I believe. Here's the problem : The second version
works fine but the call to the first version results in the second version
being executed. I would like to do this with callrpc() and registerrpc()
and not low level ( switch on rq_vers ). Here's the code


			     ***FILE add.h***


#define ADDPROG		((u_long)0x20000100) /* prog number */
#define ADDVERS1  	((u_long)1) /* for vers one */
#define ADDVERS2 	((u_long)2) /* for vers two */
#define ADDPROC      	((u_long)1) /* proc number */
extern int *add_1();		/* proc for vers one */
extern int *add_2();		/* proc for vers two */

struct argtype {		/* args struct for passing */
     int low;
     int high;
     int step;
} ;			

typedef struct argtype argtype;	
				/* declare the xdr routine which will be */
				/* called for args encoding/decoding. See */
				/* add_xdr.c for more comments */
extern bool_t xdr_sumargs(XDR *xdr_handlep, argtype *);


			   ***FILE add_xdr.c***


#include <stdio.h>
#include <rpc/rpc.h>		/* includes other rpc related files like */
				/* types.h and xdr.h */
#include "add.h"
				/* bool_t is TRUE or FALSE and defined as */
				/* int in rpc/types.h */
				/* XDR is the XDR handle defined in rpc/ */
				/* xdr.h. It contains field for operations */
				/* i. e. encode/decode */

bool_t xdr_sumargs(XDR *xdr_handlep, argtype *objp)
{
				/* xdr_int is a builtin filter from which */
				/* we are constructing a custom filter. Some */
				/* of the other builtin filters are xdr_char */
				/* xdr_short, xdr_reference and many others.*/

     return ((xdr_int(xdr_handlep, &objp->low)) &&
	     (xdr_int(xdr_handlep, &objp->high)) &&
	     (xdr_int(xdr_handlep, &objp->step)));

}

			  ***FILE add_clnt.c***


#include <stdio.h>	
#include <rpc/rpc.h>		/* std rpc include file */
#include "add.h"		/* common header file for client and server */

#define STEPSIZE	1

main(int argc, char *argv[])
{

     enum versions {one, two};
     enum versions vers=two;	/* default version */
     int defaultstep=STEPSIZE;
     int status, result1, result2; /* results for vers one and two */
     int localarg;		/* arg for vers one */
     argtype sumargs;		/* argument to be passed for vers two */
				/* defined in the header add.h */

     if (argc == 3) 
	  vers = one;		/* do args processing */
     else {
	  if ((argc != 4) && (argc !=5)) {
	       printf("usage: add_clnt server low high [step] for vers 2\n");
	       printf("       add_clnt server number for vers 1\n");
	       exit(1);
	  }
	  if (argc == 5)
	       defaultstep = atoi(argv[4]);
     }
     if (vers == one) {		/* want vers one */
	  localarg = atoi(argv[2]);
	  status = callrpc(argv[1], ADDPROG, ADDVERS1, ADDPROC , xdr_int,
			   (int *)&localarg, xdr_int, (int *)&result1);
	  if (status == 0) 
	       printf("result is %d\n", result1);
	  else {
	       fprintf(stderr, "Error: callrpc(); %s\n", clnt_sperrno((enum
		       clnt_stat)status));
	       exit(2);
	  }
     }
     else {			/* want vers two */
	  sumargs.low  = atoi(argv[2]);	/* fill in the struct to be sent */
	  sumargs.high = atoi(argv[3]);
	  sumargs.step = defaultstep; 
	  status = callrpc(argv[1], ADDPROG, ADDVERS2, ADDPROC , xdr_sumargs,
			   (argtype *)&sumargs, xdr_int, (int *)&result2);
	  if (status == 0) 
	       printf("result is %d\n", result2);
	  else {
	       fprintf(stderr, "Error: callrpc(); %s\n", clnt_sperrno((enum
		       clnt_stat)status));
	       exit(2);
	  }

     }
     return(0);
}


			   ***FILE add_svc.c***


#include <stdio.h>
#include <rpc/rpc.h>		/* std rpc header file */
#include "add.h"		/* common file to both server and client */

main()
{
     int *add_1(int *);		/* proc for vers one */
     int *add_2(argtype *);	/* proc for vers two */

				/* register vers one */
     if (registerrpc(ADDPROG, ADDVERS1, ADDPROC , add_1, xdr_int, xdr_int)
	 == -1) {
	  fprintf(stderr, "Error : cannot register vers 1\n");
	  exit(1); 
     }
				/* register vers two */
     if (registerrpc(ADDPROG, ADDVERS2, ADDPROC , add_2, xdr_sumargs, xdr_int)
	 == -1) {
	  fprintf(stderr, "Error : cannot register vers 2\n");
	  exit(2); 
     }
     svc_run();
}

int *add_1(int *number)
{
     static int result;		/* must be static */

     result = *number + 1;
     return (&result);
}

int *add_2(argtype *sumptr)
{
     int	i;
     static int	loopsum;	/* must be static */

     loopsum = 0;
     fprintf(stderr, "this is vers two\n");
     for(i = sumptr->low; i <= sumptr->high; i = i + sumptr->step) {
	  loopsum = loopsum + i;
     }
     return (&loopsum); 

}


If I comment out the registration of the second version in the file
add_svc.c the first version is executed. Have used dbx on the client side
to trace through. seems ok. The other possibility considered was that
automatically the highest version is supported in high level and I may
have to use low level. ( BTW this is for a tutorial on using SUN RPC and
any other comment/suggestion would be welcome )

	usage : add_svc & ( on the server )
		and
		add_clnt server 1 10  --> for vers two ( e. g )
		add_clnt server 1     --> for vers one ( e. g )
			  ( on the client )

Any comment is appreciated. Thanks

Pragnesh Sampat		psampat@picasso.ocis.temple.edu		(215)787-6388
Technical Details
Message-ID: <1992Oct30.173840.7650@cronkite.ocis.temple.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!uvaarpa!darwin.sura.net!wupost!cs.utexas.edu!usc!hela.iti.org!cs.widener.edu!dsinc!netnews.upenn.edu!cronkite.ocis.temple.edu!picasso.ocis.temple.edu!psampat

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!uvaarpa!darwin.sura.net!wupost!cs.utexas.edu!usc!hela.iti.org!cs.widener.edu!dsinc!netnews.upenn.edu!cronkite.ocis.temple.edu!picasso.ocis.temple.edu!psampat
From: psampat@picasso.ocis.temple.edu (Pragnesh Sampat)
Newsgroups: comp.unix.programmer
Subject: SUN RPC vers problem(long)
Keywords: RPC, UNIX
Message-ID: <1992Oct30.173840.7650@cronkite.ocis.temple.edu>
Date: 30 Oct 92 17:38:40 GMT
Sender: news@cronkite.ocis.temple.edu (NetWork News (readnews))
Organization: Temple University
Lines: 188
X-Newsreader: Tin 1.1 PL5