REMOTE PROCEDURE CALL
ADD.X
struct add_arg
{
int first;
int second;
};
program ADDPROG {
version ADDVER {
int add(add_arg)=1;
}=1;
}=0x20000199;
ADDCLIENT21.C
#include “ stdio.h “
#include “ ctype.h “
#include “ rpc/rpc.h “
#include "add.h"
add_arg arg;
main(argc,argv)
int argc;
char *argv[];
{
CLIENT *clnt;
int *result;
if(argc!=4)
{
printf("USAGE= %s HOST NUM1 NUM2 \n",argv[0]);
exit(1);
}
clnt=clnt_create(argv[1],ADDPROG,ADDVER,"udp");
if(clnt==NULL)
{
clnt_pcreateerror(argv[1]);
exit(1);
}
arg.first=atoi(argv[2]);
arg.second=atoi(argv[3]);
result=add_1(&arg,clnt);
if(result==(int *)NULL)
{
clnt_perror(clnt,"call failed");
exit(1);
}
else
{
printf("SUCCESS: %d + %d = %d\n",arg.first,arg.second,*result);
}
exit(0);
}
ADDSERVER21.C
#include "add.h"
int *add_1_svc(argp,rqstp)
add_arg *argp;
struct svc_req *rqstp;
{
static int result;
result=argp- > first+argp- > second;
return(&result);
}
OUTPUT
[NPLab@localhost rpc]$ ls
addclient21.c addserver21.c add.x
[NPLab@localhost rpc]$ rpcgen add.x
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h addserver21.c add_svc.c add.x add_xdr.c
[NPLab@localhost rpc]$ cc -c addclient21.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c addserver21.c add.x
addclient21.o add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -c add_clnt.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
addclient21.o add_clnt.o addserver21.c add.x
[NPLab@localhost rpc]$ cc -c add_xdr.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
addclient21.o add_clnt.o addserver21.c add.x add_xdr.o
[NPLab@localhost rpc]$ cc -o addc21 addclient21.o add_clnt.o add_xdr.c
[NPLab@localhost rpc]$ ls
addc21 addclient21.o add_clnt.o addserver21.c add.x add_xdr.o addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -c addserver21.c
[NPLab@localhost rpc]$ ls
addc21 addclient21.o add_clnt.o addserver21.c add_svc.c add_xdr.c addclient21.c add_clnt.c add.h add.x addserver21.o add_xdr.o
[NPLab@localhost rpc]$ cc -c add_svc.c
[NPLab@localhost rpc]$ ls
addc21 add_clnt.c addserver21.c add_svc.o add_xdr.o
addclient21.c add_clnt.o addserver21.o add.x addclient21.o add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -o adds21 addserver21.o add_svc.o add_xdr.c
[NPLab@localhost rpc]$ ls
addc21 add_clnt.c adds21 add_svc.c add_xdr.c
addclient21.c add_clnt.o addserver21.c add_svc.o add_xdr.o addclient21.o add.h addserver21.o add.x
SERVER:
[NPLab@localhost ~]$ ./adds21
CLIENT:
[NPLab@localhost ~]$ ./addc21 localhost 3 7
SUCCESS: 3 + 7 = 10