comparison src/dnsbl.cpp @ 409:e018ed19a1cc

require 3 dots in bare ip addresses
author Carl Byington <carl@five-ten-sg.com>
date Sun, 16 Apr 2017 09:06:52 -0700
parents 9096d2676c13
children 6b03435868cb
comparison
equal deleted inserted replaced
408:067963dc142f 409:e018ed19a1cc
314 // this part can be done without locking the resolver mutex. Each 314 // this part can be done without locking the resolver mutex. Each
315 // milter thread is talking over its own socket to a separate resolver 315 // milter thread is talking over its own socket to a separate resolver
316 // process, which does the actual dns resolution. 316 // process, which does the actual dns resolution.
317 if (priv.err) return 0; // cannot ask more questions on this socket. 317 if (priv.err) return 0; // cannot ask more questions on this socket.
318 if (maybe_ip && (qtype == ns_t_a)) { 318 if (maybe_ip && (qtype == ns_t_a)) {
319 // might be a bare ip address, try this first to avoid dns lookups that may not be needed 319 int c = 0;
320 const char q = question;
321 while (*q) {
322 if (*q == '.') c++;
323 q++;
324 }
325 // might be a bare IPv4 address, try this first to avoid dns lookups that may not be needed
320 in_addr ip; 326 in_addr ip;
321 if (inet_aton(question, &ip)) { 327 if ((c == 3) && inet_aton(question, &ip)) {
322 return ip.s_addr; 328 return ip.s_addr;
323 } 329 }
324 } 330 }
325 int8_t qt = qtype; 331 int8_t qt = qtype;
326 priv.my_write((const char *)&qt, 1);// write the query type 332 priv.my_write((const char *)&qt, 1);// write the query type