ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/res.c
(Generate patch)

Comparing ircd-hybrid-7.3/src/irc_res.c (file contents):
Revision 1123 by michael, Sun Feb 6 21:57:50 2011 UTC vs.
Revision 1124 by michael, Mon Feb 7 11:45:27 2011 UTC

# Line 94 | Line 94 | static fde_t ResolverFileDescriptor;
94   static dlink_list request_list = { NULL, NULL, 0 };
95   static BlockHeap *dns_heap = NULL;
96  
97 < static void rem_request(struct reslist *request);
98 < static struct reslist *make_request(dns_callback_fnc callback, void *);
99 < static void do_query_name(dns_callback_fnc callback, void *,
97 > static void rem_request(struct reslist *);
98 > static struct reslist *make_request(dns_callback_fnc, void *);
99 > static void do_query_name(dns_callback_fnc, void *,
100                            const char *, struct reslist *, int);
101 < static void do_query_number(dns_callback_fnc callback, void *ctx,
101 > static void do_query_number(dns_callback_fnc, void *,
102                              const struct irc_ssaddr *,
103 <                            struct reslist *request);
104 < static void query_name(const char *name, int query_class, int query_type,
105 <                       struct reslist *request);
106 < static int send_res_msg(const char *buf, int len, int count);
107 < static void resend_query(struct reslist *request);
108 < static int proc_answer(struct reslist *request, HEADER *header, char *, char *);
109 < static struct reslist *find_id(int id);
103 >                            struct reslist *);
104 > static void query_name(const char *, int, int, struct reslist *);
105 > static int send_res_msg(const char *, int, int);
106 > static void resend_query(struct reslist *);
107 > static int proc_answer(struct reslist *, HEADER *, char *, char *);
108 > static struct reslist *find_id(int);
109  
110  
111   /*
# Line 153 | Line 152 | res_ourserver(const struct irc_ssaddr *i
152                      sizeof(struct in6_addr)) == 0) ||
153                  (memcmp(&v6->sin6_addr.s6_addr, &in6addr_any,
154                          sizeof(struct in6_addr)) == 0))
155 <              return(1);
155 >              return 1;
156          break;
157   #endif
158        case AF_INET:
# Line 161 | Line 160 | res_ourserver(const struct irc_ssaddr *i
160            if (v4->sin_port == v4in->sin_port)
161              if ((v4->sin_addr.s_addr == INADDR_ANY) ||
162                  (v4->sin_addr.s_addr == v4in->sin_addr.s_addr))
163 <              return(1);
163 >              return 1;
164          break;
165        default:
166          break;
167      }
168    }
169  
170 <  return(0);
170 >  return 0;
171   }
172  
173   /*
# Line 206 | Line 205 | timeout_query_list(time_t now)
205      }
206  
207      if ((next_time == 0) || timeout < next_time)
209    {
208        next_time = timeout;
211    }
209    }
210  
211 <  return((next_time > now) ? next_time : (now + AR_TTL));
211 >  return (next_time > now) ? next_time : (now + AR_TTL);
212   }
213  
214   /*
# Line 347 | Line 344 | send_res_msg(const char *msg, int len, i
344        ++sent;
345    }
346  
347 <  return(sent);
347 >  return sent;
348   }
349  
350   /*
# Line 356 | Line 353 | send_res_msg(const char *msg, int len, i
353   static struct reslist *
354   find_id(int id)
355   {
356 <  dlink_node *ptr;
360 <  struct reslist *request;
356 >  dlink_node *ptr = NULL;
357  
358    DLINK_FOREACH(ptr, request_list.head)
359    {
360 <    request = ptr->data;
360 >    struct reslist *request = ptr->data;
361  
362      if (request->id == id)
363 <      return(request);
363 >      return request;
364    }
365  
366 <  return(NULL);
366 >  return NULL;
367   }
368  
369   /*
# Line 377 | Line 373 | find_id(int id)
373   void
374   gethost_byname_type(dns_callback_fnc callback, void *ctx, const char *name, int type)
375   {
376 <  assert(name != 0);
376 >  assert(name != NULL);
377    do_query_name(callback, ctx, name, NULL, type);
378   }
379  
# Line 446 | Line 442 | do_query_number(dns_callback_fnc callbac
442    if (addr->ss.ss_family == AF_INET)
443    {
444      const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
445 <    cp = (const unsigned char*)&v4->sin_addr.s_addr;
445 >    cp = (const unsigned char *)&v4->sin_addr.s_addr;
446  
447 <    ircsprintf(ipbuf, "%u.%u.%u.%u.in-addr.arpa.",
448 <               (unsigned int)(cp[3]), (unsigned int)(cp[2]),
449 <               (unsigned int)(cp[1]), (unsigned int)(cp[0]));
447 >    snprintf(ipbuf, sizeof(ipbuf), "%u.%u.%u.%u.in-addr.arpa.",
448 >             (unsigned int)(cp[3]), (unsigned int)(cp[2]),
449 >             (unsigned int)(cp[1]), (unsigned int)(cp[0]));
450    }
451   #ifdef IPV6
452    else if (addr->ss.ss_family == AF_INET6)
# Line 458 | Line 454 | do_query_number(dns_callback_fnc callbac
454      const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
455      cp = (const unsigned char *)&v6->sin6_addr.s6_addr;
456  
457 <    sprintf(ipbuf, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
458 <                   "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa.",
459 <                  (unsigned int)(cp[15]&0xf), (unsigned int)(cp[15]>>4),
460 <                  (unsigned int)(cp[14]&0xf), (unsigned int)(cp[14]>>4),
461 <                  (unsigned int)(cp[13]&0xf), (unsigned int)(cp[13]>>4),
462 <                  (unsigned int)(cp[12]&0xf), (unsigned int)(cp[12]>>4),
463 <                  (unsigned int)(cp[11]&0xf), (unsigned int)(cp[11]>>4),
464 <                  (unsigned int)(cp[10]&0xf), (unsigned int)(cp[10]>>4),
465 <                  (unsigned int)(cp[9]&0xf), (unsigned int)(cp[9]>>4),
466 <                  (unsigned int)(cp[8]&0xf), (unsigned int)(cp[8]>>4),
467 <                  (unsigned int)(cp[7]&0xf), (unsigned int)(cp[7]>>4),
468 <                  (unsigned int)(cp[6]&0xf), (unsigned int)(cp[6]>>4),
469 <                  (unsigned int)(cp[5]&0xf), (unsigned int)(cp[5]>>4),
470 <                  (unsigned int)(cp[4]&0xf), (unsigned int)(cp[4]>>4),
471 <                  (unsigned int)(cp[3]&0xf), (unsigned int)(cp[3]>>4),
472 <                  (unsigned int)(cp[2]&0xf), (unsigned int)(cp[2]>>4),
473 <                  (unsigned int)(cp[1]&0xf), (unsigned int)(cp[1]>>4),
474 <                  (unsigned int)(cp[0]&0xf), (unsigned int)(cp[0]>>4));
457 >    snprintf(ipbuf, sizeof(ipbuf),
458 >             "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
459 >             "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa.",
460 >             (unsigned int)(cp[15] & 0xf), (unsigned int)(cp[15] >> 4),
461 >             (unsigned int)(cp[14] & 0xf), (unsigned int)(cp[14] >> 4),
462 >             (unsigned int)(cp[13] & 0xf), (unsigned int)(cp[13] >> 4),
463 >             (unsigned int)(cp[12] & 0xf), (unsigned int)(cp[12] >> 4),
464 >             (unsigned int)(cp[11] & 0xf), (unsigned int)(cp[11] >> 4),
465 >             (unsigned int)(cp[10] & 0xf), (unsigned int)(cp[10] >> 4),
466 >             (unsigned int)(cp[9] & 0xf), (unsigned int)(cp[9] >> 4),
467 >             (unsigned int)(cp[8] & 0xf), (unsigned int)(cp[8] >> 4),
468 >             (unsigned int)(cp[7] & 0xf), (unsigned int)(cp[7] >> 4),
469 >             (unsigned int)(cp[6] & 0xf), (unsigned int)(cp[6] >> 4),
470 >             (unsigned int)(cp[5] & 0xf), (unsigned int)(cp[5] >> 4),
471 >             (unsigned int)(cp[4] & 0xf), (unsigned int)(cp[4] >> 4),
472 >             (unsigned int)(cp[3] & 0xf), (unsigned int)(cp[3] >> 4),
473 >             (unsigned int)(cp[2] & 0xf), (unsigned int)(cp[2] >> 4),
474 >             (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
475 >             (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4));
476    }
477   #endif
478    if (request == NULL)
# Line 552 | Line 549 | resend_query(struct reslist *request)
549   * proc_answer - process name server reply
550   */
551   static int
552 < proc_answer(struct reslist *request, HEADER* header, char* buf, char* eob)
552 > proc_answer(struct reslist *request, HEADER *header, char *buf, char *eob)
553   {
554    char hostbuf[HOSTLEN + 100]; /* working buffer */
555    unsigned char *current;      /* current position in buf */
# Line 571 | Line 568 | proc_answer(struct reslist *request, HEA
568      if ((n = irc_dn_skipname(current, (unsigned char *)eob)) < 0)
569        break;
570  
571 <    current += (size_t) n + QFIXEDSZ;
571 >    current += (size_t)n + QFIXEDSZ;
572    }
573  
574    /*
# Line 584 | Line 581 | proc_answer(struct reslist *request, HEA
581      n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob, current,
582          hostbuf, sizeof(hostbuf));
583  
584 <    if (n < 0)
585 <    {
589 <      /*
590 <       * broken message
591 <       */
592 <      return(0);
593 <    }
594 <    else if (n == 0)
595 <    {
596 <      /*
597 <       * no more answers left
598 <       */
599 <      return(0);
600 <    }
584 >    if (n < 0 /* broken message */ || n == 0 /* no more answers left */)
585 >      return 0;
586  
587      hostbuf[HOSTLEN] = '\0';
588  
# Line 629 | Line 614 | proc_answer(struct reslist *request, HEA
614      {
615        case T_A:
616          if (request->type != T_A)
617 <          return(0);
617 >          return 0;
618  
619          /*
620           * check for invalid rd_length or too many addresses
621           */
622          if (rd_length != sizeof(struct in_addr))
623 <          return(0);
623 >          return 0;
624 >
625          v4 = (struct sockaddr_in *)&request->addr;
626          request->addr.ss_len = sizeof(struct sockaddr_in);
627          v4->sin_family = AF_INET;
628          memcpy(&v4->sin_addr, current, sizeof(struct in_addr));
629 <        return(1);
629 >        return 1;
630          break;
631   #ifdef IPV6
632        case T_AAAA:
633          if (request->type != T_AAAA)
634 <          return(0);
634 >          return 0;
635 >
636          if (rd_length != sizeof(struct in6_addr))
637 <          return(0);
637 >          return 0;
638 >
639          request->addr.ss_len = sizeof(struct sockaddr_in6);
640          v6 = (struct sockaddr_in6 *)&request->addr;
641          v6->sin6_family = AF_INET6;
642          memcpy(&v6->sin6_addr, current, sizeof(struct in6_addr));
643 <        return(1);
643 >        return 1;
644          break;
645   #endif
646        case T_PTR:
647          if (request->type != T_PTR)
648 <          return(0);
648 >          return 0;
649 >
650          n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob,
651              current, hostbuf, sizeof(hostbuf));
652 <        if (n < 0)
653 <          return(0); /* broken message */
665 <        else if (n == 0)
666 <          return(0); /* no more answers left */
652 >        if (n < 0 /* broken message */ || n == 0 /* no more answers left */)
653 >          return 0;
654  
655          strlcpy(request->name, hostbuf, HOSTLEN + 1);
656 <
670 <        return(1);
656 >        return 1;
657          break;
658        case T_CNAME: /* first check we already havent started looking
659                         into a cname */
660          if (request->type != T_PTR)
661 <          return(0);
661 >          return 0;
662  
663          if (request->state == REQ_CNAME)
664          {
# Line 680 | Line 666 | proc_answer(struct reslist *request, HEA
666                              current, hostbuf, sizeof(hostbuf));
667  
668            if (n < 0)
669 <            return(0);
670 <          return(1);
669 >            return 0;
670 >          return 1;
671          }
672  
673          request->state = REQ_CNAME;
# Line 698 | Line 684 | proc_answer(struct reslist *request, HEA
684      }
685    }
686  
687 <  return(1);
687 >  return 1;
688   }
689  
690   /*

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)