Prototype Declaration Error in RPC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Siddarth777
    New Member
    • Sep 2010
    • 28

    Prototype Declaration Error in RPC

    Hi,
    I am writing a sample RPC program in C language using RPCGEN tool in my UBUNTU 12.04, when i have finished writing my client and server codes, and when i compile the complete project using a makefile i get error in my server code

    i encounter the following errors

    gcc -c -o svc_proc.o -g -Wall svc_proc.c
    svc_proc.c: In function ‘greetings_1_sv c’:
    svc_proc.c:4:1: error: number of arguments doesn’t match prototype
    helloworld.h:23 :15: error: prototype declaration
    svc_proc.c:8:2: warning: function returns address of local variable [enabled by default]
    make: *** [svc_proc.o] Error 1


    The codes of my server and helloworld.h files are

    helloworld.h
    Code:
    /*
     * Please do not edit this file.
     * It was generated using rpcgen.
     */
    
    #ifndef _HELLOWORLD_H_RPCGEN
    #define _HELLOWORLD_H_RPCGEN
    
    #include <rpc/rpc.h>
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    
    #define HELLOWORLD 0x2fffffff
    #define HELLOWORLD_V1 1
    
    #if defined(__STDC__) || defined(__cplusplus)
    #define greetings 1
    extern  int * greetings_1(void *, CLIENT *);
    extern  int * greetings_1_svc(void *, struct svc_req *);
    extern int helloworld_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
    
    #else /* K&R C */
    #define greetings 1
    extern  int * greetings_1();
    extern  int * greetings_1_svc();
    extern int helloworld_1_freeresult ();
    #endif /* K&R C */
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif /* !_HELLOWORLD_H_RPCGEN */
    svc_proc.c

    Code:
    #include"helloworld.h"
    
    // This is the SERVER Code
    
    int* greetings_1_svc()
    {
    	int i=0;
    	printf("This is your OWN RPC");
    	return &i;
    }
    please tell me where i am going wrong, thanks a lot in advance


    Siddarth
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You have declred your function in helloworld.h as:

    Code:
    extern  int * greetings_1_svc(void *, struct svc_req *);
    The actual code is:

    Code:
    int* greetings_1_svc()
    etc...

    The function and the prototype have to match. Clearly they do not.

    BTW: greetings_1_svc is returning the addres of an int that is a local variable. Be aware that by the time you use the address that is returned, the variable will have been destroyed and your program will crash.

    Comment

    Working...