ONC+ Developer's Guide

Client Side of the Intermediate-Level Interface

The following example shows the client side of the time service from Top-Level Interface, written at the intermediate level of RPC. In this example, the user must name the transport over which the call is made on the command line.

Example 4–10 Client for Time Service, Intermediate Level

#include <stdio.h>

#include <rpc/rpc.h>
#include <netconfig.h>		/* For netconfig structure */
#include "time_prot.h"
#define TOTAL (30)
	int argc;
	char *argv[];
	CLIENT *client;
	struct netconfig *nconf;
	char *netid;
	/* Declarations from previous example */
	if (argc != 3) {
		fprintf(stderr, "usage: %s host netid\n”,
	netid = argv[2];
	if ((nconf = getnetconfigent( netid)) ==
	    (struct netconfig *) NULL) {
		fprintf(stderr, "Bad netid type: %s\n",
	client = clnt_tp_create(argv[1], TIME_PROG,
										TIME_VERS, nconf);
	if (client == (CLIENT *) NULL) {
		clnt_pcreateerror("Could not create client");
	/* Same as previous example after this point */

In this example, the netconfig structure is obtained by a call to getnetconfigent(netid). See the getnetconfig(3NSL) man page and Programming Interfaces Guide for more details. At this level, the program explicitly selects the network.

To bound the time allowed for client handle creation in the previous example to 30 seconds, replace the call to clnt_tp_create() with a call to clnt_tp_create_timed() as shown in the following code segment:

 struct timeval timeout;
 timeout.tv_sec = 30; /* 30 seconds */
 timeout.tv_usec = 0;

 client = clnt_tp_create_timed(argv[1], 
				TIME_PROG, TIME_VERS, nconf,