+ n = lookup_node(name);
+
+ if(n)
+ if(n->connection)
+ {
+ if(debug_lvl >= DEBUG_CONNECTIONS)
+ syslog(LOG_INFO, _("Already connected to %s"), name);
+ return 0;
+ }
+
+ c = new_connection();
+ c->name = xstrdup(name);
+
+ init_configuration(&c->config_tree);
+ read_connection_config(c);
+
+ if(!get_config_string(lookup_config(c->config_tree, "Address"), &c->hostname))
+ {
+ syslog(LOG_ERR, _("No address specified for %s"), c->name);
+ free_connection(c);
+ return -1;
+ }
+
+ if(!get_config_string(lookup_config(c->config_tree, "Port"), &c->port))
+ {
+ syslog(LOG_ERR, _("No port specified for %s"), c->name);
+ free_connection(c);
+ return -1;
+ }
+
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_family = AF_INET;
+ if(get_config_bool(lookup_config(c->config_tree, "IPv6Preferred"), &ipv6preferred))
+ {
+ if(ipv6preferred)
+ hints.ai_family = PF_UNSPEC;
+ }
+
+ if((r = getaddrinfo(c->hostname, c->port, &hints, &aitop)) != 0)
+ {
+ syslog(LOG_ERR, _("Looking up %s failed: %s\n"),
+ c->hostname, gai_strerror(r));
+ return -1;
+ }
+
+ for(ai = aitop; ai != NULL; ai = ai->ai_next)
+ {
+ if(setup_outgoing_socket(c) < 0)
+ continue;
+ }