resolve.cc (608B)
1 #include "dnsentry" 2 3 in_addr_t &DNSEntry::resolve (string const &h) { 4 // If the entry is there and if it's up to date, run with it 5 if (result && timestamp.elapsed() <= (double)config.dnscachetimeout()) 6 return result; 7 8 // Resolve now. 9 struct hostent *hostaddr; 10 mutex_lock((void*)gethostbyname); 11 if ( (hostaddr = gethostbyname(h.c_str())) ) 12 memcpy (&result, hostaddr->h_addr_list[0], hostaddr->h_length); 13 mutex_unlock((void*)gethostbyname); 14 15 if (!hostaddr) 16 throw Error("Failed to resolve host '" + h + "'"); 17 18 debugmsg("Host " << h << " resolved\n"); 19 return result; 20 }