2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
30 * Copyright (C) 1987, Sun Microsystems, Inc.
40 #include <sys/socket.h>
43 /* Experimentally off - libc_hidden_proto(memcpy) */
44 /* Experimentally off - libc_hidden_proto(memset) */
45 /* Experimentally off - libc_hidden_proto(strcmp) */
46 /* Experimentally off - libc_hidden_proto(strcpy) */
47 /* libc_hidden_proto(clnttcp_create) */
48 /* libc_hidden_proto(clntudp_create) */
49 /* libc_hidden_proto(clntunix_create) */
50 /* libc_hidden_proto(getprotobyname_r) */
51 /* libc_hidden_proto(gethostbyname_r) */
52 /* libc_hidden_proto(__rpc_thread_createerr) */
55 * Generic client creation: takes (hostname, program-number, protocol) and
56 * returns client handle. Default options are set, which the user can
57 * change using the rpc equivalent of ioctl()'s.
60 clnt_create (const char *hostname, u_long prog, u_long vers,
63 struct hostent hostbuf, *h;
66 struct protoent protobuf, *p;
69 struct sockaddr_in sin;
70 struct sockaddr_un sun;
76 if (strcmp (proto, "unix") == 0)
78 memset ((char *)&sun, 0, sizeof (sun));
79 sun.sun_family = AF_UNIX;
80 strcpy (sun.sun_path, hostname);
82 client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
86 /* This is not wanted. This would disable the user from having
87 a timeout in the clnt_call() call. Only a call to cnlt_control()
88 by the user should set the timeout value. */
91 clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
97 hsttmpbuf = alloca (hstbuflen);
98 while (gethostbyname_r (hostname, &hostbuf, hsttmpbuf, hstbuflen,
101 if (herr != NETDB_INTERNAL || errno != ERANGE)
103 get_rpc_createerr().cf_stat = RPC_UNKNOWNHOST;
108 /* Enlarge the buffer. */
110 hsttmpbuf = alloca (hstbuflen);
113 if (h->h_addrtype != AF_INET)
116 * Only support INET for now
118 struct rpc_createerr *ce = &get_rpc_createerr ();
119 ce->cf_stat = RPC_SYSTEMERROR;
120 ce->cf_error.re_errno = EAFNOSUPPORT;
123 sin.sin_family = h->h_addrtype;
125 memset (sin.sin_zero, 0, sizeof (sin.sin_zero));
126 memcpy ((char *) &sin.sin_addr, h->h_addr, h->h_length);
129 prttmpbuf = alloca (prtbuflen);
130 while (getprotobyname_r (proto, &protobuf, prttmpbuf, prtbuflen, &p) != 0
134 struct rpc_createerr *ce = &get_rpc_createerr ();
135 ce->cf_stat = RPC_UNKNOWNPROTO;
136 ce->cf_error.re_errno = EPFNOSUPPORT;
141 /* Enlarge the buffer. */
143 prttmpbuf = alloca (prtbuflen);
152 client = clntudp_create (&sin, prog, vers, tv, &sock);
158 /* This is not wanted. This would disable the user from having
159 a timeout in the clnt_call() call. Only a call to cnlt_control()
160 by the user should set the timeout value. */
162 clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
166 client = clnttcp_create (&sin, prog, vers, &sock, 0, 0);
172 /* This is not wanted. This would disable the user from having
173 a timeout in the clnt_call() call. Only a call to cnlt_control()
174 by the user should set the timeout value. */
177 clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
182 struct rpc_createerr *ce = &get_rpc_createerr ();
183 ce->cf_stat = RPC_SYSTEMERROR;
184 ce->cf_error.re_errno = EPFNOSUPPORT;