clnt_perrno Subroutine

Important: The subroutine is exported from both the libc and the libnsl libraries.

clnt_perrno Subroutine Exported from the libc Library

Purpose

Specifies the condition of the stat parameter.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

void clnt_perrno ( stat)
enum clnt_stat stat;

Description

The clnt_perrno subroutine writes a message to standard error output, corresponding to the condition specified by the stat parameter.

This subroutine is used after a clnt_call subroutine fails. The clnt_perrno subroutine translates the failure status (the enum clnt_stat subroutine) into a message.

If the program does not have a standard error output, or the programmer does not want the message to be output with the printf subroutine, or the message format used is different from that supported by the clnt_perrno subroutine, then the clnt_sperrno subroutine is used instead of the clnt_perrno subroutine.

Parameters

Item Description
stat Specifies the client error status of the remote procedure call.

Return Values

The clnt_perrno subroutine translates and displays the following enum clnt_stat error status codes:

Item Description
RPC_SUCCESS = 0 Call succeeded.
RPC_CANTENCODEARGS = 1 Cannot encode arguments.
RPC_CANTDECODERES = 2 Cannot decode results.
RPC_CANTSEND = 3 Failure in sending call.
RPC_CANTRECV = 4 Failure in receiving result.
RPC_TIMEDOUT = 5 Call timed out.

clnt_perrno Subroutine Exported from the libnsl Library

Purpose

Specifies the reason for failure of the procedure call.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
void clnt_perrno ( stat)
const enum clnt_stat stat;

Description

The clnt_perrno subroutine writes a message to standard error output, corresponding to the condition specified by the stat parameter.

This subroutine is used after a clnt_call subroutine fails. The clnt_perrno subroutine translates the failure status (the enum clnt_stat subroutine) into a message.

If the program does not have a standard error output, or the programmer does not want the message to be output with the printf subroutine, or the message format used is different from that supported by the clnt_perrno subroutine, the clnt_sperrno subroutine is used instead of the clnt_perrno subroutine.

Parameters

Item Description
stat Specifies the client error status of the remote procedure call.

Error Codes

The following table list some error status codes that the clnt_perrno subroutine can translate and display. You can find a complete list of error codes in the clnt_stat.h file.

Item Description
RPC_SUCCESS = 0 The call succeeded.
RPC_CANTENCODEARGS = 1 Arguments cannot be encoded.
RPC_CANTDECODERES = 2 Results cannot be decoded .
RPC_CANTSEND = 3 A failure occurred in sending call.
RPC_CANTRECV = 4 A failure occurred in receiving result.
RPC_TIMEDOUT = 5 The call timed out.

Examples

In the following example, the clnt_perrno subroutine displays the condition of the cs parameter.

#include <stdlib.h>
#include <rpc/rpc.h>
#include <sys/time.h>

int main()
{
  char hostname[255] ; /* The Remote host on which server is implemented */
  rpcprog_t program_number ;
  rpcvers_t version_number ;
   rpcproc_t procedure_number ;
  enum clnt_stat cs ;  
  char *nettype = "visible";

  cs = rpc_call(hostname, program_number, version_number, procedure_number,
                 (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_void, NULL, nettype);
  if (cs != RPC_SUCCESS)
  {
    fprintf(stderr,"\n RPC Call failed\n");
    clnt_perrno(cs) ;
    exit(1);  
  }

return 0 ;
}