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 1991-2002 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * lib/libnsl/nss/gethostent6.c 27 * 28 * This file defines and implements the re-entrant enumeration routines for 29 * IPv6 hosts: sethostent6(), gethostent6(), and endhostent6(). 30 * They consult the switch policy directly and do not "share" their 31 * enumeration state nor the stayopen flag with the implentation of the 32 * more commonly used getipnodebyname()/getipnodebyaddr(). The latter 33 * follows a tortuous route in order to be consistent with netdir_getbyYY() 34 * (see getipnodebyname.c and netdir_inet.c). 35 */ 36 37 #pragma ident "%Z%%M% %I% %E% SMI" 38 39 #include <sys/socket.h> 40 #include <sys/types.h> 41 #include <nss_dbdefs.h> 42 #include <rpc/trace.h> 43 #include "nss.h" 44 45 static int ipnodes_stayopen; 46 /* 47 * Unsynchronized, but it affects only 48 * efficiency, not correctness 49 */ 50 51 static DEFINE_NSS_DB_ROOT(db_root); 52 static DEFINE_NSS_GETENT(context); 53 54 /* IPv6 wrapper for __str2hostent() */ 55 int 56 str2hostent6(const char *instr, int lenstr, void *ent, char *buffer, int buflen) 57 { 58 return (__str2hostent(AF_INET6, instr, lenstr, ent, buffer, buflen)); 59 } 60 61 void 62 _nss_initf_ipnodes(nss_db_params_t *p) 63 { 64 trace1(TR__nss_initf_ipnodes, 0); 65 p->name = NSS_DBNAM_IPNODES; 66 p->default_config = NSS_DEFCONF_IPNODES; 67 trace1(TR__nss_initf_ipnodes, 1); 68 } 69 70 int 71 __sethostent6(int stay) 72 { 73 trace1(TR_sethostent6, 0); 74 ipnodes_stayopen |= stay; 75 nss_setent(&db_root, _nss_initf_ipnodes, &context); 76 trace1(TR_sethostent6, 1); 77 return (0); 78 } 79 80 int 81 __endhostent6(void) 82 { 83 trace1(TR_endhostent6, 0); 84 ipnodes_stayopen = 0; 85 nss_endent(&db_root, _nss_initf_ipnodes, &context); 86 nss_delete(&db_root); 87 trace1(TR_endhostent6, 1); 88 return (0); 89 } 90 91 struct hostent * 92 __gethostent6(struct hostent *result, char *buffer, int buflen, int *h_errnop) 93 { 94 nss_XbyY_args_t arg; 95 nss_status_t res; 96 97 trace2(TR_gethostent6, 0, buflen); 98 NSS_XbyY_INIT(&arg, result, buffer, buflen, str2hostent6); 99 res = nss_getent(&db_root, _nss_initf_ipnodes, 100 &context, &arg); 101 arg.status = res; 102 *h_errnop = arg.h_errno; 103 trace2(TR_gethostent6, 1, buflen); 104 return ((struct hostent *)NSS_XbyY_FINI(&arg)); 105 } 106