clnt_spcreateerror Subroutine

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

clnt_spcreateerror Subroutine Exported from the libc Library

Purpose

Indicates why a client Remote Procedure Call (RPC) handle was not created.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

char *clnt_spcreateerror ( s)
char *s;

Description

The clnt_spcreateerror subroutine returns a string indicating why a client RPC handle was not created.

Note: This subroutine returns the pointer to static data that is overwritten on each call.

Parameters

Item Description
s Points to a character string that represents the error text.

clnt_spcreateerror Subroutine Exported from the libnsl Library

Purpose

Returns an error message that is related to the remote procedure call (RPC) client-handle creation.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
char * clnt_spcreateerror( error_msg );
const char *error_msg ;

Description

The clnt_spcreateerror subroutine is used for error handling. The subroutine displays the actual cause of failure of the creation of an RPC client handle. The actual error message is preceded by the string specified by error_msg parameter and a colon. However, the actual error message is not appended with a newline.
Note: If the error_msg parameter has a null value, the output is a colon followed by the actual error message.

Parameters

Item Description
error_msg Specified an error-message string that is provided by an application.

Example

In the following example, the clnt_create subroutine tries to register a program number that is not valid and hence returns a null value. The clnt_spcreateerror subroutine returns the actual error message, which is preceded by the specified string ("Invalid Program Number" ) and a colon.

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

int main()
{
  CLIENT *cl;
  char hostname[255] ;  /* The name of remote host */
  char *nettype = "visible" ;
  rpcprog_t PROGNUM ; /* Invalid Value */ 
  rpcvers_t PROGVER ;
  char *err_str;

  cl = clnt_create(hostname, PROGNUM, PROGVER, nettype);

  if(cl==NULL)
  {
    err_str = clnt_spcreateerror("Invalid Program Number ");
    printf("\n%s",err_str);
    exit(1);
  }

  /* 
  * Make a call to clnt_call() subroutine 
  */

  /* Destroy the client handle at the end */
  clnt_destroy(cl);

  return 0;
}