1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1995-1999 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <string.h> 31 #include <stdio.h> 32 #include <netconfig.h> 33 #include <netdir.h> 34 #include <rpc/rpc.h> 35 36 static CLIENT * 37 __yp_clnt_create_rsvdport_netid_req(const char *hostname, rpcprog_t prog, 38 rpcvers_t vers, const char *nettype, 39 const uint_t sendsz, const uint_t recvsz) 40 { 41 struct netconfig *nconf; 42 struct netbuf *svcaddr; 43 struct t_bind *tbind; 44 CLIENT *clnt = NULL; 45 int fd; 46 const char *nt; 47 48 if (nettype == NULL) 49 return (0); 50 else 51 nt = nettype; 52 53 if (strcmp(nt, "udp") && strcmp(nt, "tcp") && 54 strcmp(nt, "udp6") && strcmp(nt, "tcp6")) 55 return (clnt_create(hostname, prog, vers, nt)); 56 57 if ((nconf = getnetconfigent((void *) nt)) == NULL) 58 return (NULL); 59 60 if ((fd = t_open(nconf->nc_device, O_RDWR, NULL)) == -1) { 61 freenetconfigent(nconf); 62 return (NULL); 63 } 64 65 /* Attempt to set reserved port, but we don't care if it fails */ 66 netdir_options(nconf, ND_SET_RESERVEDPORT, fd, NULL); 67 68 if ((tbind = (struct t_bind *) t_alloc(fd, T_BIND, T_ADDR)) == NULL) { 69 freenetconfigent(nconf); 70 return (NULL); 71 } 72 73 svcaddr = &(tbind->addr); 74 75 if (!rpcb_getaddr(prog, vers, nconf, svcaddr, hostname)) { 76 t_close(fd); 77 t_free((char *) tbind, T_BIND); 78 freenetconfigent(nconf); 79 return (NULL); 80 } 81 82 if ((clnt = clnt_tli_create(fd, nconf, svcaddr, 83 prog, vers, sendsz, recvsz)) == NULL) { 84 t_close(fd); 85 t_free((char *) tbind, T_BIND); 86 } else { 87 t_free((char *) tbind, T_BIND); 88 clnt_control(clnt, CLSET_FD_CLOSE, NULL); 89 } 90 freenetconfigent(nconf); 91 return (clnt); 92 } 93 94 95 CLIENT * 96 __yp_clnt_create_rsvdport(const char *hostname, rpcprog_t prog, 97 rpcvers_t vers, const char *nettype, 98 const uint_t sendsz, const uint_t recvsz) 99 { 100 if (nettype == 0) { 101 CLIENT *ret; 102 ret = __yp_clnt_create_rsvdport_netid_req(hostname, prog, 103 vers, "udp6", sendsz, recvsz); 104 if (ret == 0) 105 ret = __yp_clnt_create_rsvdport_netid_req(hostname, 106 prog, vers, "udp", sendsz, recvsz); 107 return (ret); 108 } else { 109 return (__yp_clnt_create_rsvdport_netid_req(hostname, prog, 110 vers, nettype, 111 sendsz, recvsz)); 112 } 113 } 114