diff options
author | Damien Miller <djm@mindrot.org> | 2003-05-18 22:24:09 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2003-05-18 22:24:09 +1000 |
commit | e323df6c4851b04386e747a009474f469fe97137 (patch) | |
tree | 2c4209855f9ed24545b1add919db8319b34ec992 /openbsd-compat/getrrsetbyname.c | |
parent | 0b8e9006d87075968dc402afa0f6ca359184b83b (diff) |
- (djm) Sync openbsd-compat/ with OpenBSD CVS head
Diffstat (limited to 'openbsd-compat/getrrsetbyname.c')
-rw-r--r-- | openbsd-compat/getrrsetbyname.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c index 1a4d9c14b..3ba54e0da 100644 --- a/openbsd-compat/getrrsetbyname.c +++ b/openbsd-compat/getrrsetbyname.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */ | 1 | /* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. | 4 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. |
@@ -49,6 +49,8 @@ | |||
49 | 49 | ||
50 | #include "getrrsetbyname.h" | 50 | #include "getrrsetbyname.h" |
51 | 51 | ||
52 | /* #include "thread_private.h" */ | ||
53 | |||
52 | #define ANSWER_BUFFER_SIZE 1024*64 | 54 | #define ANSWER_BUFFER_SIZE 1024*64 |
53 | 55 | ||
54 | struct dns_query { | 56 | struct dns_query { |
@@ -76,10 +78,10 @@ struct dns_response { | |||
76 | struct dns_rr *additional; | 78 | struct dns_rr *additional; |
77 | }; | 79 | }; |
78 | 80 | ||
79 | static struct dns_response *parse_dns_response(const char *, int); | 81 | static struct dns_response *parse_dns_response(const u_char *, int); |
80 | static struct dns_query *parse_dns_qsection(const char *, int, const char **, | 82 | static struct dns_query *parse_dns_qsection(const u_char *, int, |
81 | int); | 83 | const u_char **, int); |
82 | static struct dns_rr *parse_dns_rrsection(const char *, int, const char **, | 84 | static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **, |
83 | int); | 85 | int); |
84 | 86 | ||
85 | static void free_dns_query(struct dns_query *); | 87 | static void free_dns_query(struct dns_query *); |
@@ -153,13 +155,15 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
153 | unsigned int rdtype, unsigned int flags, | 155 | unsigned int rdtype, unsigned int flags, |
154 | struct rrsetinfo **res) | 156 | struct rrsetinfo **res) |
155 | { | 157 | { |
158 | struct __res_state *_resp = &_res; | ||
156 | int result; | 159 | int result; |
157 | struct rrsetinfo *rrset = NULL; | 160 | struct rrsetinfo *rrset = NULL; |
158 | struct dns_response *response; | 161 | struct dns_response *response; |
159 | struct dns_rr *rr; | 162 | struct dns_rr *rr; |
160 | struct rdatainfo *rdata; | 163 | struct rdatainfo *rdata; |
161 | unsigned int length, index_ans, index_sig; | 164 | int length; |
162 | char answer[ANSWER_BUFFER_SIZE]; | 165 | unsigned int index_ans, index_sig; |
166 | u_char answer[ANSWER_BUFFER_SIZE]; | ||
163 | 167 | ||
164 | /* check for invalid class and type */ | 168 | /* check for invalid class and type */ |
165 | if (rdclass > 0xffff || rdtype > 0xffff) { | 169 | if (rdclass > 0xffff || rdtype > 0xffff) { |
@@ -180,23 +184,24 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, | |||
180 | } | 184 | } |
181 | 185 | ||
182 | /* initialize resolver */ | 186 | /* initialize resolver */ |
183 | if ((_res.options & RES_INIT) == 0 && res_init() == -1) { | 187 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { |
184 | result = ERRSET_FAIL; | 188 | result = ERRSET_FAIL; |
185 | goto fail; | 189 | goto fail; |
186 | } | 190 | } |
187 | 191 | ||
188 | #ifdef DEBUG | 192 | #ifdef DEBUG |
189 | _res.options |= RES_DEBUG; | 193 | _resp->options |= RES_DEBUG; |
190 | #endif /* DEBUG */ | 194 | #endif /* DEBUG */ |
191 | 195 | ||
192 | #ifdef RES_USE_DNSSEC | 196 | #ifdef RES_USE_DNSSEC |
193 | /* turn on DNSSEC if EDNS0 is configured */ | 197 | /* turn on DNSSEC if EDNS0 is configured */ |
194 | if (_res.options & RES_USE_EDNS0) | 198 | if (_resp->options & RES_USE_EDNS0) |
195 | _res.options |= RES_USE_DNSSEC; | 199 | _resp->options |= RES_USE_DNSSEC; |
196 | #endif /* RES_USE_DNSEC */ | 200 | #endif /* RES_USE_DNSEC */ |
197 | 201 | ||
198 | /* make query */ | 202 | /* make query */ |
199 | length = res_query(hostname, rdclass, rdtype, answer, sizeof(answer)); | 203 | length = res_query(hostname, (signed int) rdclass, (signed int) rdtype, |
204 | answer, sizeof(answer)); | ||
200 | if (length < 0) { | 205 | if (length < 0) { |
201 | switch(h_errno) { | 206 | switch(h_errno) { |
202 | case HOST_NOT_FOUND: | 207 | case HOST_NOT_FOUND: |
@@ -338,10 +343,10 @@ freerrset(struct rrsetinfo *rrset) | |||
338 | * DNS response parsing routines | 343 | * DNS response parsing routines |
339 | */ | 344 | */ |
340 | static struct dns_response * | 345 | static struct dns_response * |
341 | parse_dns_response(const char *answer, int size) | 346 | parse_dns_response(const u_char *answer, int size) |
342 | { | 347 | { |
343 | struct dns_response *resp; | 348 | struct dns_response *resp; |
344 | const char *cp; | 349 | const u_char *cp; |
345 | 350 | ||
346 | /* allocate memory for the response */ | 351 | /* allocate memory for the response */ |
347 | resp = calloc(1, sizeof(*resp)); | 352 | resp = calloc(1, sizeof(*resp)); |
@@ -403,7 +408,7 @@ parse_dns_response(const char *answer, int size) | |||
403 | } | 408 | } |
404 | 409 | ||
405 | static struct dns_query * | 410 | static struct dns_query * |
406 | parse_dns_qsection(const char *answer, int size, const char **cp, int count) | 411 | parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count) |
407 | { | 412 | { |
408 | struct dns_query *head, *curr, *prev; | 413 | struct dns_query *head, *curr, *prev; |
409 | int i, length; | 414 | int i, length; |
@@ -449,7 +454,7 @@ parse_dns_qsection(const char *answer, int size, const char **cp, int count) | |||
449 | } | 454 | } |
450 | 455 | ||
451 | static struct dns_rr * | 456 | static struct dns_rr * |
452 | parse_dns_rrsection(const char *answer, int size, const char **cp, int count) | 457 | parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, int count) |
453 | { | 458 | { |
454 | struct dns_rr *head, *curr, *prev; | 459 | struct dns_rr *head, *curr, *prev; |
455 | int i, length; | 460 | int i, length; |