Blame sunrpc/clnt_gen.c

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