mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-29 20:06:38 -05:00
added new method rsGetHostByName to use gethostbyname_r for re-entrant calls. Updated dnsresolver and extaddrfinder to use it. Suggestion by GuessWho #125
This commit is contained in:
parent
f1f722a767
commit
e776effc0d
5 changed files with 90 additions and 39 deletions
|
|
@ -62,25 +62,33 @@ void *solveDNSEntries(void *p)
|
|||
|
||||
if(!next_call.empty())
|
||||
{
|
||||
hostent *pHost = gethostbyname(next_call.c_str());
|
||||
in_addr in ;
|
||||
|
||||
bool succeed = rsGetHostByName(next_call.c_str(),in);
|
||||
|
||||
{
|
||||
RsStackMutex mut(dnsr->_rdnsMtx) ;
|
||||
|
||||
{
|
||||
RsStackMutex mut(dnsr->_rdnsMtx) ;
|
||||
DNSResolver::AddrInfo &info = (*dnsr->_addr_map)[next_call];
|
||||
|
||||
DNSResolver::AddrInfo &info = (*dnsr->_addr_map)[next_call];
|
||||
|
||||
if(pHost)
|
||||
if(succeed)
|
||||
{
|
||||
info.state = DNSResolver::DNS_HAVE ;
|
||||
// IPv4 for the moment.
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &(info.addr);
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_addr= in ;
|
||||
addrv4p->sin_port = htons(0);
|
||||
|
||||
std::cerr << "LOOKUP succeeded: " << next_call.c_str() << " => " << rs_inet_ntoa(addrv4p->sin_addr) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.state = DNSResolver::DNS_HAVE ;
|
||||
// IPv4 for the moment.
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &(info.addr);
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_addr.s_addr = *(unsigned long*) (pHost->h_addr);
|
||||
addrv4p->sin_port = htons(0);
|
||||
}
|
||||
else
|
||||
info.state = DNSResolver::DNS_LOOKUP_ERROR ;
|
||||
}
|
||||
|
||||
std::cerr << "DNSResolver: lookup error for address \"" << next_call.c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue