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 #if defined(LIBC_SCCS) && !defined(lint)
31 /*static char *sccsid = "from: @(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";*/
32 /*static char *sccsid = "from: @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC";*/
33 static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_generic.c,v 1.9.2.1 2001/03/05 10:48:28 obrien Exp $";
37 * Copyright (C) 1987, Sun Microsystems, Inc.
40 #include <sys/socket.h>
46 * Generic client creation: takes (hostname, program-number, protocol) and
47 * returns client handle. Default options are set, which the user can
48 * change using the rpc equivalent of ioctl()'s.
51 clnt_create(hostname, prog, vers, proto)
59 struct sockaddr_in sin;
60 struct sockaddr_un sun;
62 static struct timeval tv;
65 if (!strcmp(proto, "unix")) {
66 bzero((char *)&sun, sizeof(sun));
67 sun.sun_family = AF_UNIX;
68 strcpy(sun.sun_path, hostname);
69 sun.sun_len = sizeof(sun.sun_len) + sizeof(sun.sun_family) +
70 strlen(sun.sun_path) + 1;
72 client = clntunix_create(&sun, prog, vers, &sock, 0, 0);
77 clnt_control(client, CLSET_TIMEOUT, &tv);
81 h = gethostbyname(hostname);
83 rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
86 if (h->h_addrtype != AF_INET) {
88 * Only support INET for now
90 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
91 rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
94 memset(&sin, 0, sizeof(sin));
95 sin.sin_len = sizeof(struct sockaddr_in);
96 sin.sin_family = h->h_addrtype;
98 memcpy((char*)&sin.sin_addr, h->h_addr, h->h_length);
99 p = getprotobyname(proto);
101 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
102 rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
106 switch (p->p_proto) {
110 client = clntudp_create(&sin, prog, vers, tv, &sock);
111 if (client == NULL) {
114 #if 0 /* XXX do we need this? */
117 clnt_control(client, CLSET_TIMEOUT, &tv);
121 client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
122 if (client == NULL) {
125 #if 0 /* XXX do we need this? */
128 clnt_control(client, CLSET_TIMEOUT, &tv);
132 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
133 rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;