source: rtems/c/src/librpc/src/rpc/clnt_generic.c @ 1d89b75c

Last change on this file since 1d89b75c was 1d89b75c, checked in by Joel Sherrill <joel.sherrill@…>, on 05/28/00 at 17:47:39

Removed more warnings. In particular added ifdef's on IPV6 for
variables only used in IPV6.

  • 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#include <rpc/rpc.h>
40#include <sys/socket.h>
41#include <sys/errno.h>
42#include <netdb.h>
43#include <string.h>
44
45/*
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.
49 */
50CLIENT *
51clnt_create(hostname, prog, vers, proto)
52        char *hostname;
53        u_long prog;
54        u_long vers;
55        char *proto;
56{
57        struct hostent *h;
58        struct protoent *p;
59        struct sockaddr_in sin;
60#ifndef __rtems__
61        struct sockaddr_un sun;
62#endif
63        int sock;
64        struct timeval tv;
65        CLIENT *client;
66
67#ifndef __rtems__
68        if (!strcmp(proto, "unix")) {
69                bzero((char *)&sun, sizeof(sun));
70                sun.sun_family = AF_UNIX;
71                strcpy(sun.sun_path, hostname);
72                sun.sun_len = sizeof(sun.sun_len) + sizeof(sun.sun_family) +
73                                strlen(sun.sun_path) + 1;
74                sock = RPC_ANYSOCK;
75                client = clntunix_create(&sun, prog, vers, &sock, 0, 0);
76                if (client == NULL)
77                        return(NULL);
78                tv.tv_sec = 25;
79                tv.tv_usec = 0;
80                clnt_control(client, CLSET_TIMEOUT, &tv);
81                return(client);
82        }
83#endif
84
85        h = gethostbyname(hostname);
86        if (h == NULL) {
87                rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
88                return (NULL);
89        }
90        if (h->h_addrtype != AF_INET) {
91                /*
92                 * Only support INET for now
93                 */
94                rpc_createerr.cf_stat = RPC_SYSTEMERROR;
95                rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
96                return (NULL);
97        }
98        memset(&sin, 0, sizeof(sin));
99        sin.sin_len = sizeof(struct sockaddr_in);
100        sin.sin_family = h->h_addrtype;
101        sin.sin_port = 0;
102        memcpy((char*)&sin.sin_addr, h->h_addr, h->h_length);
103        p = getprotobyname(proto);
104        if (p == NULL) {
105                rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
106                rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
107                return (NULL);
108        }
109        sock = RPC_ANYSOCK;
110        switch (p->p_proto) {
111        case IPPROTO_UDP:
112                tv.tv_sec = 5;
113                tv.tv_usec = 0;
114                client = clntudp_create(&sin, prog, vers, tv, &sock);
115                if (client == NULL) {
116                        return (NULL);
117                }
118#if 0   /* XXX do we need this? */
119                tv.tv_sec = 25;
120                tv.tv_usec = 0;
121                clnt_control(client, CLSET_TIMEOUT, &tv);
122#endif
123                break;
124        case IPPROTO_TCP:
125                client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
126                if (client == NULL) {
127                        return (NULL);
128                }
129#if 0   /* XXX do we need this? */
130                tv.tv_sec = 25;
131                tv.tv_usec = 0;
132                clnt_control(client, CLSET_TIMEOUT, &tv);
133#endif
134                break;
135        default:
136                rpc_createerr.cf_stat = RPC_SYSTEMERROR;
137                rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
138                return (NULL);
139        }
140        return (client);
141}
Note: See TracBrowser for help on using the repository browser.