third.x
struct average
{
int a[10];
int n;
};
program third
{
version ver
{
int ave(average)=1;
}=1;
}=0x36767676;
third_client.c
/* This is sample code generated by rpcgen. These are only templates and you can use them
as a guideline for developing your own functions.
*/
#include “third.h”
#include “third_clnt.c”
void
third_1(char *host)
{
CLIENT *clnt;
int *result_1,i;
average ave_1_arg;
printf(“Enter Value:\n”);
scanf(“%d”,&ave_1_arg.n);
for(i=0;i<ave_1_arg.n;i++)
{
printf(“Enter Value%d:\n”,i+1);
scanf(“%d”,&ave_1_arg.a[i]);
}
#ifndef DEBUG
clnt = clnt_create (host, third, ver, “udp”);
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
result_1 = ave_1(&ave_1_arg, clnt);
printf(“Average is %d\n”,*result_1);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, “call failed”);
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf (“usage: %s server_host\n”, argv[0]);
exit (1);
}
host = argv[1];
third_1 (host);
exit (0);
}
third_server.c
/* This is sample code generated by rpcgen. These are only templates and you can use them
as a guideline for developing your own functions.
*/
#include “third.h”
#include “third_svc.c”
int *
ave_1_svc(average *argp, struct svc_req *rqstp)
{
static int result;
int sum=0,i;
for (i=0;i<((*argp).n);i++)
{
sum=sum+(*argp).a[i];
}
result=sum/(*argp).n;
printf(“Average is %d\n”,result);
return &result;
}
third_xdr.c
/* Please do not edit this file. It was generated using rpcgen. */
#include “third.h”
bool_t
xdr_average (XDR *xdrs, average *objp)
{
register int32_t *buf;
int i;
if (xdrs->x_op == XDR_ENCODE) {
buf = XDR_INLINE (xdrs, (1 + 10 )* BYTES_PER_XDR_UNIT);
if (buf == NULL) {
if (!xdr_vector (xdrs, (char *)objp->a, 10,
sizeof (int), (xdrproc_t) xdr_int))
return FALSE;
if (!xdr_int (xdrs, &objp->n))
return FALSE;
} else {
{
register int *genp;
for (i = 0, genp = objp->a;
i < 10; ++i) {
IXDR_PUT_LONG(buf, *genp++);
}
}
IXDR_PUT_LONG(buf, objp->n);
}
return TRUE;
} else if (xdrs->x_op == XDR_DECODE) {
buf = XDR_INLINE (xdrs, (1 + 10 )* BYTES_PER_XDR_UNIT);
if (buf == NULL) {
if (!xdr_vector (xdrs, (char *)objp->a, 10,
sizeof (int), (xdrproc_t) xdr_int))
return FALSE;
if (!xdr_int (xdrs, &objp->n))
return FALSE;
} else {
{
register int *genp;
for (i = 0, genp = objp->a; i < 10; ++i)
{ *genp++ = IXDR_GET_LONG(buf);}
}
objp->n = IXDR_GET_LONG(buf);
}
return TRUE;
}
if (!xdr_vector (xdrs, (char *)objp->a, 10,
sizeof (int), (xdrproc_t) xdr_int))
return FALSE;
if (!xdr_int (xdrs, &objp->n))
return FALSE;
return TRUE;
}