xref: /illumos-gate/usr/src/cmd/fs.d/nfs/lib/clnt_subr.c (revision a2f332bb)
1*a2f332bbSToomas Soome /*
2*a2f332bbSToomas Soome  * CDDL HEADER START
3*a2f332bbSToomas Soome  *
4*a2f332bbSToomas Soome  * The contents of this file are subject to the terms of the
5*a2f332bbSToomas Soome  * Common Development and Distribution License (the "License").
6*a2f332bbSToomas Soome  * You may not use this file except in compliance with the License.
7*a2f332bbSToomas Soome  *
8*a2f332bbSToomas Soome  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*a2f332bbSToomas Soome  * or http://www.opensolaris.org/os/licensing.
10*a2f332bbSToomas Soome  * See the License for the specific language governing permissions
11*a2f332bbSToomas Soome  * and limitations under the License.
12*a2f332bbSToomas Soome  *
13*a2f332bbSToomas Soome  * When distributing Covered Code, include this CDDL HEADER in each
14*a2f332bbSToomas Soome  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*a2f332bbSToomas Soome  * If applicable, add the following below this CDDL HEADER, with the
16*a2f332bbSToomas Soome  * fields enclosed by brackets "[]" replaced with your own identifying
17*a2f332bbSToomas Soome  * information: Portions Copyright [yyyy] [name of copyright owner]
18*a2f332bbSToomas Soome  *
19*a2f332bbSToomas Soome  * CDDL HEADER END
20*a2f332bbSToomas Soome  */
21*a2f332bbSToomas Soome /*
22*a2f332bbSToomas Soome  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
23*a2f332bbSToomas Soome  * Use is subject to license terms.
24*a2f332bbSToomas Soome  */
25*a2f332bbSToomas Soome 
26*a2f332bbSToomas Soome #include <libintl.h>
27*a2f332bbSToomas Soome #include <rpcsvc/mount.h>
28*a2f332bbSToomas Soome #include "clnt_subr.h"
29*a2f332bbSToomas Soome 
30*a2f332bbSToomas Soome /*
31*a2f332bbSToomas Soome  * Common code to create client of MOUNTPROG protocol.
32*a2f332bbSToomas Soome  * Used by dfmounts, dfshares, showmount.
33*a2f332bbSToomas Soome  */
34*a2f332bbSToomas Soome CLIENT *
mountprog_client_create(const char * host,struct timeval * tv)35*a2f332bbSToomas Soome mountprog_client_create(const char *host, struct timeval *tv)
36*a2f332bbSToomas Soome {
37*a2f332bbSToomas Soome 	rpcvers_t versnum;
38*a2f332bbSToomas Soome 	CLIENT *cl;
39*a2f332bbSToomas Soome 
40*a2f332bbSToomas Soome 	/*
41*a2f332bbSToomas Soome 	 * First try circuit, then drop back to datagram if
42*a2f332bbSToomas Soome 	 * circuit is unavailable (an old version of mountd perhaps)
43*a2f332bbSToomas Soome 	 * Using circuit is preferred because it can handle
44*a2f332bbSToomas Soome 	 * arbitrarily long export lists.
45*a2f332bbSToomas Soome 	 */
46*a2f332bbSToomas Soome 	cl = clnt_create_vers(host, MOUNTPROG, &versnum,
47*a2f332bbSToomas Soome 	    MOUNTVERS, MOUNTVERS3, "circuit_n");
48*a2f332bbSToomas Soome 	if (cl == NULL) {
49*a2f332bbSToomas Soome 		if (rpc_createerr.cf_stat == RPC_PROGNOTREGISTERED)
50*a2f332bbSToomas Soome 			cl = clnt_create_vers(host, MOUNTPROG, &versnum,
51*a2f332bbSToomas Soome 			    MOUNTVERS, MOUNTVERS3, "datagram_n");
52*a2f332bbSToomas Soome 		if (cl == NULL) {
53*a2f332bbSToomas Soome 			pr_err(gettext("can't contact server: %s\n"),
54*a2f332bbSToomas Soome 			    clnt_spcreateerror(host));
55*a2f332bbSToomas Soome 			(void) __rpc_control(CLCR_SET_RPCB_TIMEOUT, tv);
56*a2f332bbSToomas Soome 		}
57*a2f332bbSToomas Soome 	}
58*a2f332bbSToomas Soome 	return (cl);
59*a2f332bbSToomas Soome }
60