Hello, I was playing around with RPC and wrote a small program to test function of RPC. What i was trying to do was is to send some paramter from the client to the remote procedure. But when i do that i get the expected output. But the server terminated with the dump. Here is the code which i am using. I am sure that it is something to do with the pointer but i cant point it out where.
Server code
Code:
#include <stdio.h>
#include <string.h>
#include <rpc/rpc.h>
#include "print.h"
char dummyMessage[50];
bool_t xdr_dir(XDR *xdrs, char *objp)
{ return ( xdr_string(xdrs, &objp, 50) ); }
PrintChar(char *test)
{
strcpy(dummyMessage,"This is a test");
return (int)dummyMessage;
}
int main()
{
registerrpc(PRINTNO, PRINTVER, PRINTNUM, PrintChar, xdr_dir, xdr_dir);
svc_run();
return 0;
}
client code
Code:
enum clnt_stat clnt_stat;
char print[50] = "This is a test from client";
clnt_stat = callrpc ( "12PHLS", PRINTNO, PRINTVER, PRINTNUM, xdr_dir, print, xdr_dir, print);
printf("%s", print);
And this is the output which i get from the server
Code:
*** glibc detected *** ./server: free(): invalid pointer: 0xbfd998e4 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7e2b7cd]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7e2ee30]
/lib/tls/i686/cmov/libc.so.6(xdr_string+0xba)[0xb7ebcefa]
./server[0x8048444]
/lib/tls/i686/cmov/libc.so.6[0xb7ebbca2]
/lib/tls/i686/cmov/libc.so.6[0xb7ebb4d5]
/lib/tls/i686/cmov/libc.so.6(svc_getreq_common+0x292)[0xb7ebaaa2]
/lib/tls/i686/cmov/libc.so.6(svc_getreq_poll+0x85)[0xb7eba605]
/lib/tls/i686/cmov/libc.so.6(svc_run+0xa7)[0xb7ebb077]
./server[0x80484d7]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xdc)[0xb7dd9ebc]
./server[0x80483a1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:02 2649556 /home/ssharish/FinalYear/DistributedSystms/Tutorial5/RPCW/server
08049000-0804a000 rwxp 00000000 08:02 2649556 /home/ssharish/FinalYear/DistributedSystms/Tutorial5/RPCW/server
0804a000-0806b000 rwxp 0804a000 00:00 0 [heap]
b7c00000-b7c21000 rwxp b7c00000 00:00 0
b7c21000-b7d00000 ---p b7c21000 00:00 0
b7dc3000-b7dc4000 rwxp b7dc3000 00:00 0
b7dc4000-b7eff000 r-xp 00000000 08:01 5342 /lib/tls/i686/cmov/libc-2.5.so
b7eff000-b7f00000 r-xp 0013b000 08:01 5342 /lib/tls/i686/cmov/libc-2.5.so
b7f00000-b7f02000 rwxp 0013c000 08:01 5342 /lib/tls/i686/cmov/libc-2.5.so
b7f02000-b7f05000 rwxp b7f02000 00:00 0
b7f09000-b7f14000 r-xp 00000000 08:01 2109 /lib/libgcc_s.so.1
b7f14000-b7f15000 rwxp 0000a000 08:01 2109 /lib/libgcc_s.so.1
b7f15000-b7f18000 rwxp b7f15000 00:00 0
b7f18000-b7f31000 r-xp 00000000 08:01 2068 /lib/ld-2.5.so
b7f31000-b7f33000 rwxp 00019000 08:01 2068 /lib/ld-2.5.so
bfd89000-bfd9f000 rw-p bfd89000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Enters the functionAborted (core dumped)
Can any one please explain why is this. Or how do i send paramter to the remote procedure.
Thank you
ssharish