17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
2261961e0fSrobinson
237c478bd9Sstevel@tonic-gate /*
24*e8031f0aSraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2561961e0fSrobinson * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
297c478bd9Sstevel@tonic-gate
30*e8031f0aSraf #include "mt.h"
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <netconfig.h>
357c478bd9Sstevel@tonic-gate #include <netdir.h>
367c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate static CLIENT *
__yp_clnt_create_rsvdport_netid_req(const char * hostname,rpcprog_t prog,rpcvers_t vers,const char * nettype,const uint_t sendsz,const uint_t recvsz)397c478bd9Sstevel@tonic-gate __yp_clnt_create_rsvdport_netid_req(const char *hostname, rpcprog_t prog,
407c478bd9Sstevel@tonic-gate rpcvers_t vers, const char *nettype,
417c478bd9Sstevel@tonic-gate const uint_t sendsz, const uint_t recvsz)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate struct netconfig *nconf;
447c478bd9Sstevel@tonic-gate struct netbuf *svcaddr;
457c478bd9Sstevel@tonic-gate struct t_bind *tbind;
467c478bd9Sstevel@tonic-gate CLIENT *clnt = NULL;
477c478bd9Sstevel@tonic-gate int fd;
487c478bd9Sstevel@tonic-gate const char *nt;
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate if (nettype == NULL)
517c478bd9Sstevel@tonic-gate return (0);
527c478bd9Sstevel@tonic-gate else
537c478bd9Sstevel@tonic-gate nt = nettype;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate if (strcmp(nt, "udp") && strcmp(nt, "tcp") &&
567c478bd9Sstevel@tonic-gate strcmp(nt, "udp6") && strcmp(nt, "tcp6"))
577c478bd9Sstevel@tonic-gate return (clnt_create(hostname, prog, vers, nt));
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent((void *) nt)) == NULL)
607c478bd9Sstevel@tonic-gate return (NULL);
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate if ((fd = t_open(nconf->nc_device, O_RDWR, NULL)) == -1) {
637c478bd9Sstevel@tonic-gate freenetconfigent(nconf);
647c478bd9Sstevel@tonic-gate return (NULL);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /* Attempt to set reserved port, but we don't care if it fails */
6861961e0fSrobinson (void) netdir_options(nconf, ND_SET_RESERVEDPORT, fd, NULL);
697c478bd9Sstevel@tonic-gate
7061961e0fSrobinson /* LINTED pointer cast */
717c478bd9Sstevel@tonic-gate if ((tbind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == NULL) {
727c478bd9Sstevel@tonic-gate freenetconfigent(nconf);
737c478bd9Sstevel@tonic-gate return (NULL);
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate svcaddr = &(tbind->addr);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate if (!rpcb_getaddr(prog, vers, nconf, svcaddr, hostname)) {
7961961e0fSrobinson (void) t_close(fd);
8061961e0fSrobinson (void) t_free((char *)tbind, T_BIND);
817c478bd9Sstevel@tonic-gate freenetconfigent(nconf);
827c478bd9Sstevel@tonic-gate return (NULL);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate if ((clnt = clnt_tli_create(fd, nconf, svcaddr,
867c478bd9Sstevel@tonic-gate prog, vers, sendsz, recvsz)) == NULL) {
8761961e0fSrobinson (void) t_close(fd);
8861961e0fSrobinson (void) t_free((char *)tbind, T_BIND);
897c478bd9Sstevel@tonic-gate } else {
9061961e0fSrobinson (void) t_free((char *)tbind, T_BIND);
917c478bd9Sstevel@tonic-gate clnt_control(clnt, CLSET_FD_CLOSE, NULL);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate freenetconfigent(nconf);
947c478bd9Sstevel@tonic-gate return (clnt);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate CLIENT *
__yp_clnt_create_rsvdport(const char * hostname,rpcprog_t prog,rpcvers_t vers,const char * nettype,const uint_t sendsz,const uint_t recvsz)997c478bd9Sstevel@tonic-gate __yp_clnt_create_rsvdport(const char *hostname, rpcprog_t prog,
1007c478bd9Sstevel@tonic-gate rpcvers_t vers, const char *nettype,
1017c478bd9Sstevel@tonic-gate const uint_t sendsz, const uint_t recvsz)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate if (nettype == 0) {
1047c478bd9Sstevel@tonic-gate CLIENT *ret;
1057c478bd9Sstevel@tonic-gate ret = __yp_clnt_create_rsvdport_netid_req(hostname, prog,
1067c478bd9Sstevel@tonic-gate vers, "udp6", sendsz, recvsz);
1077c478bd9Sstevel@tonic-gate if (ret == 0)
1087c478bd9Sstevel@tonic-gate ret = __yp_clnt_create_rsvdport_netid_req(hostname,
1097c478bd9Sstevel@tonic-gate prog, vers, "udp", sendsz, recvsz);
1107c478bd9Sstevel@tonic-gate return (ret);
1117c478bd9Sstevel@tonic-gate } else {
1127c478bd9Sstevel@tonic-gate return (__yp_clnt_create_rsvdport_netid_req(hostname, prog,
1137c478bd9Sstevel@tonic-gate vers, nettype,
1147c478bd9Sstevel@tonic-gate sendsz, recvsz));
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate }
117