59 |
|
/* actual count of nameservers; set by firedns_init() */ |
60 |
|
static int i4; |
61 |
|
|
62 |
– |
#ifdef IPV6 |
62 |
|
static int i6; |
63 |
|
static struct in6_addr servers6[FDNS_MAX]; |
65 |
– |
#endif |
64 |
|
|
65 |
|
/* |
66 |
|
* linked list of open DNS queries; populated by firedns_add_query(), |
102 |
|
void *info; |
103 |
|
time_t start; |
104 |
|
char lookup[256]; |
107 |
– |
#ifdef IPV6 |
105 |
|
int v6; |
109 |
– |
#endif |
106 |
|
}; |
107 |
|
|
108 |
|
struct s_rr_middle |
160 |
|
struct in_addr addr4; |
161 |
|
char buf[1024]; |
162 |
|
const char *file; |
167 |
– |
#ifdef IPV6 |
168 |
– |
|
163 |
|
struct in6_addr addr6; |
164 |
|
|
165 |
|
i6 = 0; |
172 |
– |
#endif |
173 |
– |
|
166 |
|
i4 = 0; |
167 |
|
|
168 |
|
/* Initialize connections list */ |
170 |
|
|
171 |
|
srand((unsigned int) time(NULL)); |
172 |
|
memset(servers4,'\0',sizeof(struct in_addr) * FDNS_MAX); |
181 |
– |
#ifdef IPV6 |
182 |
– |
|
173 |
|
memset(servers6,'\0',sizeof(struct in6_addr) * FDNS_MAX); |
174 |
< |
#endif |
174 |
> |
|
175 |
|
/* read etc/firedns.conf if we've got it, otherwise parse /etc/resolv.conf */ |
176 |
|
f = fopen(FDNS_CONFIG_PREF,"r"); |
177 |
|
if (f == NULL) |
190 |
|
i = 10; |
191 |
|
while (buf[i] == ' ' || buf[i] == '\t') |
192 |
|
i++; |
193 |
< |
#ifdef IPV6 |
193 |
> |
|
194 |
|
/* glibc /etc/resolv.conf seems to allow ipv6 server names */ |
195 |
|
if (i6 < FDNS_MAX) |
196 |
|
{ |
200 |
|
continue; |
201 |
|
} |
202 |
|
} |
203 |
< |
#endif |
203 |
> |
|
204 |
|
if (i4 < FDNS_MAX) |
205 |
|
{ |
206 |
|
if (inet_pton(AF_INET, &buf[i], &addr4) > 0) |
215 |
|
while (fgets(buf,1024,f) != NULL) |
216 |
|
{ |
217 |
|
buf[strspn(buf, "0123456789.")] = '\0'; |
218 |
< |
#ifdef IPV6 |
218 |
> |
|
219 |
|
if (i6 < FDNS_MAX) |
220 |
|
{ |
221 |
|
if (inet_pton(AF_INET6, buf, &addr6) > 0) |
224 |
|
continue; |
225 |
|
} |
226 |
|
} |
227 |
< |
#endif |
227 |
> |
|
228 |
|
if (i4 < FDNS_MAX) |
229 |
|
{ |
230 |
|
if (inet_pton(AF_INET, buf, &addr4) > 0) |
235 |
|
fclose(f); |
236 |
|
|
237 |
|
if(i4 == 0 |
238 |
< |
#ifdef IPV6 /* (yuck) */ |
238 |
> |
/* (yuck) */ |
239 |
|
&& i6 |
250 |
– |
#endif |
240 |
|
) |
241 |
|
{ |
242 |
|
log_printf("FIREDNS -> No nameservers found in %s", file); |
418 |
|
{ |
419 |
|
int i, sent_ok = 0; |
420 |
|
struct sockaddr_in addr4; |
432 |
– |
|
433 |
– |
#ifdef IPV6 |
421 |
|
struct sockaddr_in6 addr6; |
435 |
– |
#endif |
422 |
|
|
423 |
|
/* set header flags */ |
424 |
|
h->flags1 = 0 | FLAGS1_MASK_RD; |
430 |
|
memcpy(h->id, s->id, 2); |
431 |
|
|
432 |
|
/* try to create ipv6 or ipv4 socket */ |
447 |
– |
#ifdef IPV6 |
448 |
– |
|
433 |
|
s->v6 = 0; |
434 |
|
if (i6 > 0) |
435 |
|
{ |
457 |
|
} |
458 |
|
if (s->v6 == 0) |
459 |
|
{ |
476 |
– |
#endif |
460 |
|
s->fd = socket(PF_INET, SOCK_DGRAM, 0); |
461 |
|
if (s->fd != -1) |
462 |
|
{ |
484 |
|
fdns_errno = FDNS_ERR_NETWORK; |
485 |
|
return -1; |
486 |
|
} |
504 |
– |
#ifdef IPV6 |
505 |
– |
|
487 |
|
} |
507 |
– |
#endif |
508 |
– |
|
488 |
|
|
510 |
– |
#ifdef IPV6 |
489 |
|
/* if we've got ipv6 support, an ip v6 socket, and ipv6 servers, send to them */ |
490 |
|
if (i6 > 0 && s->v6 == 1) |
491 |
|
{ |
499 |
|
sent_ok = 1; |
500 |
|
} |
501 |
|
} |
524 |
– |
#endif |
502 |
|
|
503 |
|
for (i = 0; i < i4; i++) |
504 |
|
{ |
528 |
– |
#ifdef IPV6 |
505 |
|
/* send via ipv4-over-ipv6 if we've got an ipv6 socket */ |
506 |
|
if (s->v6 == 1) |
507 |
|
{ |
514 |
|
sent_ok = 1; |
515 |
|
continue; |
516 |
|
} |
517 |
< |
#endif |
517 |
> |
|
518 |
|
/* otherwise send via standard ipv4 boringness */ |
519 |
|
memset(&addr4,0,sizeof(addr4)); |
520 |
|
memcpy(&addr4.sin_addr,&servers4[i],sizeof(addr4.sin_addr)); |