clnt_perror Subroutine

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

clnt_perror Subroutine Exported from the libc Library

Purpose

Indicates why a remote procedure call failed.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

clnt_perror ( clnt,  s)
CLIENT *clnt;
char *s;

Description

The clnt_perror subroutine writes a message to standard error output indicating why a remote procedure call failed. The message is preceded by the string pointed to by the s parameter and a colon.

This subroutine is used after the clnt_call macro.

Parameters

Item Description
clnt Points to the structure of the client handle.
s Points to a character string that represents the error text.

Return Values

This subroutine returns an error string to standard error output.

clnt_perror Subroutine Exported from the libnsl Library

Purpose

Indicates why a remote procedure call failed.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
void clnt_perror ( clnt, s)
const CLIENT *clnt;
const char *s;

Description

The clnt_perror subroutine writes a message to standard error output indicating why a remote procedure call failed. The message is preceded by the string pointed to by the s parameter and a colon. The message is appended by a newline. This subroutine is used after the clnt_call macro.

Parameters

Item Description
clnt Points to the structure of the client handle.
s Points to a character string that represents the error text.

Examples

In the following example, the clnt_perror subroutine displays the reason for failure of a remote procedure call.

#include <stdio.h>
#include <rpc/rpc.h>
int main()
{
  CLIENT *client ;
  char hostname[255] ; /* The Remote host on which server is implemented */
  rpcprog_t program_number = 0x3fffffffL;
  rpcvers_t version_number = 0x1L;
  rpcproc_t procedure_number = 0x1L;
  struct timeval total_timeout = { 25 , 0 } ;
  enum clnt_stat cs ;  

  /* Create client handle */
  client = clnt_create(hostname, program_number, version_number, "tcp");
  if (client == (CLIENT *)NULL)
  {
    fprintf(stderr,"Couldn't create client\n");
    exit(1);
  }

  /* Make a call to remote procedure associated with client handle */
  cs = clnt_call(client, procedure_number, (xdrproc_t)xdr_void, NULL,
                    (xdrproc_t)xdr_void, NULL, total_timeout);
  if (cs != RPC_SUCCESS)
  {
    clnt_perror(client,"Client Call failed");
    exit(1);
  }

  /* Destroy client handle in the end */
  clnt_destroy(client);

  return 0;
}