2

I'm trying to write the simpliest client in RPC with this code:

#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>

int main(int argc, char *argv[]){
  int stat;
  char out;
    char in='f';

  if(stat=callrpc(argv[1],0x20000001, 1, 1, (xdrproc_t)xdr_void, &in, (xdrproc_t)xdr_char, &out)!=0){
      clnt_perrno(stat);
      exit(1);
  }

  exit(0);
}

It compiles, but when I try to run it, it gives me a "RPC: Can't encode arguments"

EDIT: Actually the server do not recieve any argument neither it send back anything, that's why I put a xdr_void added &in and &out to avoid segmentation fault error.

Argos
  • 81
  • 1
  • 2
  • 12

1 Answers1

1

You are missing some parentheses:

if (stat = callrpc(...) != 0)

is evaluated to

if (stat = (callrpc(...) != 0))

which always assigns 1 to stat in case of an error, which is RPC_CANTENCODEARGS. You need

if ((stat = callrpc(...)) != 0)

to get the real error code and message printed in

clnt_perrno(stat);
Ctx
  • 18,090
  • 24
  • 36
  • 51