if(cache->ai) {
if(cache->aip) {
- sockaddr_t *sa = (sockaddr_t *)cache->aip;
+ sockaddr_t *sa = (sockaddr_t *)cache->aip->ai_addr;
if(find_cached(cache, sa) != NOT_CACHED) {
continue;
cache->cfg = lookup_config_next(cache->config_tree, cache->cfg);
}
- if(cache->aip) {
- sockaddr_t *sa = (sockaddr_t *)cache->aip->ai_addr;
- cache->aip = cache->aip->ai_next;
+ if(cache->ai) {
+ if(cache->aip) {
+ sockaddr_t *sa = (sockaddr_t *)cache->aip->ai_addr;
- if(!cache->aip) {
+ cache->aip = cache->aip->ai_next;
+ return sa;
+ } else {
freeaddrinfo(cache->ai);
- cache->ai = cache->aip = NULL;
+ cache->ai = NULL;
}
-
- return sa;
}
// We're all out of addresses.
int flags = fcntl(c->socket, F_GETFL);
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) {
- logger(DEBUG_ALWAYS, LOG_ERR, "fcntl for %s: %s", c->hostname, strerror(errno));
+ logger(DEBUG_ALWAYS, LOG_ERR, "fcntl for %s fd %d: %s", c->hostname, c->socket, strerror(errno));
}
#elif defined(WIN32)
unsigned long arg = 1;
if(ioctlsocket(c->socket, FIONBIO, &arg) != 0) {
- logger(DEBUG_ALWAYS, LOG_ERR, "ioctlsocket for %s: %s", c->hostname, sockstrerror(sockerrno));
+ logger(DEBUG_ALWAYS, LOG_ERR, "ioctlsocket for %s fd %d: %s", c->hostname, c->socket, sockstrerror(sockerrno));
}
#endif
connection_t *c = new_connection();
c->outgoing = outgoing;
- c->address = *sa;
+ memcpy(&c->address, sa, SALEN(sa->sa));
c->hostname = sockaddr2hostname(&c->address);
logger(DEBUG_CONNECTIONS, LOG_INFO, "Trying to connect to %s (%s)", outgoing->node->name, c->hostname);