RPC

This is a discussion on RPC within the Networking/Device Communication forums, part of the General Programming Boards category; Hello, I was playing around with RPC and wrote a small program to test function of RPC. What i was ...

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

    RPC

    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("&#37;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

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Any help

    ssharish

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    I would first try to get a working example going with a simple "int foo(void)" RPC call. I suspect there is something not right with the processing of the "char*" return type and parameter type - according to your "xdr_dir" filter - even though PrintChar() returns an int.

    gg

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by Codeplug View Post
    I would first try to get a working example going with a simple "int foo(void)" RPC call. I suspect there is something not right with the processing of the "char*" return type and parameter type - according to your "xdr_dir" filter - even though PrintChar() returns an int.

    gg
    Thanks a lot CodePlug, i did that before i dint this example. Cos i wasn't sure about RPC working. And Indeed it worked if I dont send any parameter to the function. This is how it looks like

    My 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()
    {
         strcpy(dummyMessage,"This is a test\n");
         
         return (int)dummyMessage;
    }
    int main()
    {
        registerrpc(PRINTNO, PRINTVER, PRINTNUM, PrintChar, xdr_void, xdr_dir);
        
        svc_run();
        return 0;
    }
    client code
    Code:
    #include <stdio.h>
    #include <rpc/rpc.h>
    #include "print.h"
    
    bool_t xdr_dir(XDR *xdrs, char *objp)
    { return ( xdr_string(xdrs, &objp, 50) ); }
    
    int main()
    {
        enum clnt_stat clnt_stat;
        char print[50];
        
        clnt_stat = callrpc ( "12PHLS", PRINTNO, PRINTVER, PRINTNUM, xdr_void, (char *)0, xdr_dir, print);
        
        printf("&#37;s", print);
        
        if (clnt_stat != 0) 
           clnt_perrno (clnt_stat);
        
        return 0;
    }
    And Indeed it works as expected. The problems comes when I start sending parameters.

    ssharish

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    In all the online examples, I didn't see any custom xdr filters that passed the address of a parameter off the stack. In this case, xdr_dir() is passing along the address of the stack parameter "objp".

    One other clue that suggests that might not be correct is the built-in "xdr_wrapstring()" filter. This simply calls xdr_string() for you - as your xdr_dir() does - but it uses a parameter of "char**".

    Try using xdr_wrapstring() alone - or see if using "char **objp" makes any difference.

    My other thought was that perhaps callrpc() should be called with "&print" instead of just "print" - but if the no parameter example is working as expected then perhaps not.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RPC concurrent server in C...???
    By mr_m4x in forum C Programming
    Replies: 1
    Last Post: 03-29-2009, 12:10 AM
  2. RPC and IOCP tutorial?
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 07-17-2008, 08:39 PM
  3. RPC probe explosion.
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 08-13-2003, 10:08 PM
  4. IPC vs RPC
    By hermit in forum Tech Board
    Replies: 7
    Last Post: 09-09-2002, 10:58 AM
  5. Rpc
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 11-10-2001, 07:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21