source: rtems-libbsd/services/librpc/src/rpc/clnt_generic.c @ cd450d2

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since cd450d2 was cd450d2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/06/12 at 00:10:35

librpc: now compiles

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
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.
8 *
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.
12 *
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.
16 *
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.
20 *
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.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
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";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_generic.c,v 1.9 1999/08/28 00:00:35 peter Exp $";
34#endif
35
36/*
37 * Copyright (C) 1987, Sun Microsystems, Inc.
38 */
39#ifdef HAVE_CONFIG_H
40#include "config.h"
41#endif
42
43#include <freebsd/bsd.h>
44#include <rpc/rpc.h>
45#include <rpc/rpc.h>
46#include <sys/socket.h>
47#include <sys/errno.h>
48#include <netdb.h>
49#include <string.h>
50
51/*
52 * Generic client creation: takes (hostname, program-number, protocol) and
53 * returns client handle. Default options are set, which the user can
54 * change using the rpc equivalent of ioctl()'s.
55 */
56CLIENT *
57clnt_create(
58        const char *hostname,
59        rpcprog_t prog,
60        rpcvers_t vers,
61        const char *proto)
62{
63        struct hostent *h;
64        struct protoent *p;
65        struct sockaddr_in sin;
66#ifndef __rtems__
67        struct sockaddr_un sun;
68#endif
69        int sock;
70        struct timeval tv;
71        CLIENT *client;
72
73#ifndef __rtems__
74        if (!strcmp(proto, "unix")) {
75                bzero((char *)&sun, sizeof(sun));
76                sun.sun_family = AF_UNIX;
77                strcpy(sun.sun_path, hostname);
78                sun.sun_len = sizeof(sun.sun_len) + sizeof(sun.sun_family) +
79                                strlen(sun.sun_path) + 1;
80                sock = RPC_ANYSOCK;
81                client = clntunix_create(&sun, prog, vers, &sock, 0, 0);
82                if (client == NULL)
83                        return(NULL);
84                tv.tv_sec = 25;
85                tv.tv_usec = 0;
86                clnt_control(client, CLSET_TIMEOUT, &tv);
87                return(client);
88        }
89#endif
90
91        h = gethostbyname(hostname);
92        if (h == NULL) {
93                rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
94                return (NULL);
95        }
96        if (h->h_addrtype != AF_INET) {
97                /*
98                 * Only support INET for now
99                 */
100                rpc_createerr.cf_stat = RPC_SYSTEMERROR;
101                rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
102                return (NULL);
103        }
104        memset(&sin, 0, sizeof(sin));
105        sin.sin_len = sizeof(struct sockaddr_in);
106        sin.sin_family = h->h_addrtype;
107        sin.sin_port = 0;
108        memcpy((char*)&sin.sin_addr, h->h_addr, h->h_length);
109        p = getprotobyname(proto);
110        if (p == NULL) {
111                rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
112                rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
113                return (NULL);
114        }
115        sock = RPC_ANYSOCK;
116        switch (p->p_proto) {
117        case IPPROTO_UDP:
118                tv.tv_sec = 5;
119                tv.tv_usec = 0;
120                client = clntudp_create(&sin, prog, vers, tv, &sock);
121                if (client == NULL) {
122                        return (NULL);
123                }
124#if 0   /* XXX do we need this? */
125                tv.tv_sec = 25;
126                tv.tv_usec = 0;
127                clnt_control(client, CLSET_TIMEOUT, &tv);
128#endif
129                break;
130        case IPPROTO_TCP:
131                client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
132                if (client == NULL) {
133                        return (NULL);
134                }
135#if 0   /* XXX do we need this? */
136                tv.tv_sec = 25;
137                tv.tv_usec = 0;
138                clnt_control(client, CLSET_TIMEOUT, &tv);
139#endif
140                break;
141        default:
142                rpc_createerr.cf_stat = RPC_SYSTEMERROR;
143                rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
144                return (NULL);
145        }
146        return (client);
147}
Note: See TracBrowser for help on using the repository browser.