Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!elroy.jpl.nasa.gov!mahendo!wlbr!mh From: mh@iti.org (Mike Hoegeman) Newsgroups: comp.protocols.nfs Subject: Re: bug in sun-3/os4.1 rpc/xdr? Message-ID: <56999@wlbr.IMSD.CONTEL.COM> Date: 15 Aug 90 22:38:44 GMT References: <90225.174053BACON@MTUS5.BITNET> Sender: news@wlbr.IMSD.CONTEL.COM Reply-To: mh@tweedledum.imsd.contel.com.UUCP (Mike Hoegeman) Organization: Contel FSD, Westlake Village, CA Lines: 78 In article <90225.174053BACON@MTUS5.BITNET> BACON@MTUS5.BITNET (Jeffery Bacon) writes: >I submit the following problem: >Given the following declaration (taken just about right out of the Sun 4.1 >netowrk prog guide) bla.x: >------------- >program BLAPROG { version BLAVERS {int BLA(int) = 1; } = 1; } = 0x20000099; >-------------- >This should send an integer and receive an integer. >For this, I've written the following server procedure: >-------------- >int *bla_1(oog) int *oog; { int erg = 5; printf("%d\n",*oog);return(&erg); } >-------------- >(please forgive my lack of formatting, but this is pretty simple; I wrote it >on the fly) >And for the client side, a simple little program: >----------------- >#include >#include >#include "bla.h" >main() { > CLIENT *bla; > int *result, oog; > bla=clnt_create("ctsee8",BLAPROG,BLAVERS,"tcp"); > oog=44; > result=bla_1(&oog,bla); > printf("%d\n",*result); >} (poster goes on to explain that sometimes the server program returns garbage.) answer: the problem is in your server procedure >int *bla_1(oog) int *oog; { int erg = 5; printf("%d\n",*oog);return(&erg); } the statement int erg = 5; should be static int erg; erg = 5; You are returning pointer to a int which is a variable that goes out of scope by the time the service transport to returns that value. That is why you sometimes get back garbage. You are just getting 'lucky' in the cases where it seems to work. If you find making 'erg' static repugnant , you can do something like this inside of bla_1 int * bla_1(oog) int *oog; { extern SVCXPRT *MyXprt; int erg; : : svc_sendreply(MyXprt, xdr_int, &erg); /* xprt is the SVCXPRT * created at via something like svcudp_create or svctcp_create */ return ((int *)0); /* the return of a NULL pointer tells the server machinery that you have already sent the reply back yourself. */ } the above is off the top of my head , you can check the man page on svc_sendreply() to make sure it's right -mike h. -- ------------------------------------------------------------------------------- Mike Hoegeman email: mike@wlv.imsd.contel.com tel: (818)706-4145 Contel Federal Systems 31717 La Tienda Dr, Westlake Village CA. 91359