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

Comparing:
ircd-hybrid-7.2/src/irc_reslib.c (file contents), Revision 993 by michael, Thu Aug 20 10:44:18 2009 UTC vs.
ircd-hybrid/trunk/src/reslib.c (file contents), Revision 3322 by michael, Tue Apr 15 16:11:11 2014 UTC

# Line 10 | Line 10
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
13   * 4. Neither the name of the University nor the names of its contributors
14   *    may be used to endorse or promote products derived from this software
15   *    without specific prior written permission.
# Line 81 | Line 77
77   */
78  
79   #include "stdinc.h"
84 #include "irc_reslib.h"
85 #include "irc_res.h"    
80   #include "ircd_defs.h"
81 < #include "fileio.h"
81 > #include "res.h"
82 > #include "reslib.h"
83   #include "irc_string.h"
89 #include "irc_getaddrinfo.h"
84  
85   #define NS_TYPE_ELT             0x40 /* EDNS0 extended label type */
86   #define DNS_LABELTYPE_BITSTRING 0x41
# Line 95 | Line 89
89   /* $Id$ */
90  
91   struct irc_ssaddr irc_nsaddr_list[IRCD_MAXNS];
92 < int irc_nscount = 0;
99 < char irc_domain[HOSTLEN + 1];
92 > unsigned int irc_nscount = 0;
93  
94 + static const char digits[] = "0123456789";
95   static const char digitvalue[256] = {
96    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
97    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
# Line 117 | Line 111 | static const char digitvalue[256] = {
111    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
112   };
113  
120 static int parse_resvconf(void);
121 static void add_nameserver(char *arg);
122
123 static const char digits[] = "0123456789";
114   static int labellen(const unsigned char *lp);
115   static int special(int ch);
116   static int printable(int ch);
# Line 140 | Line 130 | static int irc_ns_name_ntop(const unsign
130   static int irc_ns_name_skip(const unsigned char **, const unsigned char *);
131   static int mklower(int ch);
132    
133 < int
134 < irc_res_init(void)
133 >
134 > /* add_nameserver()
135 > *
136 > * input        - either an IPV4 address in dotted quad
137 > *                or an IPV6 address in : format
138 > * output       - NONE
139 > * side effects - entry in irc_nsaddr_list is filled in as needed
140 > */
141 > static void
142 > add_nameserver(const char *arg)
143   {
144 <  irc_nscount = 0;
145 <  return parse_resvconf();
144 >  struct addrinfo hints, *res;
145 >
146 >  /* Done max number of nameservers? */
147 >  if (irc_nscount >= IRCD_MAXNS)
148 >    return;
149 >
150 >  memset(&hints, 0, sizeof(hints));
151 >  hints.ai_family   = PF_UNSPEC;
152 >  hints.ai_socktype = SOCK_DGRAM;
153 >  hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
154 >
155 >  if (getaddrinfo(arg, "domain", &hints, &res))
156 >    return;
157 >
158 >  if (res == NULL)
159 >    return;
160 >
161 >  memcpy(&irc_nsaddr_list[irc_nscount].ss, res->ai_addr, res->ai_addrlen);
162 >  irc_nsaddr_list[irc_nscount++].ss_len = res->ai_addrlen;
163 >  freeaddrinfo(res);
164   }
165  
166   /* parse_resvconf()
# Line 153 | Line 169 | irc_res_init(void)
169   * output - -1 if failure 0 if success
170   * side effects - fills in irc_nsaddr_list
171   */
172 < static int
172 > static void
173   parse_resvconf(void)
174   {
175    char *p;
176    char *opt;
177    char *arg;
178    char input[MAXLINE];
179 <  FBFILE *file;
179 >  FILE *file;
180  
181    /* XXX "/etc/resolv.conf" should be from a define in config.h perhaps
182     * for cygwin support etc. this hardcodes it to unix for now -db
183     */
184 <  if ((file = fbopen("/etc/resolv.conf", "r")) == NULL)
185 <    return -1;
184 >  if ((file = fopen("/etc/resolv.conf", "r")) == NULL)
185 >    return;
186  
187 <  while (fbgets(input, sizeof(input), file) != NULL)
187 >  while (fgets(input, sizeof(input), file) != NULL)
188    {
189      /* blow away any newline */
190      if ((p = strpbrk(input, "\r\n")) != NULL)
# Line 209 | Line 225 | parse_resvconf(void)
225      if ((p = strpbrk(arg, " \t")) != NULL)
226        *p = '\0';  /* take the first word */
227  
228 <    if (irccmp(opt, "domain") == 0)
213 <      strlcpy(irc_domain, arg, HOSTLEN);
214 <    else if (irccmp(opt, "nameserver") == 0)
228 >    if (!irccmp(opt, "nameserver"))
229        add_nameserver(arg);
230    }
231  
232 <  fbclose(file);
219 <  return 0;
232 >  fclose(file);
233   }
234  
235 < /* add_nameserver()
236 < *
224 < * input        - either an IPV4 address in dotted quad
225 < *                or an IPV6 address in : format
226 < * output       - NONE
227 < * side effects - entry in irc_nsaddr_list is filled in as needed
228 < */
229 < static void
230 < add_nameserver(char *arg)
235 > void
236 > irc_res_init(void)
237   {
238 <  struct addrinfo hints, *res;
239 <  /* Done max number of nameservers? */
234 <  if ((irc_nscount) >= IRCD_MAXNS)
235 <    return;
236 <
237 <  memset(&hints, 0, sizeof(hints));
238 <  hints.ai_family   = PF_UNSPEC;
239 <  hints.ai_socktype = SOCK_DGRAM;
240 <  hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
238 >  irc_nscount = 0;
239 >  memset(irc_nsaddr_list, 0, sizeof(irc_nsaddr_list));
240  
241 <  if (irc_getaddrinfo(arg, "domain", &hints, &res))
243 <    return;
241 >  parse_resvconf();
242  
243 <  if (res == NULL)
244 <    return;
247 <
248 <  memcpy(&irc_nsaddr_list[irc_nscount].ss, res->ai_addr, res->ai_addrlen);
249 <  irc_nsaddr_list[irc_nscount].ss_len = res->ai_addrlen;
250 <  irc_nscount++;
251 <  irc_freeaddrinfo(res);
243 >  if (!irc_nscount)
244 >    add_nameserver("127.0.0.1");
245   }
246  
247   /*
# Line 1134 | Line 1127 | irc_res_mkquery(
1127          HEADER *hp;
1128          unsigned char *cp;
1129          int n;
1130 <        unsigned char *dnptrs[20], **dpp, **lastdnptr;
1130 >        const unsigned char *dnptrs[20], **dpp, **lastdnptr;
1131  
1132          /*
1133           * Initialize header fields.
# Line 1157 | Line 1150 | irc_res_mkquery(
1150  
1151          if ((buflen -= QFIXEDSZ) < 0)
1152            return (-1);
1153 <        if ((n = irc_ns_name_compress(dname, cp, buflen, (const unsigned char **)dnptrs,
1154 <                                                         (const unsigned char **)lastdnptr)) < 0)
1153 >        if ((n = irc_ns_name_compress(dname, cp, buflen, dnptrs,
1154 >                                                         lastdnptr)) < 0)
1155            return (-1);
1156  
1157          cp += n;

Diff Legend

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