xref: /titanic_41/usr/src/lib/nsswitch/files/common/gethostent6.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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 1988-1995, 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  *	files/gethostent6.c -- "files" backend for nsswitch "hosts" database
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <netdb.h>
32 #include "files_common.h"
33 #include <string.h>
34 #include <strings.h>
35 #include <stddef.h>
36 #include <stdlib.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/nameser.h>
41 #include <ctype.h>
42 
43 extern nss_status_t __nss_files_XY_hostbyname();
44 extern int __nss_files_2herrno();
45 extern int __nss_files_check_addr(nss_XbyY_args_t *);
46 
47 
48 static nss_status_t
49 getbyname(be, a)
50 	files_backend_ptr_t	be;
51 	void			*a;
52 {
53 	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
54 	nss_status_t		res;
55 
56 	res = __nss_files_XY_hostbyname(be, argp, argp->key.ipnode.name,
57 							AF_INET6);
58 	if (res != NSS_SUCCESS)
59 		argp->h_errno = __nss_files_2herrno(res);
60 	return (res);
61 }
62 
63 
64 
65 static nss_status_t
66 getbyaddr(be, a)
67 	files_backend_ptr_t	be;
68 	void			*a;
69 {
70 	nss_XbyY_args_t		*argp	= (nss_XbyY_args_t *)a;
71 	nss_status_t		res;
72 
73 
74 	res = _nss_files_XY_all(be, argp, 1, 0, __nss_files_check_addr);
75 	if (res != NSS_SUCCESS)
76 		argp->h_errno = __nss_files_2herrno(res);
77 	return (res);
78 }
79 
80 
81 static files_backend_op_t ipnodes_ops[] = {
82 	_nss_files_destr,
83 	_nss_files_endent,
84 	_nss_files_setent,
85 	_nss_files_getent_netdb,
86 	getbyname,
87 	getbyaddr,
88 };
89 
90 /*ARGSUSED*/
91 nss_backend_t *
92 _nss_files_ipnodes_constr(dummy1, dummy2, dummy3)
93 	const char	*dummy1, *dummy2, *dummy3;
94 {
95 	return (_nss_files_constr(ipnodes_ops,
96 				sizeof (ipnodes_ops) / sizeof (ipnodes_ops[0]),
97 				_PATH_IPNODES,
98 				NSS_LINELEN_HOSTS,
99 				NULL));
100 }
101