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