clnttcp_create Subroutine

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

clnttcp_create Subroutine Exported from the libc Library

Purpose

Creates a Transmission Control Protocol/Internet Protocol (TCP/IP) client transport handle.

Library

C Library (libc.a)

Syntax

CLIENT *clnttcp_create (addr, prognum, versnum, sockp, sendsz, recvsz)
struct sockaddr_in * addr;
u_long  prognum,  versnum;
int * sockp;
u_int  sendsz,  recvsz;

Description

The clnttcp_create subroutine creates a Remote Procedure Call (RPC) client transport handle for a remote program. This client uses TCP/IP as the transport to pass messages to the service.

The TCP/IP remote procedure calls use buffered input/output (I/O). Users can set the size of the send and receive buffers with the sendsz and recvsz parameters. If the size of either buffer is set to a value of 0, the clnttcp_create subroutine picks suitable default values.

Parameters

Item Description
addr Points to the Internet address of the remote program. If the port number for this Internet address (addr->sin_port) is a value of 0, then the addr parameter is set to the actual port on which the remote program is listening. The client making the remote procedure call consults the remote portmap daemon to obtain the port information.
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
sockp Specifies a pointer to a socket. If the value of the sockp parameter is RPC_ANYSOCK, the clnttcp_create subroutine opens a new socket and sets the sockp pointer to the new socket.
sendsz Sets the size of the send buffer.
recvsz Sets the size of the receive buffer.

Return Values

Upon successful completion, this routine returns a valid TCP/IP client handle. If unsuccessful, it returns a value of null.

clnttcp_create Subroutine Exported from the libnsl Library

Purpose

Creates a Transmission Control Protocol/Internet Protocol (TCP/IP) client transport handle.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
CLIENT *clnttcp_create (addr, prognum, versnum, fdp, sendsz, recvsz)
struct sockaddr_in *addr;
rpcprog_t prognum;
rpcvers_t versnum;
int *fdp;
uint_t sendsz, recvsz;

Description

The clnttcp_create subroutine creates a Remote Procedure Call (RPC) client transport handle for a remote program. This client uses TCP/IP as the transport to pass messages to the service.

The TCP/IP remote procedure calls use buffered input/output (I/O). Users can set the size of the send and receive buffers with the sendsz and recvsz parameters. If the size of either buffer is set to a value of 0, the clnttcp_create subroutine picks suitable default values.

Parameters

Item Description
addr Points to the Internet address of the remote program. If the port number for this Internet address (addr->sin_port) is a value of 0, then the addr parameter is set to the actual port on which the remote program is listening. The client making the remote procedure call consults the remote portmap daemon to obtain the port information.
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
fdp Specifies a pointer to a socket. If the value of the fdp parameter is RPC_ANYSOCK, the clnttcp_create subroutine opens a new socket and sets the fdp pointer to the new socket.
sendsz Sets the size of the send buffer.
recvsz Sets the size of the receive buffer.

Return Values

Item Description
a valid TCP/IP client handle successful
a null value unsuccessful

Error Codes

Item Description
RPC_PROGNOTREGISTERED The program is not registered.
RPC_SYSTEMERROR The file descriptor is not valid.

Examples

In the following example, the clnttcp_create subroutine creates and returns a TCP/IP client transport handle.

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

#define ADDRBUFSIZE 255

int main()
{
  CLIENT *clnt;
  rpcprog_t  PROGNUM = 0x3fffffffL;
  rpcvers_t  PROGVER = 0x1L;
  int    fd;
  uint_t  sendsz=0, recvsz=0;
  struct sockaddr_in addr;
  char       addrbuf[ADDRBUFSIZE];
  struct netbuf   svcaddr;
  struct netconfig *nconf;
  char host[255] ; /* The remote host name */

  svcaddr.len = 0;
  svcaddr.maxlen = ADDRBUFSIZE;
  svcaddr.buf = addrbuf;

  /* Get pointer to struct netconfig for tcp transport */
  nconf = getnetconfigent("tcp");
  if (nconf == (struct netconfig *) NULL) {
    printf("getnetconfigent() failed\n");
    exit(1);
  }

  /* Get the address of remote service */  
  if (!rpcb_getaddr(PROGNUM, PROGVER, nconf, &svcaddr, host)) {
    printf("rpcb_getaddr() failed\n");
    exit(1);
  }
  memcpy(&addr, svcaddr.buf, sizeof(struct sockaddr_in));

  fd = ... /*   Code to obtain open and bound file descriptor on tcp transport  */

  clnt = (CLIENT *) clnttcp_create(&addr, PROGNUM, PROGVER, &fd, sendsz, recvsz);

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

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

  return 0;
}