]>
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 const char *__res_opcodes
[] = {
54 "CQUERYU", /* experimental */
55 "NOTIFY", /* experimental */
70 __h_errno_set(struct __res_state
*res
, int err
)
72 h_errno
= res
->res_h_errno
= err
;
76 res_client_close(res_state res
)
78 if (res
== NULL
) return;
80 if (res
->_u
._ext
.ext
!= NULL
) free(res
->_u
._ext
.ext
);
89 x
= (res_state
)calloc(1, sizeof(struct __res_state
));
90 if (x
== NULL
) return NULL
;
93 * We use _pad (normally unused) to hold a version number.
94 * We use it provide limited compatibility between versions.
98 x
->_u
._ext
.ext
= (struct __res_state_ext
*)calloc(1, sizeof(struct __res_state_ext
));
99 if (x
->_u
._ext
.ext
== NULL
)
111 extern int __res_vinit(res_state
, int);
112 unsigned int save_retrans
, save_retry
, save_options
, save_id
;
113 struct __res_state_ext
*save_ext
;
116 _res_static
= &_res_9
;
121 save_retrans
= RES_TIMEOUT
;
122 save_retry
= RES_DFLRETRY
;
123 save_options
= RES_DEFAULT
;
124 save_id
= res_randomid();
125 save_ext
= _res_static
->_u
._ext
.ext
;
127 if (_res_static
->options
& RES_INIT
)
129 /* Caller wants to override default options */
130 save_options
= _res_static
->options
;
131 if (_res_static
->retrans
!= 0) save_retrans
= _res_static
->retrans
;
132 if (_res_static
->retry
!= 0) save_retry
= _res_static
->retry
;
133 if (_res_static
->id
!= 0) save_id
= _res_static
->id
;
136 memset(_res_static
, 0, sizeof(struct __res_state
));
137 _res_static
->_vcsock
= -1;
139 _res_static
->retrans
= save_retrans
;
140 _res_static
->retry
= save_retry
;
141 _res_static
->id
= save_id
;
142 _res_static
->options
= save_options
;
143 _res_static
->_u
._ext
.ext
= save_ext
;
145 _res_static
->_pad
= 9;
147 if (_res_static
->_u
._ext
.ext
== NULL
) _res_static
->_u
._ext
.ext
= (struct __res_state_ext
*)calloc(1, sizeof(struct __res_state_ext
));
149 return (__res_vinit(_res_static
, 1));
153 res_query(const char *name
, int class, int type
, u_char
*answer
, int anslen
)
156 _res_static
= &_res_9
;
161 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
163 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
166 return (res_nquery(_res_static
, name
, class, type
, answer
, anslen
));
170 fp_nquery(const u_char
*msg
, int len
, FILE *file
)
173 _res_static
= &_res_9
;
178 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1)) return;
180 res_pquery(_res_static
, msg
, len
, file
);
184 fp_query(const u_char
*msg
, FILE *file
)
186 fp_nquery(msg
, NS_PACKETSZ
, file
);
190 p_query(const u_char
*msg
)
192 fp_query(msg
, stdout
);
196 hostalias(const char *name
)
198 static char abuf
[NS_MAXDNAME
];
201 _res_static
= &_res_9
;
206 return (res_hostalias(_res_static
, name
, abuf
, sizeof abuf
));
213 _res_static
= &_res_9
;
218 res_nclose(_res_static
);
222 res_isourserver(const struct sockaddr_in
*inp
)
225 _res_static
= &_res_9
;
230 return (res_ourserver_p(_res_static
, (const struct sockaddr
*)inp
));
234 res_nisourserver(const res_state res
, const struct sockaddr_in
*inp
)
236 return (res_ourserver_p(res
, (const struct sockaddr
*)inp
));
240 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
)
243 _res_static
= &_res_9
;
248 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
250 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
254 return res_nmkquery(_res_static
, op
, dname
, class, type
, data
, datalen
, newrr_in
, buf
, buflen
);
258 res_querydomain(const char *name
, const char *domain
, int class, int type
, u_char
*answer
, int anslen
)
261 _res_static
= &_res_9
;
266 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
268 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
272 return res_nquerydomain(_res_static
, name
, domain
, class, type
, answer
, anslen
);
276 res_search(const char *name
, int class, int type
, u_char
*answer
, int anslen
)
279 _res_static
= &_res_9
;
284 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
286 RES_SET_H_ERRNO(_res_static
, NETDB_INTERNAL
);
290 return res_nsearch(_res_static
, name
, class, type
, answer
, anslen
);
294 res_send(const u_char
*buf
, int buflen
, u_char
*ans
, int anssiz
)
297 _res_static
= &_res_9
;
302 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
304 /* errno should have been set by res_init() in this case. */
308 return res_nsend(_res_static
, buf
, buflen
, ans
, anssiz
);
312 res_sendsigned(const u_char
*buf
, int buflen
, ns_tsig_key
*key
, u_char
*ans
, int anssiz
)
315 _res_static
= &_res_9
;
320 if (((_res_static
->options
& RES_INIT
) == 0) && (res_init() == -1))
322 /* errno should have been set by res_init() in this case. */
326 return res_nsendsigned(_res_static
, buf
, buflen
, key
, ans
, anssiz
);