xref: /onnv-gate/usr/src/lib/libnsl/nss/gethostent6.c (revision 1219:f89f56c2d9ac)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22132Srobinson 
230Sstevel@tonic-gate /*
24*1219Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
26*1219Sraf  */
27*1219Sraf 
28*1219Sraf /*
290Sstevel@tonic-gate  * This file defines and implements the re-entrant enumeration routines for
300Sstevel@tonic-gate  *   IPv6 hosts: sethostent6(), gethostent6(), and endhostent6().
310Sstevel@tonic-gate  *   They consult the switch policy directly and do not "share" their
320Sstevel@tonic-gate  *   enumeration state nor the stayopen flag with the implentation of the
330Sstevel@tonic-gate  *   more commonly used getipnodebyname()/getipnodebyaddr(). The latter
340Sstevel@tonic-gate  *   follows a tortuous route in order to be consistent with netdir_getbyYY()
350Sstevel@tonic-gate  *   (see getipnodebyname.c and netdir_inet.c).
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
390Sstevel@tonic-gate 
40*1219Sraf #include "mt.h"
410Sstevel@tonic-gate #include <sys/socket.h>
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <nss_dbdefs.h>
440Sstevel@tonic-gate #include "nss.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate static int ipnodes_stayopen;
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * Unsynchronized, but it affects only
490Sstevel@tonic-gate  * efficiency, not correctness
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
530Sstevel@tonic-gate static DEFINE_NSS_GETENT(context);
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /* IPv6 wrapper for __str2hostent() */
560Sstevel@tonic-gate int
str2hostent6(const char * instr,int lenstr,void * ent,char * buffer,int buflen)570Sstevel@tonic-gate str2hostent6(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	return (__str2hostent(AF_INET6, instr, lenstr, ent, buffer, buflen));
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate void
_nss_initf_ipnodes(nss_db_params_t * p)630Sstevel@tonic-gate _nss_initf_ipnodes(nss_db_params_t *p)
640Sstevel@tonic-gate {
650Sstevel@tonic-gate 	p->name	= NSS_DBNAM_IPNODES;
660Sstevel@tonic-gate 	p->default_config = NSS_DEFCONF_IPNODES;
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate int
__sethostent6(int stay)700Sstevel@tonic-gate __sethostent6(int stay)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	ipnodes_stayopen |= stay;
730Sstevel@tonic-gate 	nss_setent(&db_root, _nss_initf_ipnodes, &context);
740Sstevel@tonic-gate 	return (0);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate 
770Sstevel@tonic-gate int
__endhostent6(void)780Sstevel@tonic-gate __endhostent6(void)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate 	ipnodes_stayopen = 0;
810Sstevel@tonic-gate 	nss_endent(&db_root, _nss_initf_ipnodes, &context);
820Sstevel@tonic-gate 	nss_delete(&db_root);
830Sstevel@tonic-gate 	return (0);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate struct hostent *
__gethostent6(struct hostent * result,char * buffer,int buflen,int * h_errnop)870Sstevel@tonic-gate __gethostent6(struct hostent *result, char *buffer, int buflen, int *h_errnop)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 	nss_XbyY_args_t arg;
900Sstevel@tonic-gate 	nss_status_t	res;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2hostent6);
930Sstevel@tonic-gate 	res = nss_getent(&db_root, _nss_initf_ipnodes,
940Sstevel@tonic-gate 	    &context, &arg);
950Sstevel@tonic-gate 	arg.status = res;
960Sstevel@tonic-gate 	*h_errnop = arg.h_errno;
970Sstevel@tonic-gate 	return ((struct hostent *)NSS_XbyY_FINI(&arg));
980Sstevel@tonic-gate }
99