xref: /minix3/lib/libc/resolv/res_data.c (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras /*	$NetBSD: res_data.c,v 1.14 2009/10/24 05:35:37 christos Exp $	*/
2*2fe8fb19SBen Gras 
3*2fe8fb19SBen Gras /*
4*2fe8fb19SBen Gras  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5*2fe8fb19SBen Gras  * Copyright (c) 1995-1999 by Internet Software Consortium.
6*2fe8fb19SBen Gras  *
7*2fe8fb19SBen Gras  * Permission to use, copy, modify, and distribute this software for any
8*2fe8fb19SBen Gras  * purpose with or without fee is hereby granted, provided that the above
9*2fe8fb19SBen Gras  * copyright notice and this permission notice appear in all copies.
10*2fe8fb19SBen Gras  *
11*2fe8fb19SBen Gras  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12*2fe8fb19SBen Gras  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13*2fe8fb19SBen Gras  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
14*2fe8fb19SBen Gras  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15*2fe8fb19SBen Gras  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16*2fe8fb19SBen Gras  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17*2fe8fb19SBen Gras  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*2fe8fb19SBen Gras  */
19*2fe8fb19SBen Gras 
20*2fe8fb19SBen Gras #include <sys/cdefs.h>
21*2fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
22*2fe8fb19SBen Gras #ifdef notdef
23*2fe8fb19SBen Gras static const char rcsid[] = "Id: res_data.c,v 1.7 2008/12/11 09:59:00 marka Exp";
24*2fe8fb19SBen Gras #else
25*2fe8fb19SBen Gras __RCSID("$NetBSD: res_data.c,v 1.14 2009/10/24 05:35:37 christos Exp $");
26*2fe8fb19SBen Gras #endif
27*2fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
28*2fe8fb19SBen Gras 
29*2fe8fb19SBen Gras #include "port_before.h"
30*2fe8fb19SBen Gras 
31*2fe8fb19SBen Gras #include "namespace.h"
32*2fe8fb19SBen Gras #include <sys/types.h>
33*2fe8fb19SBen Gras #include <sys/param.h>
34*2fe8fb19SBen Gras #include <sys/socket.h>
35*2fe8fb19SBen Gras #include <sys/time.h>
36*2fe8fb19SBen Gras 
37*2fe8fb19SBen Gras #include <netinet/in.h>
38*2fe8fb19SBen Gras #include <arpa/inet.h>
39*2fe8fb19SBen Gras #include <arpa/nameser.h>
40*2fe8fb19SBen Gras 
41*2fe8fb19SBen Gras #include <ctype.h>
42*2fe8fb19SBen Gras #include <netdb.h>
43*2fe8fb19SBen Gras #include <resolv.h>
44*2fe8fb19SBen Gras #include <res_update.h>
45*2fe8fb19SBen Gras #include <stdio.h>
46*2fe8fb19SBen Gras #include <stdlib.h>
47*2fe8fb19SBen Gras #include <string.h>
48*2fe8fb19SBen Gras #include <unistd.h>
49*2fe8fb19SBen Gras 
50*2fe8fb19SBen Gras #include "port_after.h"
51*2fe8fb19SBen Gras 
52*2fe8fb19SBen Gras #include "res_private.h"
53*2fe8fb19SBen Gras 
54*2fe8fb19SBen Gras #ifdef __weak_alias
55*2fe8fb19SBen Gras __weak_alias(res_init,_res_init)
56*2fe8fb19SBen Gras __weak_alias(res_mkquery,_res_mkquery)
57*2fe8fb19SBen Gras __weak_alias(res_query,_res_query)
58*2fe8fb19SBen Gras __weak_alias(res_search,_res_search)
59*2fe8fb19SBen Gras __weak_alias(res_send,__res_send)
60*2fe8fb19SBen Gras __weak_alias(res_close,__res_close)
61*2fe8fb19SBen Gras /* XXX: these leaked in the old bind8 libc */
62*2fe8fb19SBen Gras __weak_alias(res_querydomain,__res_querydomain)
63*2fe8fb19SBen Gras __weak_alias(res_send_setqhook,__res_send_setqhook)
64*2fe8fb19SBen Gras __weak_alias(res_send_setrhook,__res_send_setrhook)
65*2fe8fb19SBen Gras #if 0
66*2fe8fb19SBen Gras __weak_alias(p_query,__p_query)
67*2fe8fb19SBen Gras __weak_alias(fp_query,__fp_query)
68*2fe8fb19SBen Gras __weak_alias(fp_nquery,__fp_nquery)
69*2fe8fb19SBen Gras __weak_alias(res_isourserver,__res_isourserver)
70*2fe8fb19SBen Gras __weak_alias(res_opt,_res_opt)
71*2fe8fb19SBen Gras __weak_alias(hostalias,__hostalias)
72*2fe8fb19SBen Gras #endif
73*2fe8fb19SBen Gras #endif
74*2fe8fb19SBen Gras 
75*2fe8fb19SBen Gras const char *_res_opcodes[] = {
76*2fe8fb19SBen Gras 	"QUERY",
77*2fe8fb19SBen Gras 	"IQUERY",
78*2fe8fb19SBen Gras 	"CQUERYM",
79*2fe8fb19SBen Gras 	"CQUERYU",	/*%< experimental */
80*2fe8fb19SBen Gras 	"NOTIFY",	/*%< experimental */
81*2fe8fb19SBen Gras 	"UPDATE",
82*2fe8fb19SBen Gras 	"6",
83*2fe8fb19SBen Gras 	"7",
84*2fe8fb19SBen Gras 	"8",
85*2fe8fb19SBen Gras 	"9",
86*2fe8fb19SBen Gras 	"10",
87*2fe8fb19SBen Gras 	"11",
88*2fe8fb19SBen Gras 	"12",
89*2fe8fb19SBen Gras 	"13",
90*2fe8fb19SBen Gras 	"ZONEINIT",
91*2fe8fb19SBen Gras 	"ZONEREF",
92*2fe8fb19SBen Gras };
93*2fe8fb19SBen Gras 
94*2fe8fb19SBen Gras #ifdef BIND_UPDATE
95*2fe8fb19SBen Gras const char *_res_sectioncodes[] = {
96*2fe8fb19SBen Gras 	"ZONE",
97*2fe8fb19SBen Gras 	"PREREQUISITES",
98*2fe8fb19SBen Gras 	"UPDATE",
99*2fe8fb19SBen Gras 	"ADDITIONAL",
100*2fe8fb19SBen Gras };
101*2fe8fb19SBen Gras #endif
102*2fe8fb19SBen Gras 
103*2fe8fb19SBen Gras #ifndef __BIND_NOSTATIC
104*2fe8fb19SBen Gras extern struct __res_state _nres;
105*2fe8fb19SBen Gras 
106*2fe8fb19SBen Gras /* Proto. */
107*2fe8fb19SBen Gras 
108*2fe8fb19SBen Gras int  res_ourserver_p(const res_state, const struct sockaddr *);
109*2fe8fb19SBen Gras 
110*2fe8fb19SBen Gras int
res_init(void)111*2fe8fb19SBen Gras res_init(void) {
112*2fe8fb19SBen Gras 	int rv;
113*2fe8fb19SBen Gras #ifdef COMPAT__RES
114*2fe8fb19SBen Gras 	/*
115*2fe8fb19SBen Gras 	 * Compatibility with program that were accessing _res directly
116*2fe8fb19SBen Gras 	 * to set options. We keep another struct res that is the same
117*2fe8fb19SBen Gras 	 * size as the original res structure, and then copy fields to
118*2fe8fb19SBen Gras 	 * it so that we achieve the same initialization
119*2fe8fb19SBen Gras 	 */
120*2fe8fb19SBen Gras 	extern void *__res_get_old_state(void);
121*2fe8fb19SBen Gras 	extern void __res_put_old_state(void *);
122*2fe8fb19SBen Gras 	res_state ores = __res_get_old_state();
123*2fe8fb19SBen Gras 
124*2fe8fb19SBen Gras 	if (ores->options != 0)
125*2fe8fb19SBen Gras 		_nres.options = ores->options;
126*2fe8fb19SBen Gras 	if (ores->retrans != 0)
127*2fe8fb19SBen Gras 		_nres.retrans = ores->retrans;
128*2fe8fb19SBen Gras 	if (ores->retry != 0)
129*2fe8fb19SBen Gras 		_nres.retry = ores->retry;
130*2fe8fb19SBen Gras #endif
131*2fe8fb19SBen Gras 
132*2fe8fb19SBen Gras 	/*
133*2fe8fb19SBen Gras 	 * These three fields used to be statically initialized.  This made
134*2fe8fb19SBen Gras 	 * it hard to use this code in a shared library.  It is necessary,
135*2fe8fb19SBen Gras 	 * now that we're doing dynamic initialization here, that we preserve
136*2fe8fb19SBen Gras 	 * the old semantics: if an application modifies one of these three
137*2fe8fb19SBen Gras 	 * fields of _res before res_init() is called, res_init() will not
138*2fe8fb19SBen Gras 	 * alter them.  Of course, if an application is setting them to
139*2fe8fb19SBen Gras 	 * _zero_ before calling res_init(), hoping to override what used
140*2fe8fb19SBen Gras 	 * to be the static default, we can't detect it and unexpected results
141*2fe8fb19SBen Gras 	 * will follow.  Zero for any of these fields would make no sense,
142*2fe8fb19SBen Gras 	 * so one can safely assume that the applications were already getting
143*2fe8fb19SBen Gras 	 * unexpected results.
144*2fe8fb19SBen Gras 	 *
145*2fe8fb19SBen Gras 	 * _nres.options is tricky since some apps were known to diddle the bits
146*2fe8fb19SBen Gras 	 * before res_init() was first called. We can't replicate that semantic
147*2fe8fb19SBen Gras 	 * with dynamic initialization (they may have turned bits off that are
148*2fe8fb19SBen Gras 	 * set in RES_DEFAULT).  Our solution is to declare such applications
149*2fe8fb19SBen Gras 	 * "broken".  They could fool us by setting RES_INIT but none do (yet).
150*2fe8fb19SBen Gras 	 */
151*2fe8fb19SBen Gras 	if (!_nres.retrans)
152*2fe8fb19SBen Gras 		_nres.retrans = RES_TIMEOUT;
153*2fe8fb19SBen Gras 	if (!_nres.retry)
154*2fe8fb19SBen Gras 		_nres.retry = 4;
155*2fe8fb19SBen Gras 	if (!(_nres.options & RES_INIT))
156*2fe8fb19SBen Gras 		_nres.options = RES_DEFAULT;
157*2fe8fb19SBen Gras 
158*2fe8fb19SBen Gras 	/*
159*2fe8fb19SBen Gras 	 * This one used to initialize implicitly to zero, so unless the app
160*2fe8fb19SBen Gras 	 * has set it to something in particular, we can randomize it now.
161*2fe8fb19SBen Gras 	 */
162*2fe8fb19SBen Gras 	if (!_nres.id)
163*2fe8fb19SBen Gras 		_nres.id = res_nrandomid(&_nres);
164*2fe8fb19SBen Gras 
165*2fe8fb19SBen Gras 	rv = __res_vinit(&_nres, 1);
166*2fe8fb19SBen Gras #ifdef COMPAT__RES
167*2fe8fb19SBen Gras 	__res_put_old_state(&_nres);
168*2fe8fb19SBen Gras #endif
169*2fe8fb19SBen Gras 	return rv;
170*2fe8fb19SBen Gras }
171*2fe8fb19SBen Gras 
172*2fe8fb19SBen Gras void
p_query(const u_char * msg)173*2fe8fb19SBen Gras p_query(const u_char *msg) {
174*2fe8fb19SBen Gras 	fp_query(msg, stdout);
175*2fe8fb19SBen Gras }
176*2fe8fb19SBen Gras 
177*2fe8fb19SBen Gras void
fp_query(const u_char * msg,FILE * file)178*2fe8fb19SBen Gras fp_query(const u_char *msg, FILE *file) {
179*2fe8fb19SBen Gras 	fp_nquery(msg, PACKETSZ, file);
180*2fe8fb19SBen Gras }
181*2fe8fb19SBen Gras 
182*2fe8fb19SBen Gras void
fp_nquery(const u_char * msg,int len,FILE * file)183*2fe8fb19SBen Gras fp_nquery(const u_char *msg, int len, FILE *file) {
184*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1)
185*2fe8fb19SBen Gras 		return;
186*2fe8fb19SBen Gras 
187*2fe8fb19SBen Gras 	res_pquery(&_nres, msg, len, file);
188*2fe8fb19SBen Gras }
189*2fe8fb19SBen Gras 
190*2fe8fb19SBen Gras int
res_mkquery(int op,const char * dname,int class,int type,const u_char * data,int datalen,const u_char * newrr_in,u_char * buf,int buflen)191*2fe8fb19SBen Gras res_mkquery(int op,			/*!< opcode of query  */
192*2fe8fb19SBen Gras 	    const char *dname,		/*!< domain name  */
193*2fe8fb19SBen Gras 	    int class, int type,	/*!< class and type of query  */
194*2fe8fb19SBen Gras 	    const u_char *data,		/*!< resource record data  */
195*2fe8fb19SBen Gras 	    int datalen,		/*!< length of data  */
196*2fe8fb19SBen Gras 	    const u_char *newrr_in,	/*!< new rr for modify or append  */
197*2fe8fb19SBen Gras 	    u_char *buf,		/*!< buffer to put query  */
198*2fe8fb19SBen Gras 	    int buflen)			/*!< size of buffer  */
199*2fe8fb19SBen Gras {
200*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
201*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
202*2fe8fb19SBen Gras 		return (-1);
203*2fe8fb19SBen Gras 	}
204*2fe8fb19SBen Gras 	return (res_nmkquery(&_nres, op, dname, class, type,
205*2fe8fb19SBen Gras 			     data, datalen,
206*2fe8fb19SBen Gras 			     newrr_in, buf, buflen));
207*2fe8fb19SBen Gras }
208*2fe8fb19SBen Gras 
209*2fe8fb19SBen Gras #ifdef _LIBRESOLV
210*2fe8fb19SBen Gras int
res_mkupdate(ns_updrec * rrecp_in,u_char * buf,int buflen)211*2fe8fb19SBen Gras res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
212*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
213*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
214*2fe8fb19SBen Gras 		return (-1);
215*2fe8fb19SBen Gras 	}
216*2fe8fb19SBen Gras 
217*2fe8fb19SBen Gras 	return (res_nmkupdate(&_nres, rrecp_in, buf, buflen));
218*2fe8fb19SBen Gras }
219*2fe8fb19SBen Gras #endif
220*2fe8fb19SBen Gras 
221*2fe8fb19SBen Gras int
res_query(const char * name,int class,int type,u_char * answer,int anslen)222*2fe8fb19SBen Gras res_query(const char *name,	/*!< domain name  */
223*2fe8fb19SBen Gras 	  int class, int type,	/*!< class and type of query  */
224*2fe8fb19SBen Gras 	  u_char *answer,	/*!< buffer to put answer  */
225*2fe8fb19SBen Gras 	  int anslen)		/*!< size of answer buffer  */
226*2fe8fb19SBen Gras {
227*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
228*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
229*2fe8fb19SBen Gras 		return (-1);
230*2fe8fb19SBen Gras 	}
231*2fe8fb19SBen Gras 	return (res_nquery(&_nres, name, class, type, answer, anslen));
232*2fe8fb19SBen Gras }
233*2fe8fb19SBen Gras 
234*2fe8fb19SBen Gras void
res_send_setqhook(res_send_qhook hook)235*2fe8fb19SBen Gras res_send_setqhook(res_send_qhook hook) {
236*2fe8fb19SBen Gras 	_nres.qhook = hook;
237*2fe8fb19SBen Gras }
238*2fe8fb19SBen Gras 
239*2fe8fb19SBen Gras void
res_send_setrhook(res_send_rhook hook)240*2fe8fb19SBen Gras res_send_setrhook(res_send_rhook hook) {
241*2fe8fb19SBen Gras 	_nres.rhook = hook;
242*2fe8fb19SBen Gras }
243*2fe8fb19SBen Gras 
244*2fe8fb19SBen Gras int
res_isourserver(const struct sockaddr_in * inp)245*2fe8fb19SBen Gras res_isourserver(const struct sockaddr_in *inp) {
246*2fe8fb19SBen Gras 	return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp));
247*2fe8fb19SBen Gras }
248*2fe8fb19SBen Gras 
249*2fe8fb19SBen Gras int
res_send(const u_char * buf,int buflen,u_char * ans,int anssiz)250*2fe8fb19SBen Gras res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
251*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
252*2fe8fb19SBen Gras 		/* errno should have been set by res_init() in this case. */
253*2fe8fb19SBen Gras 		return (-1);
254*2fe8fb19SBen Gras 	}
255*2fe8fb19SBen Gras 
256*2fe8fb19SBen Gras 	return (res_nsend(&_nres, buf, buflen, ans, anssiz));
257*2fe8fb19SBen Gras }
258*2fe8fb19SBen Gras 
259*2fe8fb19SBen Gras #ifdef _LIBRESOLV
260*2fe8fb19SBen Gras int
res_sendsigned(const u_char * buf,int buflen,ns_tsig_key * key,u_char * ans,int anssiz)261*2fe8fb19SBen Gras res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
262*2fe8fb19SBen Gras 	       u_char *ans, int anssiz)
263*2fe8fb19SBen Gras {
264*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
265*2fe8fb19SBen Gras 		/* errno should have been set by res_init() in this case. */
266*2fe8fb19SBen Gras 		return (-1);
267*2fe8fb19SBen Gras 	}
268*2fe8fb19SBen Gras 
269*2fe8fb19SBen Gras 	return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz));
270*2fe8fb19SBen Gras }
271*2fe8fb19SBen Gras #endif
272*2fe8fb19SBen Gras 
273*2fe8fb19SBen Gras void
res_close(void)274*2fe8fb19SBen Gras res_close(void) {
275*2fe8fb19SBen Gras 	res_nclose(&_nres);
276*2fe8fb19SBen Gras }
277*2fe8fb19SBen Gras 
278*2fe8fb19SBen Gras #ifdef _LIBRESOLV
279*2fe8fb19SBen Gras int
res_update(ns_updrec * rrecp_in)280*2fe8fb19SBen Gras res_update(ns_updrec *rrecp_in) {
281*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
282*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
283*2fe8fb19SBen Gras 		return (-1);
284*2fe8fb19SBen Gras 	}
285*2fe8fb19SBen Gras 
286*2fe8fb19SBen Gras 	return (res_nupdate(&_nres, rrecp_in, NULL));
287*2fe8fb19SBen Gras }
288*2fe8fb19SBen Gras #endif
289*2fe8fb19SBen Gras 
290*2fe8fb19SBen Gras int
res_search(const char * name,int class,int type,u_char * answer,int anslen)291*2fe8fb19SBen Gras res_search(const char *name,	/*!< domain name  */
292*2fe8fb19SBen Gras 	   int class, int type,	/*!< class and type of query  */
293*2fe8fb19SBen Gras 	   u_char *answer,	/*!< buffer to put answer  */
294*2fe8fb19SBen Gras 	   int anslen)		/*!< size of answer  */
295*2fe8fb19SBen Gras {
296*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
297*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
298*2fe8fb19SBen Gras 		return (-1);
299*2fe8fb19SBen Gras 	}
300*2fe8fb19SBen Gras 
301*2fe8fb19SBen Gras 	return (res_nsearch(&_nres, name, class, type, answer, anslen));
302*2fe8fb19SBen Gras }
303*2fe8fb19SBen Gras 
304*2fe8fb19SBen Gras int
res_querydomain(const char * name,const char * domain,int class,int type,u_char * answer,int anslen)305*2fe8fb19SBen Gras res_querydomain(const char *name,
306*2fe8fb19SBen Gras 		const char *domain,
307*2fe8fb19SBen Gras 		int class, int type,	/*!< class and type of query  */
308*2fe8fb19SBen Gras 		u_char *answer,		/*!< buffer to put answer  */
309*2fe8fb19SBen Gras 		int anslen)		/*!< size of answer  */
310*2fe8fb19SBen Gras {
311*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
312*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL);
313*2fe8fb19SBen Gras 		return (-1);
314*2fe8fb19SBen Gras 	}
315*2fe8fb19SBen Gras 
316*2fe8fb19SBen Gras 	return (res_nquerydomain(&_nres, name, domain,
317*2fe8fb19SBen Gras 				 class, type,
318*2fe8fb19SBen Gras 				 answer, anslen));
319*2fe8fb19SBen Gras }
320*2fe8fb19SBen Gras 
321*2fe8fb19SBen Gras int
res_opt(int a,u_char * b,int c,int d)322*2fe8fb19SBen Gras res_opt(int a, u_char *b, int c, int d)
323*2fe8fb19SBen Gras {
324*2fe8fb19SBen Gras 	return res_nopt(&_nres, a, b, c, d);
325*2fe8fb19SBen Gras }
326*2fe8fb19SBen Gras 
327*2fe8fb19SBen Gras u_int
res_randomid(void)328*2fe8fb19SBen Gras res_randomid(void) {
329*2fe8fb19SBen Gras 	if ((_nres.options & RES_INIT) == 0U && res_init() == -1) {
330*2fe8fb19SBen Gras 		RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
331*2fe8fb19SBen Gras 		return (u_int)-1;
332*2fe8fb19SBen Gras 	}
333*2fe8fb19SBen Gras 
334*2fe8fb19SBen Gras 	return (res_nrandomid(&_nres));
335*2fe8fb19SBen Gras }
336*2fe8fb19SBen Gras 
337*2fe8fb19SBen Gras const char *
hostalias(const char * name)338*2fe8fb19SBen Gras hostalias(const char *name) {
339*2fe8fb19SBen Gras 	static char abuf[MAXDNAME];
340*2fe8fb19SBen Gras 
341*2fe8fb19SBen Gras 	return (res_hostalias(&_nres, name, abuf, sizeof abuf));
342*2fe8fb19SBen Gras }
343*2fe8fb19SBen Gras 
344*2fe8fb19SBen Gras #ifdef ultrix
345*2fe8fb19SBen Gras int
local_hostname_length(const char * hostname)346*2fe8fb19SBen Gras local_hostname_length(const char *hostname) {
347*2fe8fb19SBen Gras 	int len_host, len_domain;
348*2fe8fb19SBen Gras 
349*2fe8fb19SBen Gras 	if (!*_nres.defdname)
350*2fe8fb19SBen Gras 		res_init();
351*2fe8fb19SBen Gras 	len_host = strlen(hostname);
352*2fe8fb19SBen Gras 	len_domain = strlen(_nres.defdname);
353*2fe8fb19SBen Gras 	if (len_host > len_domain &&
354*2fe8fb19SBen Gras 	    !strcasecmp(hostname + len_host - len_domain, _nres.defdname) &&
355*2fe8fb19SBen Gras 	    hostname[len_host - len_domain - 1] == '.')
356*2fe8fb19SBen Gras 		return (len_host - len_domain - 1);
357*2fe8fb19SBen Gras 	return (0);
358*2fe8fb19SBen Gras }
359*2fe8fb19SBen Gras #endif /*ultrix*/
360*2fe8fb19SBen Gras 
361*2fe8fb19SBen Gras #endif
362*2fe8fb19SBen Gras 
363*2fe8fb19SBen Gras /*! \file */
364