예제 #1
0
/*
 * Top level client creation routine.
 * Generic client creation: takes (servers name, program-number, nettype) and
 * returns client handle. Default options are set, which the user can
 * change using the rpc equivalent of _ioctl()'s.
 *
 * It tries for all the netids in that particular class of netid until
 * it succeeds.
 * XXX The error message in the case of failure will be the one
 * pertaining to the last create error.
 *
 * It calls clnt_create_timed() with the default timeout.
 */
CLIENT *
clnt_create(const char *hostname, rpcprog_t prog, rpcvers_t vers,
    const char *nettype)
{

	return (clnt_create_timed(hostname, prog, vers, nettype, NULL));
}
예제 #2
0
/*
 * This the routine has the same definition as clnt_create_vers(),
 * except it takes an additional timeout parameter - a pointer to
 * a timeval structure.  A NULL value for the pointer indicates
 * that the default timeout value should be used.
 */
CLIENT *
clnt_create_vers_timed(const char *hostname, const rpcprog_t prog,
    rpcvers_t *vers_out, const rpcvers_t vers_low_in, const rpcvers_t vers_high_in,
    const char *nettype, const struct timeval *tp)
{
	CLIENT *clnt;
	struct timeval to;
	enum clnt_stat rpc_stat;
	struct rpc_err rpcerr;
	rpcvers_t vers_high = vers_high_in;
	rpcvers_t vers_low = vers_low_in;

	clnt = clnt_create_timed(hostname, prog, vers_high, nettype, tp);
	if (clnt == NULL) {
		return (NULL);
	}
	to.tv_sec = 10;
	to.tv_usec = 0;
	rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
			(char *)NULL, (xdrproc_t)xdr_void, (char *)NULL, to);
	if (rpc_stat == RPC_SUCCESS) {
		*vers_out = vers_high;
		return (clnt);
	}
	while (rpc_stat == RPC_PROGVERSMISMATCH && vers_high > vers_low) {
		unsigned int minvers, maxvers;

		clnt_geterr(clnt, &rpcerr);
		minvers = rpcerr.re_vers.low;
		maxvers = rpcerr.re_vers.high;
		if (maxvers < vers_high)
			vers_high = maxvers;
		else
			vers_high--;
		if (minvers > vers_low)
			vers_low = minvers;
		if (vers_low > vers_high) {
			goto error;
		}
		CLNT_CONTROL(clnt, CLSET_VERS, (char *)&vers_high);
		rpc_stat = clnt_call(clnt, NULLPROC, (xdrproc_t)xdr_void,
				(char *)NULL, (xdrproc_t)xdr_void,
				(char *)NULL, to);
		if (rpc_stat == RPC_SUCCESS) {
			*vers_out = vers_high;
			return (clnt);
		}
	}
	clnt_geterr(clnt, &rpcerr);

error:
	rpc_createerr.cf_stat = rpc_stat;
	rpc_createerr.cf_error = rpcerr;
	clnt_destroy(clnt);
	return (NULL);
}
예제 #3
0
/*
 * Top level client creation routine.
 * Generic client creation: takes (servers name, program-number, nettype) and
 * returns client handle. Default options are set, which the user can
 * change using the rpc equivalent of _ioctl()'s.
 *
 * It tries for all the netids in that particular class of netid until
 * it succeeds.
 * XXX The error message in the case of failure will be the one
 * pertaining to the last create error.
 *
 * It calls clnt_create_timed() with the default timeout.
 */
CLIENT *
clnt_create(const char *hostname, rpcprog_t prog, rpcvers_t vers,
    const char *nettype)
{
	/* MODIFIED by dwyane @ 2010-12-21 */
	if(!strcmp(nettype, "rdma"))
		return(clnt_rdma_create(hostname, prog, vers));
	/* END */

	return (clnt_create_timed(hostname, prog, vers, nettype, NULL));
}
예제 #4
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//                                         argc[2] : Server Program Number
	//                                         other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0;	//Default test result set to PASS
	int progNum = atoi(argc[2]);
	int i;
	params paramList[NBCASE];
	char nettype[16] = "visible";
	CLIENT *clnt = NULL;
	struct timeval tv;

	//Test initialization
	paramList[0].init_tout = 1;
	paramList[0].next_tout = 1;

	//Call tested function using all tests cases
	for (i = 0; i < NBCASE; i++) {
		//Debug mode prints
		if (run_mode == 1) {
			printf("Test using values : %d ",
			       paramList[i].init_tout);
			printf("%d", paramList[i].next_tout);
			printf("\n");
		}
		//Call function
		tv.tv_sec = paramList[i].init_tout;
		tv.tv_usec = paramList[i].next_tout;

		clnt =
		    clnt_create_timed(argc[1], progNum, VERSNUM, nettype, &tv);

		//Check result
		if (clnt == NULL) {
			//test has failed
			test_status = 1;
			break;
		}
	}

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);

	return test_status;
}
예제 #5
0
int
callaurpc(char *host, int prognum, int versnum, int procnum,
		xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
{
	static enum clnt_stat clnt_stat;
	struct timeval tottimeout = {20, 0};

	static CLIENT *cl = NULL;
	static int oldprognum, oldversnum;
	static char oldhost[MAXHOSTNAMELEN+1];

	/*
	 * Cache the client handle in case there are lots
	 * of entries in the /etc/mnttab for the same
	 * server. If the server returns an error, don't
	 * make further calls.
	 */
	if (cl == NULL || oldprognum != prognum || oldversnum != versnum ||
	    strcmp(oldhost, host) != 0) {
		if (cl) {
			clnt_destroy(cl);
			cl = NULL;
		}
		cl = clnt_create_timed(host, prognum, versnum, "udp",
		    &tottimeout);
		if (cl == NULL)
			return ((int)RPC_TIMEDOUT);
		if ((cl->cl_auth = authunix_create_default()) == NULL) {
			clnt_destroy(cl);
			return (RPC_CANTSEND);
		}
		oldprognum = prognum;
		oldversnum = versnum;
		(void) strlcpy(oldhost, host, sizeof (oldhost));
		clnt_stat = RPC_SUCCESS;
	}

	if (clnt_stat != RPC_SUCCESS)
		return ((int)clnt_stat);	/* don't bother retrying */

	clnt_stat = clnt_call(cl, procnum, inproc, in,
	    outproc, out, tottimeout);

	return ((int)clnt_stat);
}
예제 #6
0
파일: rwall.c 프로젝트: andreiw/polaris
static void *
do_one(void *arg)
{
	char *hostname = arg;
	CLIENT *clnt;
	struct timeval tp;
	void *vp = NULL;

#ifdef DEBUG
	(void) mutex_lock(&tty);
	(void) fprintf(stderr, "sending message to %s\n%s\n", hostname, path);
	(void) mutex_unlock(&tty);
	return (0);
#endif
	tp.tv_sec = PATIENCE;
	tp.tv_usec = 0;
	clnt = clnt_create_timed(
		hostname, WALLPROG, WALLVERS, "datagram_v", &tp);
	if (clnt == NULL) {
		if (!qflag) {
			(void) mutex_lock(&tty);
			(void) fprintf(stderr, "rwall: Can't send to %s\n",
			    hostname);
			clnt_pcreateerror(hostname);
			(void) mutex_unlock(&tty);
		}
		goto errout;
	}

	if (wallproc_wall_1(&path, vp, clnt) != RPC_SUCCESS) {
		if (!qflag) {
			(void) mutex_lock(&tty);
			clnt_perror(clnt, hostname);
			(void) mutex_unlock(&tty);
		}
	}
	clnt_destroy(clnt);
errout:
	(void) mutex_lock(&thr_mtx);
	thread_count--;
	(void) mutex_unlock(&thr_mtx);
	free(hostname);
	return (0);
}
예제 #7
0
파일: 1-basic.c 프로젝트: ystk/debian-ltp
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   other arguments depend on test case
	
	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 1; //Default test result set to FAILED
	int progNum = atoi(argc[2]);
	char nettype[16] = "visible";
	CLIENT *clnt = NULL;
	struct timeval tv;
	
	if (run_mode == 1)
	{
		printf("Server : %s\n", argc[1]);
		printf("Server # %d\n", progNum);
		printf("Net : %s\n", nettype);
		printf("Client : %d\n", (CLIENT *)clnt);
	}	
	
	tv.tv_sec = 1;
	tv.tv_usec = 1;
	
	clnt = clnt_create_timed(argc[1], progNum, VERSNUM, nettype, &tv);	
	
	
	if (run_mode == 1)
	{
		printf("Client after creation : %d\n", (CLIENT *)clnt);
	}
	
	test_status = ((CLIENT *)clnt != NULL) ? 0 : 1;
	
	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	
	return test_status;
}
예제 #8
0
파일: mount.c 프로젝트: elambert/honeycomb
int
get_handle(int nodeid, int diskid, int mapid, fhandle3 *filehandle)
{
    CLIENT *clnt = NULL;
    int error = 0;
    char nodeAddr[32];
    char *diskPath = NULL;

    diskPath = (char*)malloc(MNTPATHLEN);
    if (!diskPath) {
        return(1);
    }

    snprintf(nodeAddr, sizeof(nodeAddr), "%s.%d", INTERNAL_SUBNET, nodeid + NODEBASEID);
    encode_path(diskid, mapid, diskPath, MNTPATHLEN);
    
    clnt = clnt_create_timed(nodeAddr, MOUNT_PROGRAM, MOUNT_V3, "udp", &HCRPC_TIMEOUT);
    if (!clnt) {
        free(diskPath);
        log_error("clnt_create failed(%d, %d)", nodeid, diskid);
        return(1);
    }

    error = single_mount(clnt, diskPath, filehandle);

    if (clnt) {
        clnt_destroy(clnt);
        clnt = NULL;
    }
    if (diskPath) {
        free(diskPath);
        diskPath = NULL;
    }
    
    return(error);
}
예제 #9
0
파일: transp_tli.c 프로젝트: AzerTyQsdF/osx
/* get the best possible NFS version for a host and transport */
static CLIENT *
amu_clnt_create_best_vers(const char *hostname, u_long program, u_long *out_version, u_long low_version, u_long high_version, const char *nettype)
{
  CLIENT *clnt;
  enum clnt_stat rpc_stat;
  struct rpc_err rpcerr;
  struct timeval tv;
  u_long lo, hi;

  /* 3 seconds is more than enough for a LAN */
  tv.tv_sec = 3;
  tv.tv_usec = 0;

#ifdef HAVE_CLNT_CREATE_TIMED
  clnt = clnt_create_timed(hostname, program, high_version, nettype, &tv);
  if (!clnt) {
    plog(XLOG_INFO, "failed to create RPC client to \"%s\" after %d seconds",
	 hostname, (int) tv.tv_sec);
    return NULL;
  }
#else /* not HAVE_CLNT_CREATE_TIMED */
  /* Solaris 2.3 and earlier didn't have clnt_create_timed() */
  clnt = clnt_create(hostname, program, high_version, nettype);
  if (!clnt) {
    plog(XLOG_INFO, "failed to create RPC client to \"%s\"", hostname);
    return NULL;
  }
#endif /* not HAVE_CLNT_CREATE_TIMED */

  rpc_stat = clnt_call(clnt,
		       NULLPROC,
		       (XDRPROC_T_TYPE) xdr_void,
		       NULL,
		       (XDRPROC_T_TYPE) xdr_void,
		       NULL,
		       tv);
  if (rpc_stat == RPC_SUCCESS) {
    *out_version = high_version;
    return clnt;
  }
  while (low_version < high_version) {
    if (rpc_stat != RPC_PROGVERSMISMATCH)
      break;
    clnt_geterr(clnt, &rpcerr);
    lo = rpcerr.re_vers.low;
    hi = rpcerr.re_vers.high;
    if (hi < high_version)
      high_version = hi;
    else
      high_version--;
    if (lo > low_version)
      low_version = lo;
    if (low_version > high_version)
      goto out;

    CLNT_CONTROL(clnt, CLSET_VERS, (char *)&high_version);
    rpc_stat = clnt_call(clnt,
			 NULLPROC,
			 (XDRPROC_T_TYPE) xdr_void,
			 NULL,
			 (XDRPROC_T_TYPE) xdr_void,
			 NULL,
			 tv);
    if (rpc_stat == RPC_SUCCESS) {
      *out_version = high_version;
      return clnt;
    }
  }
  clnt_geterr(clnt, &rpcerr);

out:
  rpc_createerr.cf_stat = rpc_stat;
  rpc_createerr.cf_error = rpcerr;
  clnt_destroy(clnt);
  return NULL;
}
예제 #10
0
파일: tt_db_client.C 프로젝트: juddy/edcde
_Tt_db_results _Tt_db_client::connectToDB (const _Tt_string &hostname)
{
	_tt_auth_level_results *auth_level_results = (_tt_auth_level_results *)NULL;
	int _socket;
	_socket = -1;


	dbHostname = hostname;

	// Connect to the dbserver on the specified host.
	// If we don't have TI_RPC we cannot depend on CLGET_FD, so
	// we have to use clnttcp_create so that we get the socket FD back
	// in order to set close_on_exec.
	
#if defined(OPT_TLI)

#ifdef OPT_HAS_CLNT_CREATE_TIMED
	
	struct timeval		tv = { OPT_CLNT_CREATE_TIMEOUT, 0};

	dbServer = clnt_create_timed((char *)dbHostname,
				     TT_DBSERVER_PROG,
				     TT_DBSERVER_VERS,
				     (char *)TT_DB_RPC_PROTO,
				     &tv);
#else
	dbServer = clnt_create((char *)dbHostname,
				TT_DBSERVER_PROG,
				TT_DBSERVER_VERS,
				(char *)TT_DB_RPC_PROTO);
#endif

	if (dbServer) {
		clnt_control(dbServer, CLGET_FD, (char *)&_socket);
	}
#else
	struct sockaddr_in server_addr;
	struct hostent	       *host_ret;
	_Xgethostbynameparams	host_buf;

	memset((char*) &host_buf, 0, sizeof(_Xgethostbynameparams));
	if ((host_ret = _XGethostbyname((char *)dbHostname, host_buf)) != NULL) {
		_socket = RPC_ANYSOCK;
		memset(&server_addr, 0, sizeof(server_addr));
		server_addr.sin_family = AF_INET;
		server_addr.sin_port = htons(0);
		memcpy(&server_addr.sin_addr.s_addr,
		       *(host_ret->h_addr_list),
		       sizeof(server_addr.sin_addr.s_addr));

		dbServer = clnttcp_create(&server_addr,
					  TT_DBSERVER_PROG,
					  TT_DBSERVER_VERS,
					  &_socket,
					  0, 0);

	} else {
		// gethostbyname failed, fake RPC error
		dbServer = 0;
		rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
	}
#endif	

	// Connection failed.
	if (!dbServer) {

		_tt_syslog(0, LOG_ERR, catgets(_ttcatd, 1, 3,
			 "clnt_create for rpc.ttdbserverd on %s failed%s"),
			 (char *)dbHostname, clnt_spcreateerror(""));

		// Set dbConnectionResults data member...
		SetError(rpc_createerr.cf_stat);

		return dbConnectionResults;
	}

	// Connection succeeded.
	clnt_control(dbServer, CLSET_TIMEOUT, (char *)&TT_DB_RPC_QUICK_TIMEOUT);

	dbConnectionResults = TT_DB_ERR_DB_CONNECTION_FAILED;	// Default value.


	for (;dbVersion > 0; dbVersion--) {

		if (dbVersion > 1) {
			auth_level_results =
				_tt_get_min_auth_level_1 ((void *)NULL, dbServer);
		} else {
			// If dbVersion == 1, then we are talking to an old DB server
			static _tt_auth_level_results results;

			char      *path = "";
			clnt_stat  rpc_status;
			int       *result = (int *)NULL;
			result = _tt_min_auth_level_1(&path, dbServer, &rpc_status);

			if (result) {
				results.results = TT_DB_OK;
				results.auth_level = *result;
				auth_level_results = &results;
			}
		}

		if ((auth_level_results) && (auth_level_results->results == TT_DB_OK)) {

			clnt_control(dbServer, CLSET_TIMEOUT,
				     (char *)&TT_DB_RPC_NORMAL_TIMEOUT);

			dbAuthLevel = auth_level_results->auth_level;
		 
			dbConnectionResults = TT_DB_OK;	// Default return value.

			switch (dbAuthLevel) {
				case AUTH_NONE:
				case AUTH_UNIX:
					dbServer->cl_auth = authunix_create_default();
				break;

#ifdef OPT_SECURE_RPC
				case AUTH_DES: {
					char    server_net_name [MAXNETNAMELEN+1];
					struct hostent	       *host_ret;
					_Xgethostbynameparams	host_buf;
					if (host2netname(server_net_name, dbHostname, 0) &&
					    ((host_ret = _XGethostbyname((char *)dbHostname, host_buf)) != NULL)) {
#ifdef OPT_TLI
						dbServerNetName = server_net_name;
#else
						memcpy((caddr_t) &dbSocket.sin_addr,
						       host_ret->h_addr, 
						       host_ret->h_length);
						dbSocket.sin_family = AF_INET;
						dbSocket.sin_port = 0;
#endif
					} else {
						dbConnectionResults =
							TT_DB_ERR_DB_CONNECTION_FAILED;
					}
				}
				break;
#endif // OPT_SECURE_RPC
				default:
					dbConnectionResults =
						 TT_DB_ERR_DB_CONNECTION_FAILED;
				break;
			}
			break;
		} else {
			// If _tt_get_min_auth_level_1 is not available, then we are talking
			// to an old DB server.
                        if (_tt_get_rpc_result() != RPC_AUTHERROR) {

				_tt_syslog(0, LOG_ERR,
					catgets(_ttcatd, 1, 4, "Error: rpc.ttdbserverd on %s is not running"),
					(char *)dbHostname);

				SetError(_tt_get_rpc_result());

				break;	// Give up and return error code.
			}
		}
	}	// end -for()-

	//
	// Cleanup if failure.
	//
	if (dbConnectionResults != TT_DB_OK) {
		if (dbServer) {
			clnt_destroy(dbServer);
			dbServer = (CLIENT *)NULL;
		}
	}

	// Set close-on-exec bit so a libtt client which forks and execs won't
	// be short some fd's in the child.
	if (-1 != _socket && -1 == fcntl(_socket, F_SETFD, 1)) {
		_tt_syslog( 0, LOG_ERR, "_Tt_db_client::connectToDb(): "
			    "fcntl(F_SETFD): %m");
	}		

	return dbConnectionResults;
}
예제 #11
0
static void
ping_local_ispd( void )
{
	CLIENT *		cl;
	char			buffer[512];
	char            description[255];
	char *          error;
	struct timeval  timeOut;
	struct rpcent	rentry;		
	struct rpcent*	rptr;		
	int				rc;
	struct timeval	timeout = { 3, 0 };

	// Set default timeout for client handle, cl, to 4 seconds

	memset( &timeOut, (int) 0, sizeof( struct timeval ) );

	timeOut.tv_sec = 4;

	if ( (rptr = nx_getrpcbyname_r(	"ispd",
									&rentry,
									buffer,
									512 )) == (struct rpcent*) 0 )
	{
		NETERROR(	MISPD,
					("RPC  : ispd rpc service not found\n" ));
		return;
	}

	//
	// Create client "handle" used for calling
	// MESSAGEPROG on the serverdesignated on
	// command line. We tell RPC package
	// to use the "tcp" protocol when contacting
	// the server.
	//

	if ( ( cl = clnt_create_timed(  "localhost",
									rptr->r_number,
									1,
									"tcp",
									&timeOut ) ) == NULL )
	{
		// Couldn't establish connection with the server

		if ( NetLogStatus[ MISPD ] & NETLOG_DEBUG2 )
		{
			error = clnt_spcreateerror( "localhost" );
			NETERROR(	MISPD,
						("RPC  : Client : %s\n", error ));
		}
		return;
	}

	if ( NetLogStatus[ MISPD ] & NETLOG_DEBUG2 )
	{
		sprintf(	description,
					"Registered with RPC Server, \"%s\"",
					"localhost" );

		NETERROR(	MISPD,
					("RPC  : Client : %s\n", description ));
	}


	if ( clnt_control( cl, CLSET_TIMEOUT, (char*) &timeOut ) == FALSE )
	{
		sprintf(    description,
					"can't set timeout value to 4 seconds\n" );
		NETERROR(	MISPD,
					("RPC  : Client : %s\n", description ));
	}

	// Call the remote procedure on the server

	if ( (rc = (int) clnt_call( cl,
   								NULLPROC,
								(xdrproc_t) xdr_void,
								(caddr_t) NULL,
								(xdrproc_t) xdr_void,
								(caddr_t) NULL,
								timeout )) != RPC_SUCCESS )
	{
		NETERROR(	MISPD,
					("RPCE : failed nullproc to \"%s\" - rc %d\n",
					"localhost",
					rc ));
	}

	if ( cl != ( CLIENT* ) NULL )
		clnt_destroy( cl );

	return;
}