4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * gethostbyname_r() is defined in this file. It is implemented on top of
31 * _get_hostserv_inetnetdir_byname() which is also used to implement
32 * netdir_getbyname() for inet family transports. In turn the common code
33 * uses the name service switch policy for "hosts" and "services" unless
34 * the administrator chooses to bypass the name service switch by
35 * specifying third-party supplied nametoaddr libs for inet transports
38 * gethostbyaddr_r() is similarly related to _get_hostserv_inetnetdir_byaddr()
39 * and netdir_getbyaddr();
41 * The common code lives in netdir_inet.c.
43 * gethostent_r(), sethostent() and endhostent() are *not* implemented on top
44 * of the common interface; they go straight to the switch and are
45 * defined in gethostent_r.c.
47 * There is absolutely no data sharing, not even the stayopen flag or
48 * enumeration state, between gethostbyYY_r() and gethostent_r();
54 #include <sys/types.h>
55 #include <nss_netdir.h>
58 extern struct netconfig
*__rpc_getconfip();
61 * h_errno POLICY: The frontends expect the name service
62 * backends to modify the h_errno in "arg"; _switch_gethostbyYY_r()
63 * will copy that over onto user's h_errnop pointer. This h_errno is
64 * never used for "switching" -- status from nss_search serves
65 * the purpose. There is no explicit zeroing in the case of success.
68 extern struct hostent
*
69 _switch_gethostbyname_r(const char *nam
, struct hostent
*result
, char *buffer
,
70 int buflen
, int *h_errnop
);
72 extern struct hostent
*
73 _switch_gethostbyaddr_r(const char *addr
, int length
, int type
,
74 struct hostent
*result
, char *buffer
, int buflen
, int *h_errnop
);
78 _uncached_gethostbyname_r(const char *nam
, struct hostent
*result
,
79 char *buffer
, int buflen
, int *h_errnop
)
81 return (_switch_gethostbyname_r(nam
, result
,
82 buffer
, buflen
, h_errnop
));
86 _uncached_gethostbyaddr_r(const char *addr
, int length
, int type
,
87 struct hostent
*result
, char *buffer
, int buflen
, int *h_errnop
)
89 return (_switch_gethostbyaddr_r(addr
, length
, type
,
90 result
, buffer
, buflen
, h_errnop
));
95 extern struct hostent
*
96 gethostbyname_r(const char *nam
, struct hostent
*result
, char *buffer
,
97 int buflen
, int *h_errnop
);
99 extern struct hostent
*
100 gethostbyaddr_r(const char *addr
, int length
, int type
,
101 struct hostent
*result
, char *buffer
, int buflen
, int *h_errnop
);
104 gethostbyname_r(const char *nam
, struct hostent
*result
, char *buffer
,
105 int buflen
, int *h_errnop
)
107 struct netconfig
*nconf
;
108 struct nss_netdirbyname_in nssin
;
109 union nss_netdirbyname_out nssout
;
112 if (h_errnop
== NULL
)
115 if (strlen(nam
) == 0) {
116 *h_errnop
= HOST_NOT_FOUND
;
120 if ((nconf
= __rpc_getconfip("udp")) == NULL
&&
121 (nconf
= __rpc_getconfip("tcp")) == NULL
) {
122 *h_errnop
= NO_RECOVERY
;
126 nssin
.op_t
= NSS_HOST
;
127 nssin
.arg
.nss
.host
.name
= nam
;
128 nssin
.arg
.nss
.host
.buf
= buffer
;
129 nssin
.arg
.nss
.host
.buflen
= buflen
;
131 nssout
.nss
.host
.hent
= result
;
132 nssout
.nss
.host
.herrno_p
= h_errnop
;
135 * We pass in nconf and let the implementation of the long-named func
136 * decide whether to use the switch based on nc_nlookups.
138 neterr
= _get_hostserv_inetnetdir_byname(nconf
, &nssin
, &nssout
);
140 (void) freenetconfigent(nconf
);
143 return (nssout
.nss
.host
.hent
);
147 gethostbyaddr_r(const char *addr
, int length
, int type
,
148 struct hostent
*result
, char *buffer
, int buflen
, int *h_errnop
)
150 struct netconfig
*nconf
;
151 struct nss_netdirbyaddr_in nssin
;
152 union nss_netdirbyaddr_out nssout
;
155 if (h_errnop
== NULL
)
158 if (type
!= AF_INET
) {
159 *h_errnop
= HOST_NOT_FOUND
;
163 if ((nconf
= __rpc_getconfip("udp")) == NULL
&&
164 (nconf
= __rpc_getconfip("tcp")) == NULL
) {
165 *h_errnop
= NO_RECOVERY
;
169 nssin
.op_t
= NSS_HOST
;
170 nssin
.arg
.nss
.host
.addr
= addr
;
171 nssin
.arg
.nss
.host
.len
= length
;
172 nssin
.arg
.nss
.host
.type
= type
;
173 nssin
.arg
.nss
.host
.buf
= buffer
;
174 nssin
.arg
.nss
.host
.buflen
= buflen
;
176 nssout
.nss
.host
.hent
= result
;
177 nssout
.nss
.host
.herrno_p
= h_errnop
;
180 * We pass in nconf and let the implementation of this long-named func
181 * decide whether to use the switch based on nc_nlookups.
183 neterr
= _get_hostserv_inetnetdir_byaddr(nconf
, &nssin
, &nssout
);
185 (void) freenetconfigent(nconf
);
188 return (nssout
.nss
.host
.hent
);