]>
git.ipfire.org Git - thirdparty/glibc.git/blob - resolv/res_data.c
2 * Copyright (c) 1995-1999 by Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
18 #include <sys/types.h>
19 #include <sys/param.h>
20 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #include <arpa/nameser.h>
35 const char *_res_opcodes
[] = {
39 "CQUERYU", /* experimental */
40 "NOTIFY", /* experimental */
53 libresolv_hidden_data_def (_res_opcodes
)
55 #ifndef __BIND_NOSTATIC
57 p_query(const u_char
*msg
) {
58 fp_query(msg
, stdout
);
62 fp_query(const u_char
*msg
, FILE *file
) {
63 fp_nquery(msg
, PACKETSZ
, file
);
65 libresolv_hidden_def (fp_query
)
68 fp_nquery(const u_char
*msg
, int len
, FILE *file
) {
69 if (__res_maybe_init (&_res
, 0) == -1)
72 res_pquery(&_res
, msg
, len
, file
);
74 libresolv_hidden_def (fp_nquery
)
77 res_mkquery(int op
, /* opcode of query */
78 const char *dname
, /* domain name */
79 int class, int type
, /* class and type of query */
80 const u_char
*data
, /* resource record data */
81 int datalen
, /* length of data */
82 const u_char
*newrr_in
, /* new rr for modify or append */
83 u_char
*buf
, /* buffer to put query */
84 int buflen
) /* size of buffer */
86 if (__res_maybe_init (&_res
, 1) == -1) {
87 RES_SET_H_ERRNO(&_res
, NETDB_INTERNAL
);
90 return (res_nmkquery(&_res
, op
, dname
, class, type
,
92 newrr_in
, buf
, buflen
));
96 res_query(const char *name
, /* domain name */
97 int class, int type
, /* class and type of query */
98 u_char
*answer
, /* buffer to put answer */
99 int anslen
) /* size of answer buffer */
101 if (__res_maybe_init (&_res
, 1) == -1) {
102 RES_SET_H_ERRNO(&_res
, NETDB_INTERNAL
);
105 return (res_nquery(&_res
, name
, class, type
, answer
, anslen
));
109 res_send_setqhook(res_send_qhook hook
) {
114 res_send_setrhook(res_send_rhook hook
) {
119 res_isourserver(const struct sockaddr_in
*inp
) {
120 return (res_ourserver_p(&_res
, (const struct sockaddr_in6
*) inp
));
124 res_send(const u_char
*buf
, int buflen
, u_char
*ans
, int anssiz
) {
125 if (__res_maybe_init (&_res
, 1) == -1) {
126 /* errno should have been set by res_init() in this case. */
130 return (res_nsend(&_res
, buf
, buflen
, ans
, anssiz
));
137 * Some stupid programs out there call res_close() before res_init().
138 * Since _res._vcsock isn't explicitly initialized, these means that
139 * we could do a close(0), which might lead to some security problems.
140 * Therefore we check if res_init() was called before by looking at
141 * the RES_INIT bit in _res.options. If it hasn't been set we bail out
143 if ((_res
.options
& RES_INIT
) == 0)
145 /* We don't free the name server addresses because we never
146 did it and it would be done implicitly on shutdown. */
147 __res_iclose(&_res
, false);
151 res_search(const char *name
, /* domain name */
152 int class, int type
, /* class and type of query */
153 u_char
*answer
, /* buffer to put answer */
154 int anslen
) /* size of answer */
156 if (__res_maybe_init (&_res
, 1) == -1) {
157 RES_SET_H_ERRNO(&_res
, NETDB_INTERNAL
);
161 return (res_nsearch(&_res
, name
, class, type
, answer
, anslen
));
165 res_querydomain(const char *name
,
167 int class, int type
, /* class and type of query */
168 u_char
*answer
, /* buffer to put answer */
169 int anslen
) /* size of answer */
171 if (__res_maybe_init (&_res
, 1) == -1) {
172 RES_SET_H_ERRNO(&_res
, NETDB_INTERNAL
);
176 return (res_nquerydomain(&_res
, name
, domain
,
182 hostalias(const char *name
) {
183 static char abuf
[MAXDNAME
];
185 return (res_hostalias(&_res
, name
, abuf
, sizeof abuf
));
187 libresolv_hidden_def (hostalias
)
192 #include <shlib-compat.h>
194 #if SHLIB_COMPAT(libresolv, GLIBC_2_0, GLIBC_2_2)
197 # undef res_querydomain
199 weak_alias (__res_mkquery
, res_mkquery
);
200 weak_alias (__res_query
, res_query
);
201 weak_alias (__res_querydomain
, res_querydomain
);
202 weak_alias (__res_search
, res_search
);