]>
git.saurik.com Git - apple/libresolv.git/blob - 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 #if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid
[] = "$Id: res_data.c,v 1.1 2006/03/01 19:01:37 majka Exp $";
20 #endif /* LIBC_SCCS and not lint */
22 #include <sys/types.h>
23 #include <sys/param.h>
24 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <arpa/nameser.h>
34 #include <res_update.h>
40 #include "res_private.h"
42 static struct __res_state
*_res_static
;
45 struct __res_9_state _res_9
;
48 extern int __res_vinit(res_state
, int);
50 __attribute__((__visibility__("hidden")))
51 const char *__res_opcodes
[] = {
55 "CQUERYU", /* experimental */
56 "NOTIFY", /* experimental */
71 __h_errno_set(struct __res_state
*res
, int err
)
73 h_errno
= res
->res_h_errno
= err
;
77 res_client_close(res_state res
)
79 if (res
== NULL
) return;
81 if (res
->_u
._ext
.ext
!= NULL
) free(res
->_u
._ext
.ext
);
90 x
= (res_state
)calloc(1, sizeof(struct __res_state
));
91 if (x
== NULL
) return NULL
;
94 * We use _pad (normally unused) to hold a version number.
95 * We use it provide limited compatibility between versions.
99 x
->_u
._ext
.ext
= (struct __res_state_ext
*)calloc(1, sizeof(struct __res_state_ext
));
100 if (x
->_u
._ext
.ext
== NULL
)
112 extern int __res_vinit(res_state
, int);
113 unsigned int save_retrans
, save_retry
, save_options
, save_id
;
114 struct __res_state_ext
*save_ext
;
117 _res_static
= &_res_9
;
122 save_retrans
= RES_TIMEOUT
;
123 save_retry
= RES_DFLRETRY
;
124 save_options
= RES_DEFAULT
;
125 save_id
= res_randomid();
126 save_ext
= _res_static
->_u
._ext
.ext
;
128 if (_res_static
->options
& RES_INIT
)
130 /* Caller wants to override default options */
131 save_options
= _res_static
->options
;
132 if (_res_static
->retrans
!= 0) save_retrans
= _res_static
->retrans
;
133 if (_res_static
->retry
!= 0) save_retry
= _res_static
->retry
;
134 if (_res_static
->id
!= 0) save_id
= _res_static
->id
;
137 memset(_res_static
, 0, sizeof(struct __res_state
));
138 _res_static
->_vcsock
= -1;
140 _res_static
->retrans
= save_retrans
;
141 _res_static
->retry
= save_retry
;
142 _res_static
->id
= save_id
;
143 _res_static
->options
= save_options
;
144 _res_static
->_u
._ext
.ext
= save_ext
;
146 _res_static
->_pad
= 9;
148 if (_res_static
->_u
._ext
.ext
== NULL
) _res_static
->_u
._ext
.ext
= (struct __res_state_ext
*)calloc(1, sizeof(struct __res_state_ext
));
150 return (__res_vinit(_res_static
, 1));
154 res_query(const char *name
, int class, int type
, u_char
*answer
, int anslen
)
157 _res_static
= &_res_9
;
162 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
164 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
167 return (res_nquery(_res_static
, name
, class, type
, answer
, anslen
));
171 fp_nquery(const u_char
*msg
, int len
, FILE *file
)
174 _res_static
= &_res_9
;
179 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1)) return;
181 res_pquery(_res_static
, msg
, len
, file
);
185 fp_query(const u_char
*msg
, FILE *file
)
187 fp_nquery(msg
, NS_PACKETSZ
, file
);
191 p_query(const u_char
*msg
)
193 fp_query(msg
, stdout
);
197 hostalias(const char *name
)
199 static char abuf
[NS_MAXDNAME
];
202 _res_static
= &_res_9
;
207 return (res_hostalias(_res_static
, name
, abuf
, sizeof abuf
));
214 _res_static
= &_res_9
;
219 res_nclose(_res_static
);
223 res_isourserver(const struct sockaddr_in
*inp
)
226 _res_static
= &_res_9
;
231 return (res_ourserver_p(_res_static
, (const struct sockaddr
*)inp
));
235 res_nisourserver(const res_state res
, const struct sockaddr_in
*inp
)
237 return (res_ourserver_p(res
, (const struct sockaddr
*)inp
));
241 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
)
244 _res_static
= &_res_9
;
249 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
251 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
255 return res_nmkquery(_res_static
, op
, dname
, class, type
, data
, datalen
, newrr_in
, buf
, buflen
);
259 res_querydomain(const char *name
, const char *domain
, int class, int type
, u_char
*answer
, int anslen
)
262 _res_static
= &_res_9
;
267 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
269 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
273 return res_nquerydomain(_res_static
, name
, domain
, class, type
, answer
, anslen
);
277 res_search(const char *name
, int class, int type
, u_char
*answer
, int anslen
)
280 _res_static
= &_res_9
;
285 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
287 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
291 return res_nsearch(_res_static
, name
, class, type
, answer
, anslen
);
295 res_send(const u_char
*buf
, int buflen
, u_char
*ans
, int anssiz
)
298 _res_static
= &_res_9
;
303 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
305 /* errno should have been set by res_init() in this case. */
309 return res_nsend(_res_static
, buf
, buflen
, ans
, anssiz
);
313 res_sendsigned(const u_char
*buf
, int buflen
, ns_tsig_key
*key
, u_char
*ans
, int anssiz
)
316 _res_static
= &_res_9
;
321 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
323 /* errno should have been set by res_init() in this case. */
327 return res_nsendsigned(_res_static
, buf
, buflen
, key
, ans
, anssiz
);