2 * Copyright (c) 2010, Oracle America, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of the "Oracle America, Inc." nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/socket.h>
40 * Generic client creation: takes (hostname, program-number, protocol) and
41 * returns client handle. Default options are set, which the user can
42 * change using the rpc equivalent of ioctl()'s.
45 clnt_create (const char *hostname
, u_long prog
, u_long vers
,
48 struct hostent hostbuf
, *h
;
51 struct protoent protobuf
, *p
;
54 struct sockaddr_in sin
;
55 struct sockaddr_un sun
;
61 if (strcmp (proto
, "unix") == 0)
63 __bzero ((char *)&sun
, sizeof (sun
));
64 sun
.sun_family
= AF_UNIX
;
65 strcpy (sun
.sun_path
, hostname
);
67 client
= clntunix_create (&sun
, prog
, vers
, &sock
, 0, 0);
71 /* This is not wanted. This would disable the user from having
72 a timeout in the clnt_call() call. Only a call to cnlt_control()
73 by the user should set the timeout value. */
76 clnt_control (client
, CLSET_TIMEOUT
, (char *)&tv
);
82 hsttmpbuf
= __alloca (hstbuflen
);
83 while (__gethostbyname_r (hostname
, &hostbuf
, hsttmpbuf
, hstbuflen
,
86 if (herr
!= NETDB_INTERNAL
|| errno
!= ERANGE
)
88 get_rpc_createerr().cf_stat
= RPC_UNKNOWNHOST
;
93 /* Enlarge the buffer. */
95 hsttmpbuf
= __alloca (hstbuflen
);
98 if (h
->h_addrtype
!= AF_INET
)
101 * Only support INET for now
103 struct rpc_createerr
*ce
= &get_rpc_createerr ();
104 ce
->cf_stat
= RPC_SYSTEMERROR
;
105 ce
->cf_error
.re_errno
= EAFNOSUPPORT
;
108 sin
.sin_family
= h
->h_addrtype
;
110 __bzero (sin
.sin_zero
, sizeof (sin
.sin_zero
));
111 memcpy ((char *) &sin
.sin_addr
, h
->h_addr
, h
->h_length
);
114 prttmpbuf
= __alloca (prtbuflen
);
115 while (__getprotobyname_r (proto
, &protobuf
, prttmpbuf
, prtbuflen
, &p
) != 0
119 struct rpc_createerr
*ce
= &get_rpc_createerr ();
120 ce
->cf_stat
= RPC_UNKNOWNPROTO
;
121 ce
->cf_error
.re_errno
= EPFNOSUPPORT
;
126 /* Enlarge the buffer. */
128 prttmpbuf
= __alloca (prtbuflen
);
137 client
= clntudp_create (&sin
, prog
, vers
, tv
, &sock
);
143 /* This is not wanted. This would disable the user from having
144 a timeout in the clnt_call() call. Only a call to cnlt_control()
145 by the user should set the timeout value. */
147 clnt_control (client
, CLSET_TIMEOUT
, (char *)&tv
);
151 client
= clnttcp_create (&sin
, prog
, vers
, &sock
, 0, 0);
157 /* This is not wanted. This would disable the user from having
158 a timeout in the clnt_call() call. Only a call to cnlt_control()
159 by the user should set the timeout value. */
162 clnt_control (client
, CLSET_TIMEOUT
, (char *)&tv
);
167 struct rpc_createerr
*ce
= &get_rpc_createerr ();
168 ce
->cf_stat
= RPC_SYSTEMERROR
;
169 ce
->cf_error
.re_errno
= EPFNOSUPPORT
;
175 #ifdef EXPORT_RPC_SYMBOLS
176 libc_hidden_def (clnt_create
)
178 libc_hidden_nolink (clnt_create
, GLIBC_2_0
)