2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include "mt.h"
2N/A#include <sys/types.h>
2N/A#include <string.h>
2N/A#include <stdio.h>
2N/A#include <netconfig.h>
2N/A#include <netdir.h>
2N/A#include <rpc/rpc.h>
2N/A
2N/Astatic CLIENT *
2N/A__yp_clnt_create_rsvdport_netid_req(const char *hostname, rpcprog_t prog,
2N/A rpcvers_t vers, const char *nettype,
2N/A const uint_t sendsz, const uint_t recvsz)
2N/A{
2N/A struct netconfig *nconf;
2N/A struct netbuf *svcaddr;
2N/A struct t_bind *tbind;
2N/A CLIENT *clnt = NULL;
2N/A int fd;
2N/A const char *nt;
2N/A
2N/A if (nettype == NULL)
2N/A return (0);
2N/A else
2N/A nt = nettype;
2N/A
2N/A if (strcmp(nt, "udp") && strcmp(nt, "tcp") &&
2N/A strcmp(nt, "udp6") && strcmp(nt, "tcp6"))
2N/A return (clnt_create(hostname, prog, vers, nt));
2N/A
2N/A if ((nconf = getnetconfigent((void *) nt)) == NULL)
2N/A return (NULL);
2N/A
2N/A if ((fd = t_open(nconf->nc_device, O_RDWR, NULL)) == -1) {
2N/A freenetconfigent(nconf);
2N/A return (NULL);
2N/A }
2N/A
2N/A /* Attempt to set reserved port, but we don't care if it fails */
2N/A (void) netdir_options(nconf, ND_SET_RESERVEDPORT, fd, NULL);
2N/A
2N/A if ((tbind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == NULL) {
2N/A freenetconfigent(nconf);
2N/A return (NULL);
2N/A }
2N/A
2N/A svcaddr = &(tbind->addr);
2N/A
2N/A if (!rpcb_getaddr(prog, vers, nconf, svcaddr, hostname)) {
2N/A (void) t_close(fd);
2N/A (void) t_free((char *)tbind, T_BIND);
2N/A freenetconfigent(nconf);
2N/A return (NULL);
2N/A }
2N/A
2N/A if ((clnt = clnt_tli_create(fd, nconf, svcaddr,
2N/A prog, vers, sendsz, recvsz)) == NULL) {
2N/A (void) t_close(fd);
2N/A (void) t_free((char *)tbind, T_BIND);
2N/A } else {
2N/A (void) t_free((char *)tbind, T_BIND);
2N/A clnt_control(clnt, CLSET_FD_CLOSE, NULL);
2N/A }
2N/A freenetconfigent(nconf);
2N/A return (clnt);
2N/A}
2N/A
2N/A
2N/ACLIENT *
2N/A__yp_clnt_create_rsvdport(const char *hostname, rpcprog_t prog,
2N/A rpcvers_t vers, const char *nettype,
2N/A const uint_t sendsz, const uint_t recvsz)
2N/A{
2N/A if (nettype == 0) {
2N/A CLIENT *ret;
2N/A ret = __yp_clnt_create_rsvdport_netid_req(hostname, prog,
2N/A vers, "udp6", sendsz, recvsz);
2N/A if (ret == 0)
2N/A ret = __yp_clnt_create_rsvdport_netid_req(hostname,
2N/A prog, vers, "udp", sendsz, recvsz);
2N/A return (ret);
2N/A } else {
2N/A return (__yp_clnt_create_rsvdport_netid_req(hostname, prog,
2N/A vers, nettype,
2N/A sendsz, recvsz));
2N/A }
2N/A}