Purpose
Indicates why a remote procedure call failed.
Library
C Library (libc.a)
Syntax
Description
The clnt_sperror subroutine returns a string to standard error output indicating why a Remote Procedure Call (RPC) call failed. This subroutine also returns the pointer to static data overwritten on each call.
Parameters
| Item | Description | 
|---|---|
| cl | 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.
Purpose
Returns the error message indicating why a remote procedure call failed.
Library
Network Services Library (libnsl.a)
Syntax
Description
Parameters
| Item | Description | 
|---|---|
| cl | 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.
Examples
In the following example, the clnt_sperror subroutine returns the reason for failure of a remote procedure call that is pointed to by the err_str parameter.
#include <rpc/clnt.h>
#include <stdio.h>
#include <sys/time.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 ;
  char *err_str ;  
  /* 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);
  }
  /* Call 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)
  {
      err_str = clnt_sperror(client,"Client Call failed");
      fprintf(stderr,"%s",err_str);
      exit(1);
  }
  /* Destroy client handle in the end */
  clnt_destroy(client);
  
  return 0;
}