Está en la página 1de 5

suma.

x
struct peticion { int a; int b; };
program SUMAR { version SUMAVER { int SUMA(peticion) = 1; } = 1; } = 99; La compilacion es : # rpcgen a suma.x

Archivos que se generan


Makefile.suma Suma.h Suma_client.c Suma_client.o Suma_clnt.c Suma_clnt.o Suma_server.o Suma_server.c Suma_svc.c Suma_svc.o Suma_xdr.c Suma_xdr.o

ARREGLAMOS EL CODIGO # vi suma_client.c

# vi suma_server.c
Y compilamos con:

# make -f Makefile.suma

Suma_client.c
#include "suma.h" void sumar_1(char *host) { CLIENT *clnt; int *result_1, a, b; peticion suma_1_arg; #ifndef DEBUG clnt = clnt_create (host, SUMAR, SUMAVER, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ printf("Digite el valor de a = "); scanf("%d", &a); printf("\n"); printf("Digite el valor de b = "); scanf("%d", &b); suma_1_arg.a = a; suma_1_arg.b = b; result_1 = suma_1(&suma_1_arg, clnt); printf("la suma de %d + %d es = %d\n",a , b, *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]; sumar_1 (host); exit (0); }

Suma.h - generado
#ifndef _SUMA_H_RPCGEN #define _SUMA_H_RPCGEN #include <rpc/rpc.h> #else /* K&R C */ #define SUMA 1 extern int * suma_1(); extern int * suma_1_svc(); extern int sumar_1_freeresult (); #endif /* K&R C */ /* the xdr functions */ #if defined(__STDC__) || defined(__cplusplus) extern bool_t xdr_peticion (XDR *, peticion*); #else /* K&R C */ extern bool_t xdr_peticion (); #ifdef __cplusplus extern "C" { #endif

struct peticion { int a; int b; }; typedef struct peticion peticion; #define SUMAR 99 #define SUMAVER 1 #if defined(__STDC__) || defined(__cplusplus) #define SUMA 1 extern int * suma_1(peticion *, CLIENT *); extern int * suma_1_svc(peticion *, struct svc_req *); extern int sumar_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);

#endif /* K&R C */
#ifdef __cplusplus } #endif #endif /* !_SUMA_H_RPCGEN */

Suma_server.c
#include "suma.h" int * suma_1_svc(peticion *argp, struct svc_req *rqstp) { static int result;

/* * insert server code here */ result = argp->a + argp->b; printf("Me han llamado y he contestado ...\n"); return &result; }

También podría gustarte