Unix Programming - RPC Blues (arrrghh) H-E-L-P

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2005 > RPC Blues (arrrghh) H-E-L-P





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author RPC Blues (arrrghh) H-E-L-P
50295@web.de

2005-03-17, 5:55 pm

I'm trying to compile the RPC example on this webpage:
http://www.cs.wpi.edu/~cs4513/b01/w...ek4-sunrpc.html

--------------------------------------------------------------
Client:
/*
* rdate.c client program for remote date program
*/

#include <stdio.h>
#include <rpc/rpc.h> /* standard RPC include file */
#include "date.h" /* this file is generated by rpcgen */

main(int argc, char *argv[])
{
CLIENT *cl; /* RPC handle */
char *server;
long *lresult; /* return value from bin_date_1() */
char **sresult; /* return value from str_date_1() */

if (argc != 2) {
fprintf(stderr, "usage: %s hostname\n", argv[0]);
exit(1);
}

server = argv[1];

/*
* Create client handle
*/

if ((cl = clnt_create(server, DATE_PROG, DATE_VERS, "udp")) ==
NULL) {
/*
* can't establish connection with server
*/
clnt_pcreateerror(server);
exit(2);
}

/*
* First call the remote procedure "bin_date".
*/

if ( (lresult = bin_date_1(NULL, cl)) == NULL) {
clnt_perror(cl, server);
exit(3);
}
printf("time on host %s = %ld\n",server, *lresult);

/*
* Now call the remote procedure str_date
*/

if ( (sresult = str_date_1(lresult, cl)) == NULL) {
clnt_perror(cl, server);
exit(4);
}
printf("time on host %s = %s", server, *sresult);

clnt_destroy(cl); /* done with the handle */
exit(0);
}

--------------------------------------------------------------
Remote procedures:

/*
* dateproc.c remote procedures; called by server stub
*/

#include <rpc/rpc.h> /* standard RPC include file */
#include "date.h" /* this file is generated by rpcgen */

/*
* Return the binary date and time
*/

long *bin_date_1()
{
static long timeval; /* must be static */

timeval = time((long *) 0);
return &timeval;
}

/*
* Convert a binary time and return a human readable string
*/

char **str_date_1(long *bintime)
{
static char *ptr; /* must be static */
ptr = ctime(bintime); /* convert to local time */
return &ptr;
}
--------------------------------------------------------------
/*
* date.x Specification of the remote date and time server
*/

/*
* Define two procedures
* bin_date_1() returns the binary date and time (no arguments)
* str_date_1() takes a binary time and returns a string
*
*/

program DATE_PROG {
version DATE_VERS {
long BIN_DATE(void) = 1; /* procedure number = 1 */
string STR_DATE(long) = 2; /* procedure number = 2 */
} = 1; /* version number = 1 */
} = 0x31234567; /* program number = 0x31234567 */

--------------------------------------------------------------

and all is well till I try:
cc -o dateproc dateproc.c date_svc.c

the result:
dateproc.c: In function `bin_date_1':
dateproc.c:13: number of arguments doesn't match prototype
date.h:22: prototype declaration
dateproc.c: At top level:
dateproc.c:25: conflicting types for `str_date_1'
date.h:25: previous declaration of `str_date_1'
dateproc.c: In function `str_date_1':
dateproc.c:27: warning: assignment makes pointer from integer without a
cast

What's going wrong???????

Thanks,

- Olumide

50295@web.de

2005-03-17, 5:55 pm

I'm having problems compling this example too:

http://www.linuxjournal.com/article/2204

Source for avg.x ::
http://www.linuxjournal.com/article...204/2204l1.html
Header File avg.h ::
http://www.linuxjournal.com/article...204/2204l2.html
Server Code for Average Application ::
http://www.linuxjournal.com/article...204/2204l3.html
Client Code for Average Application ::
http://www.linuxjournal.com/article...204/2204l4.html
Makefile ::
http://www.linuxjournal.com/article...204/2204l5.html

What am I doing wrong?

I'm getting the following message:
-bash-2.05b$ make
cc -g ravg.c -c
ravg.c:25:2: warning: no newline at end of file
cc -o ravg ravg.o avg_clnt.o avg_xdr.o
avg_clnt.o(.text+0x0): In function `average_1':
: multiple definition of `average_1'
ravg.o(.text+0x0):/cgstaff/oaina/practice/rpc/test2/ravg.c:8: first
defined here
/usr/bin/ld: Warning: size of symbol `average_1' changed from 124 in
ravg.o to 99 in avg_clnt
..o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18):
In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [ravg] Error 1

By the way, I'm not quite sure if the server is avg_proc.c and the
client racg.c or the other way round

Thanks

- Olumide

50295@web.de

2005-03-17, 8:48 pm

Eureka! I solved it.

For posteriry's sake I'm answering my own questions.

First to compile the remote procedure interface/specification file
foo.x (with rpcgen), in order to get a:

(1) client stub source file (foo_clnt.c),
(2) server stub source file (foo_svc.c),
(3) machine-independent eXternal Data Representation filter (foo_xdr.c)
if necessary (depends on if you've defined a struct in foo.x), and ...
(4) a header file (foo.h) - to be used by the client and server source
files and stubs

The key however is to make sure that you implement the necessary
interfaces defined specifed in foo.h.

Accordingly, the remote procedure file dateproc.c shold look like::

#include <stdio.h>
#include <time.h>

#include <rpc/rpc.h>
#include "date.h"

long bin_date(void)
{
return (long) time(NULL);
}

char *str_date(long t)
{
return ctime((time_t *) &t);
}



long *bin_date_1(void *p, CLIENT *cl)
{
static long t;

t = bin_date();
return &t;
}

long * bin_date_1_svc(void *p, struct svc_req *cl){
CLIENT *client;
return(bin_date_1(NULL, client));
}


char **str_date_1(long *p, CLIENT *cl)
{
static char *s;

s = str_date(t);
return &s;
}


char **str_date_1_svc(long *p, struct svc_req *cl){
CLIENT *client;
return(str_date_1(NULL, client));
}

- Olumide

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com