ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.0.x/src/firedns.c
(Generate patch)

Comparing hopm/branches/1.0.x/src/firedns.c (file contents):
Revision 5174 by michael, Fri Dec 26 21:08:42 2014 UTC vs.
Revision 5180 by michael, Sun Dec 28 11:26:52 2014 UTC

# Line 59 | Line 59 | static struct in_addr servers4[FDNS_MAX]
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(),
# Line 104 | Line 102 | struct s_connection
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
# Line 164 | Line 160 | void firedns_init(void)
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 */
# Line 178 | Line 170 | void firedns_init(void)
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)
# Line 200 | Line 190 | void firedns_init(void)
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              {
# Line 210 | Line 200 | void firedns_init(void)
200                    continue;
201                 }
202              }
203 < #endif
203 >
204              if (i4 < FDNS_MAX)
205              {
206                if (inet_pton(AF_INET, &buf[i], &addr4) > 0)
# Line 225 | Line 215 | void firedns_init(void)
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)
# Line 234 | Line 224 | void firedns_init(void)
224                 continue;
225              }
226           }
227 < #endif
227 >
228           if (i4 < FDNS_MAX)
229           {
230                if (inet_pton(AF_INET, buf, &addr4) > 0)
# Line 245 | Line 235 | void firedns_init(void)
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);
# Line 429 | Line 418 | static int firedns_send_requests(struct
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;
# Line 444 | Line 430 | static int firedns_send_requests(struct
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     {
# Line 473 | Line 457 | static int firedns_send_requests(struct
457     }
458     if (s->v6 == 0)
459     {
476 #endif
460        s->fd = socket(PF_INET, SOCK_DGRAM, 0);
461        if (s->fd != -1)
462        {
# Line 501 | Line 484 | static int firedns_send_requests(struct
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     {
# Line 521 | Line 499 | static int firedns_send_requests(struct
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        {
# Line 538 | Line 514 | static int firedns_send_requests(struct
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));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines