OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [clnt_generic.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
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
 * Copyright (C) 1987, Sun Microsystems, Inc.
31
 */
32
 
33
#define __FORCE_GLIBC
34
#include <features.h>
35
 
36
#include <alloca.h>
37
#include <errno.h>
38
#include <string.h>
39
#include <rpc/rpc.h>
40
#include <sys/socket.h>
41
#include <sys/errno.h>
42
#include <netdb.h>
43
 
44
/*
45
 * Generic client creation: takes (hostname, program-number, protocol) and
46
 * returns client handle. Default options are set, which the user can
47
 * change using the rpc equivalent of ioctl()'s.
48
 */
49
CLIENT *
50
clnt_create (const char *hostname, u_long prog, u_long vers,
51
             const char *proto)
52
{
53
  struct hostent hostbuf, *h;
54
  size_t hstbuflen;
55
  char *hsttmpbuf;
56
  struct protoent *p;
57
  struct sockaddr_in sin;
58
  struct sockaddr_un sun;
59
  int sock;
60
  struct timeval tv;
61
  CLIENT *client;
62
  int herr;
63
 
64
  if (strcmp (proto, "unix") == 0)
65
    {
66
      bzero ((char *)&sun, sizeof (sun));
67
      sun.sun_family = AF_UNIX;
68
      strcpy (sun.sun_path, hostname);
69
      sock = RPC_ANYSOCK;
70
      client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
71
      if (client == NULL)
72
        return NULL;
73
#if 0
74
      /* This is not wanted.  This would disable the user from having
75
         a timeout in the clnt_call() call.  Only a call to cnlt_control()
76
         by the user should set the timeout value.  */
77
      tv.tv_sec = 25;
78
      tv.tv_usec = 0;
79
      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
80
#endif
81
      return client;
82
    }
83
 
84
  hstbuflen = 1024;
85
  hsttmpbuf = alloca (hstbuflen);
86
  while (gethostbyname_r (hostname, &hostbuf, hsttmpbuf, hstbuflen,
87
                            &h, &herr) != 0
88
         || h == NULL)
89
    if (herr != NETDB_INTERNAL || errno != ERANGE)
90
      {
91
        get_rpc_createerr().cf_stat = RPC_UNKNOWNHOST;
92
        return NULL;
93
      }
94
    else
95
      {
96
        /* Enlarge the buffer.  */
97
        hstbuflen *= 2;
98
        hsttmpbuf = alloca (hstbuflen);
99
      }
100
 
101
  if (h->h_addrtype != AF_INET)
102
    {
103
      /*
104
       * Only support INET for now
105
       */
106
      struct rpc_createerr *ce = &get_rpc_createerr ();
107
      ce->cf_stat = RPC_SYSTEMERROR;
108
      ce->cf_error.re_errno = EAFNOSUPPORT;
109
      return NULL;
110
    }
111
  sin.sin_family = h->h_addrtype;
112
  sin.sin_port = 0;
113
  bzero (sin.sin_zero, sizeof (sin.sin_zero));
114
  memcpy ((char *) &sin.sin_addr, h->h_addr, h->h_length);
115
 
116
#warning getprotobyname is not reentrant...  Add getprotobyname_r
117
  p = getprotobyname(proto);
118
  if (p == NULL) {
119
      struct rpc_createerr *ce = &get_rpc_createerr ();
120
      ce->cf_stat = RPC_UNKNOWNPROTO;
121
      ce->cf_error.re_errno = EPFNOSUPPORT;
122
      return NULL;
123
  }
124
 
125
  sock = RPC_ANYSOCK;
126
  switch (p->p_proto)
127
    {
128
    case IPPROTO_UDP:
129
      tv.tv_sec = 5;
130
      tv.tv_usec = 0;
131
      client = clntudp_create (&sin, prog, vers, tv, &sock);
132
      if (client == NULL)
133
        {
134
          return NULL;
135
        }
136
#if 0
137
      /* This is not wanted.  This would disable the user from having
138
         a timeout in the clnt_call() call.  Only a call to cnlt_control()
139
         by the user should set the timeout value.  */
140
      tv.tv_sec = 25;
141
      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
142
#endif
143
      break;
144
    case IPPROTO_TCP:
145
      client = clnttcp_create (&sin, prog, vers, &sock, 0, 0);
146
      if (client == NULL)
147
        {
148
          return NULL;
149
        }
150
#if 0
151
      /* This is not wanted.  This would disable the user from having
152
         a timeout in the clnt_call() call.  Only a call to cnlt_control()
153
         by the user should set the timeout value.  */
154
      tv.tv_sec = 25;
155
      tv.tv_usec = 0;
156
      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
157
#endif
158
      break;
159
    default:
160
      {
161
        struct rpc_createerr *ce = &get_rpc_createerr ();
162
        ce->cf_stat = RPC_SYSTEMERROR;
163
        ce->cf_error.re_errno = EPFNOSUPPORT;
164
      }
165
      return (NULL);
166
    }
167
  return client;
168
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.