Why is `rpcb_getaddr' failing?

This is a discussion on Why is `rpcb_getaddr' failing? within the C Programming forums, part of the General Programming Boards category; Why is my linker warning me "C:/cygwin/home/eb/rap00/main.c:94: warning: passing arg 4 of `rpcb_getaddr' from incompatible pointer type"? And yes, rpcb_getaddr() ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    59

    Why is `rpcb_getaddr' failing?

    Why is my linker warning me "C:/cygwin/home/eb/rap00/main.c:94: warning: passing arg 4 of `rpcb_getaddr' from incompatible pointer type"?


    And yes, rpcb_getaddr() fails.




    Code:
    /*
     * The netbuf structure is used for transport-independent address storage.
     */
    struct netbuf {
      unsigned int maxlen;
      unsigned int len;
      void *buf;
    };
    
    
    
    
    struct netbuf svcaddr;
    
    
      struct netconfig *nconf;
      char host[255] ; /* The remote host name */
    
    
      svcaddr.len = 0;
      svcaddr.maxlen = ADDRBUFSIZE;
      svcaddr.buf = addrbuf;
    
    
      /* Get pointer to struct netconfig for tcp transport */
      nconf = getnetconfigent("tcp");
      if (nconf == (struct netconfig *) NULL) {
        printf("getnetconfigent() failed\n");
        exit(1);
      }
    
    
      /* Get the address of remote service */
      if (!rpcb_getaddr(300456, 1, nconf, &svcaddr, host)) {
        printf("rpcb_getaddr() failed\n");
        exit(1);
      }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
         rpcb_getaddr()
    	    An interface to the rpcbind service, which finds the address of
    	    the service on host that is registered with program number
    	    prognum, version versnum, and speaks the transport protocol asso-
    	    ciated with netconf.  The address found is returned in svcaddr.
    	    The svcaddr argument should be preallocated.  This routine returns
    	    TRUE if it succeeds.  A return value of FALSE means that the map-
    	    ping does not exist or that the RPC system failed to contact the
    	    remote rpcbind service.  In the latter case, the global variable
    	    rpc_createerr (see rpc_clnt_create(3)) contains the RPC status.
    That's from the man page. How about you check the global variable which tells you why it failed?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Well, it would seem that there is something wrong with how you are passing the fourth argument (&scvaddress) of 'rcbp_getaddr'. In more detail, it's probably something to do with the pointer type (struct netbuf*) being incompatible (with the function declaration).

    I can't find any documentation for rpcb_getaddress but I find it hard to believe that you need to define one of the structures that it takes yourself.

  4. #4
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    According to this I'm doing it right:Help - AIX 6.1 Information Center


    I think I'm structuring netbuf wrong.
    Should I have mentioned that this is in Cygwin? Probably huh?
    Perhaps the Cygwin struct is different from the IBM struct? I doubt it but it's all I have for now.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,541
    Are you including the proper headers like "rpc.h" from the "/usr/include/tirpc/rpc" folder?
    Note: "/usr/include/tirpc" should be the search folder; including "rpc/rpc.h" header.

    Tim S.
    Last edited by stahta01; 02-01-2012 at 12:11 PM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  6. #6
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    Yup, everything is there. I included rpc.h which includes types.h which contains:
    Code:
    struct netbuf {
      unsigned int maxlen;
      unsigned int len;
      void *buf;
    };
    Last edited by evb@studioe.com; 02-01-2012 at 12:32 PM.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    2,541
    It compilers and links for me.

    Code:
    gcc-3.exe -Wall  -g    -IC:/Apps/cygwin2/usr/include/tirpc  -c C:/Users/tsta8844/temp/net/main.c -o obj/Debug/main.o
    g++-3.exe  -o bin/Debug/net.exe obj/Debug/main.o    -ltirpc 
    Output size is 45.70 KB
    Compiled this code.
    Code:
    #include <stdio.h>
    #include "rpc/rpc.h"
    
    struct netbuf svcaddr;
    #define ADDRBUFSIZE 255 /* wild guess */
    
    int main(){
      struct netconfig *nconf;
      char host[255] ; /* The remote host name */
    
    
      svcaddr.len = 0;
      svcaddr.maxlen = ADDRBUFSIZE;
    //  svcaddr.buf = addrbuf;
    
    
      /* Get pointer to struct netconfig for tcp transport */
      nconf = getnetconfigent("tcp");
      if (nconf == (struct netconfig *) NULL) {
        printf("getnetconfigent() failed\n");
        exit(1);
      }
    
    
      /* Get the address of remote service */
      if (!rpcb_getaddr(300456, 1, nconf, &svcaddr, host)) {
        printf("rpcb_getaddr() failed\n");
        exit(1);
      }
      return 0;
    }
    Edit1: I suggest posting short but complete test code; this helps to help others help you.
    Edit2: I had to add a function and guess on variables; it would be better to post code that compilers without missing code that prevents it from showing the error you get.
    Last edited by stahta01; 02-01-2012 at 12:37 PM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  8. #8
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    fyi - my Build Log:



    -------------- Clean: Release in rap00 ---------------


    Cleaned "rap00 - Release"


    -------------- Build: Release in rap00 ---------------


    gcc-3.exe -Wall -O2 -IC:/cygwin/usr/include/tirpc -IC:/cygwin/usr/include -c C:/cygwin/home/eb/rap00/main.c -o obj/Release/main.o
    C:/cygwin/home/eb/rap00/main.c: In function `rapvar_read_name_1':
    C:/cygwin/home/eb/rap00/main.c:41: warning: function returns address of local variable
    C:/cygwin/home/eb/rap00/main.c: In function `main':
    C:/cygwin/home/eb/rap00/main.c:95: warning: passing arg 4 of `rpcb_getaddr' from incompatible pointer type
    g++-3.exe -o bin/Release/rap00.exe obj/Release/main.o C:/cygwin/lib/libtirpc.a
    Output size is 113.62 KB
    Process terminated with status 0 (0 minutes, 1 seconds)
    0 errors, 2 warnings

  9. #9
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    OH! Here's the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <memory.h> /* for memset */
    #include "rap.h"
    #include <rpc/rpc.h>
    
    
    /* Default timeout can be changed using clnt_control() */
    static struct timeval TIMEOUT = { 25, 0 };
    
    
    RAPVAR_READ_NAME_RESP_TYPE *rapvar_read_name_1(RAPVAR_READ_NAME_REQ_TYPE *argp, CLIENT *clnt)
    {
        RAPVAR_READ_NAME_REQ_TYPE *inproc = NULL;
        RAPVAR_READ_NAME_RESP_TYPE *outproc = NULL;
        RAPVAR_READ_NAME_RESP_TYPE clnt_res;
    
    
        memset((char *)&clnt_res, 0, sizeof(clnt_res));
    
    
        if (clnt_call (clnt, 1001, (xdrproc_t) inproc, (caddr_t) argp,              /*---CRASH--- */
                       (xdrproc_t) outproc, (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS)
        {
            return (NULL);
            printf("clnt_call FAILED!\n");
        }
        printf("Hello world!\n");
        return (&clnt_res);
    }
    
    
    int main()
    {
        int pstat=0;
        RAPVAR_READ_NAME_RESP_TYPE *result = NULL;
        RAPVAR_READ_NAME_REQ_TYPE request;
    
    
        CLIENT *clnt = NULL;
        clnt = clnt_create("s4c",300456,1,"tcp");
        if(clnt==NULL) printf("Client is\tNULL\n");
        if(clnt!=NULL) printf("Client is\tCREATED\n");
    
    
        CLIENT *clnt2 = NULL;
        clnt2 = clnt_create("192.168.1.2",300456,1,"tcp");
        if(clnt2==NULL) printf("Client2 is\tNULL\n");
        if(clnt2!=NULL) printf("Client is\tCREATED\n");
    
    
    #define ADDRBUFSIZE 255
    
    
      CLIENT *clnt3;
      int sock = RPC_ANYSOCK;
      unsigned int sendsz=0, recvsz=0;
      struct sockaddr_in addr;
      char addrbuf[ADDRBUFSIZE];
      struct netbuf {
      unsigned int maxlen;
      unsigned int len;
      void *buf;
    };
    
    
      struct netbuf svcaddr;
      struct netconfig *nconf;
      char host[255] ; /* The remote host name */
    
    
      svcaddr.len = 0;
      svcaddr.maxlen = ADDRBUFSIZE;
      svcaddr.buf = addrbuf;
    
    
      /* Get pointer to struct netconfig for tcp transport */
      nconf = getnetconfigent("tcp");
      if (nconf == (struct netconfig *) NULL) {
        printf("getnetconfigent() failed\n");
        exit(1);
      }
    
    
      /* Get the address of remote service */
      if (!rpcb_getaddr(300456, 1, nconf, &svcaddr, host)) {
        printf("rpcb_getaddr() failed\n");
        exit(1);
      }
      memcpy(&addr, svcaddr.buf, sizeof(struct sockaddr_in));
    
    
      clnt3 = (CLIENT *) clnttcp_create(&addr, 300456, 1, &sock, sendsz, recvsz);
    
    
      /* Destroy the client handle in the end */
      clnt_destroy(clnt3);
    
    
        char string [256];
        printf ("Hit [Enter] to exit (irony):");
        gets (string);
    
    
        request.head.userdef=1;
        request.var.name="name";
        request.var.type="robposdata";
        request.var.domain=1;
        request.var.number1=0;
        request.var.number2=26;			                    /*ROBTARGET_TRANSFER_TYPE */
    
    
        result = rapvar_read_name_1(&request, clnt);		/*Call the RPC function */
    
    
        if (result == (RAPVAR_READ_NAME_RESP_TYPE *) NULL)
        {
            printf("'result' is NULL\n");
            pstat = -1;
            return(0);
        }
        return 0;
    }

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    2,541
    I still suggest posting small but complete code that demonstrates the error you are having.

    DO NOT DEFINE structures that are supplied by headers in this case "netbuf"!!!!!!

    Tim S.
    Last edited by stahta01; 02-01-2012 at 12:46 PM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  11. #11
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    Small but complete. Gotcha.
    Last edited by evb@studioe.com; 02-01-2012 at 12:56 PM.

  12. #12
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    DANG! I don't know how I missed that duplicate struct.
    Problem solved.
    Thanks again Tim!

  13. #13
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,451
    Quote Originally Posted by evb@studioe.com View Post
    C:/cygwin/home/eb/rap00/main.c: In function `rapvar_read_name_1':
    C:/cygwin/home/eb/rap00/main.c:41: warning: function returns address of local variable
    This will likely be a major problem. The minute the function returns, that variable (clnt_res) goes out of scope, thus returning it's address results in undefined behavior. Never return the address of a local variable (including returning arrays). You can only return a pointer to memory that is valid after the function call is done, like memory you malloc, static locals, globals (ick) or variables in a "higher" scope (belonging to a function that directly or indirectly called this one) that you passed in.

  14. #14
    Registered User
    Join Date
    Jan 2012
    Posts
    59
    Thanks for the heads up. I'll make it global.

  15. #15
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,451
    Quote Originally Posted by evb@studioe.com View Post
    Thanks for the heads up. I'll make it global.
    You pick the one alternative that I put an "ick" next to. Why? Read this: Global Variables Are Bad. I would suggest passing in a pointer to an object that you can populate:
    Code:
    RAPVAR_READ_NAME_RESP_TYPE *rapvar_read_name_1(RAPVAR_READ_NAME_REQ_TYPE *argp, CLIENT *clnt, RAPVAR_READ_NAME_RESP_TYPE *clnt_res)
    {
        clnt_call (..., (caddr_t) clnt_res, TIMEOUT)  // note no & in front of clnt_res, it's already a pointer
    
        return clnt_res;  // this is safe, because the address was passed in, so it must be valid in the outer context
    }
    ...
    // in the calling context
    RAPVAR_READ_NAME_RESP_TYPE clnt_res;
    rapvar_read_name_1(argp, clnt, &clnt_res);

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp failing
    By Sn0wcra5h in forum C Programming
    Replies: 3
    Last Post: 02-25-2010, 10:10 PM
  2. ListView_InsertItem is failing!
    By Joelito in forum Windows Programming
    Replies: 5
    Last Post: 08-22-2006, 07:09 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 08:03 PM
  4. Failing constructors
    By kzar in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2005, 10:24 AM
  5. LoadBitmap failing
    By zid in forum Windows Programming
    Replies: 7
    Last Post: 10-10-2005, 09:44 AM

Tags for this Thread


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