|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* Copyright (c) 2010, Oracle America, Inc.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
6c4009 |
* modification, are permitted provided that the following conditions are
|
|
Packit |
6c4009 |
* met:
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* * Redistributions of source code must retain the above copyright
|
|
Packit |
6c4009 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
6c4009 |
* * Redistributions in binary form must reproduce the above
|
|
Packit |
6c4009 |
* copyright notice, this list of conditions and the following
|
|
Packit |
6c4009 |
* disclaimer in the documentation and/or other materials
|
|
Packit |
6c4009 |
* provided with the distribution.
|
|
Packit |
6c4009 |
* * Neither the name of the "Oracle America, Inc." nor the names of its
|
|
Packit |
6c4009 |
* contributors may be used to endorse or promote products derived
|
|
Packit |
6c4009 |
* from this software without specific prior written permission.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
6c4009 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
6c4009 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit |
6c4009 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit |
6c4009 |
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
Packit |
6c4009 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
6c4009 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
Packit |
6c4009 |
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
6c4009 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
Packit |
6c4009 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
Packit |
6c4009 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
6c4009 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <alloca.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <rpc/rpc.h>
|
|
Packit |
6c4009 |
#include <sys/socket.h>
|
|
Packit |
6c4009 |
#include <netdb.h>
|
|
Packit |
6c4009 |
#include <shlib-compat.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* Generic client creation: takes (hostname, program-number, protocol) and
|
|
Packit |
6c4009 |
* returns client handle. Default options are set, which the user can
|
|
Packit |
6c4009 |
* change using the rpc equivalent of ioctl()'s.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
CLIENT *
|
|
Packit |
6c4009 |
clnt_create (const char *hostname, u_long prog, u_long vers,
|
|
Packit |
6c4009 |
const char *proto)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct protoent protobuf, *p;
|
|
Packit |
6c4009 |
size_t prtbuflen;
|
|
Packit |
6c4009 |
char *prttmpbuf;
|
|
Packit |
6c4009 |
struct sockaddr_in sin;
|
|
Packit |
6c4009 |
struct sockaddr_un sun;
|
|
Packit |
6c4009 |
int sock;
|
|
Packit |
6c4009 |
struct timeval tv;
|
|
Packit |
6c4009 |
CLIENT *client;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (strcmp (proto, "unix") == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
memset ((char *)&sun, 0, sizeof (sun));
|
|
Packit |
6c4009 |
sun.sun_family = AF_UNIX;
|
|
Packit |
6c4009 |
strcpy (sun.sun_path, hostname);
|
|
Packit |
6c4009 |
sock = RPC_ANYSOCK;
|
|
Packit |
6c4009 |
client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
|
|
Packit |
6c4009 |
if (client == NULL)
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
#if 0
|
|
Packit |
6c4009 |
/* This is not wanted. This would disable the user from having
|
|
Packit |
6c4009 |
a timeout in the clnt_call() call. Only a call to cnlt_control()
|
|
Packit |
6c4009 |
by the user should set the timeout value. */
|
|
Packit |
6c4009 |
tv.tv_sec = 25;
|
|
Packit |
6c4009 |
tv.tv_usec = 0;
|
|
Packit |
6c4009 |
clnt_control (client, CLSET_TIMEOUT, (char *)&tv;;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
return client;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (__libc_rpc_gethostbyname (hostname, &sin) != 0)
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
prtbuflen = 1024;
|
|
Packit |
6c4009 |
prttmpbuf = __alloca (prtbuflen);
|
|
Packit |
6c4009 |
while (__getprotobyname_r (proto, &protobuf, prttmpbuf, prtbuflen, &p) != 0
|
|
Packit |
6c4009 |
|| p == NULL)
|
|
Packit |
6c4009 |
if (errno != ERANGE)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct rpc_createerr *ce = &get_rpc_createerr ();
|
|
Packit |
6c4009 |
ce->cf_stat = RPC_UNKNOWNPROTO;
|
|
Packit |
6c4009 |
ce->cf_error.re_errno = EPFNOSUPPORT;
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Enlarge the buffer. */
|
|
Packit |
6c4009 |
prtbuflen *= 2;
|
|
Packit |
6c4009 |
prttmpbuf = __alloca (prtbuflen);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sock = RPC_ANYSOCK;
|
|
Packit |
6c4009 |
switch (p->p_proto)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
case IPPROTO_UDP:
|
|
Packit |
6c4009 |
tv.tv_sec = 5;
|
|
Packit |
6c4009 |
tv.tv_usec = 0;
|
|
Packit |
6c4009 |
client = clntudp_create (&sin, prog, vers, tv, &sock);
|
|
Packit |
6c4009 |
if (client == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#if 0
|
|
Packit |
6c4009 |
/* This is not wanted. This would disable the user from having
|
|
Packit |
6c4009 |
a timeout in the clnt_call() call. Only a call to cnlt_control()
|
|
Packit |
6c4009 |
by the user should set the timeout value. */
|
|
Packit |
6c4009 |
tv.tv_sec = 25;
|
|
Packit |
6c4009 |
clnt_control (client, CLSET_TIMEOUT, (char *)&tv;;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
case IPPROTO_TCP:
|
|
Packit |
6c4009 |
client = clnttcp_create (&sin, prog, vers, &sock, 0, 0);
|
|
Packit |
6c4009 |
if (client == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return NULL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#if 0
|
|
Packit |
6c4009 |
/* This is not wanted. This would disable the user from having
|
|
Packit |
6c4009 |
a timeout in the clnt_call() call. Only a call to cnlt_control()
|
|
Packit |
6c4009 |
by the user should set the timeout value. */
|
|
Packit |
6c4009 |
tv.tv_sec = 25;
|
|
Packit |
6c4009 |
tv.tv_usec = 0;
|
|
Packit |
6c4009 |
clnt_control (client, CLSET_TIMEOUT, (char *)&tv;;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
break;
|
|
Packit |
6c4009 |
default:
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct rpc_createerr *ce = &get_rpc_createerr ();
|
|
Packit |
6c4009 |
ce->cf_stat = RPC_SYSTEMERROR;
|
|
Packit |
6c4009 |
ce->cf_error.re_errno = EPFNOSUPPORT;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return (NULL);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return client;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#ifdef EXPORT_RPC_SYMBOLS
|
|
Packit |
6c4009 |
libc_hidden_def (clnt_create)
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
libc_hidden_nolink_sunrpc (clnt_create, GLIBC_2_0)
|
|
Packit |
6c4009 |
#endif
|