+
+ /* Check last connect attempt? */
+ if( Conf_Server[i].lasttry > time( NULL ) - Conf_ConnectRetry ) continue;
+
+ /* Okay, try to connect now */
+ Conf_Server[i].lasttry = time( NULL );
+
+ /* Search free connection structure */
+ for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == NONE ) break;
+ if( idx >= Pool_Size )
+ {
+ Log( LOG_ALERT, "Can't establist server connection: connection limit reached (%d)!", Pool_Size );
+ return;
+ }
+ Log( LOG_DEBUG, "Preparing connection %d for \"%s\" ...", idx, Conf_Server[i].host );
+
+ /* Verbindungs-Struktur initialisieren */
+ Init_Conn_Struct( idx );
+ My_Connections[idx].sock = SERVER_WAIT;
+ Conf_Server[i].conn_id = idx;
+
+ /* Resolve Hostname. If this fails, try to use it as an IP address */
+ strlcpy( Conf_Server[i].ip, Conf_Server[i].host, sizeof( Conf_Server[i].ip ));
+ strlcpy( My_Connections[idx].host, Conf_Server[i].host, sizeof( My_Connections[idx].host ));
+ s = Resolve_Name( Conf_Server[i].host );
+ if( s )
+ {
+ /* Sub-Prozess wurde asyncron gestartet */
+ My_Connections[idx].res_stat = s;
+ }
+ }
+} /* Check_Servers */
+
+
+LOCAL VOID
+New_Server( INT Server, CONN_ID Idx )
+{
+ /* Neue Server-Verbindung aufbauen */
+
+ struct sockaddr_in new_addr;
+ struct in_addr inaddr;
+ INT res, new_sock;
+ CLIENT *c;
+
+ assert( Server > NONE );
+ assert( Idx > NONE );
+
+ /* Wurde eine gueltige IP-Adresse gefunden? */
+ if( ! Conf_Server[Server].ip[0] )
+ {
+ /* Nein. Verbindung wieder freigeben: */
+ Init_Conn_Struct( Idx );
+ Log( LOG_ERR, "Can't connect to \"%s\" (connection %d): ip address unknown!", Conf_Server[Server].host, Idx );
+ return;
+ }
+
+ Log( LOG_INFO, "Establishing connection to \"%s\", %s, port %d (connection %d) ... ", Conf_Server[Server].host, Conf_Server[Server].ip, Conf_Server[Server].port, Idx );
+
+#ifdef HAVE_INET_ATON
+ if( inet_aton( Conf_Server[Server].ip, &inaddr ) == 0 )
+#else
+ memset( &inaddr, 0, sizeof( inaddr ));
+ inaddr.s_addr = inet_addr( Conf_Server[Server].ip );
+ if( inaddr.s_addr == (unsigned)-1 )
+#endif
+ {
+ /* Konnte Adresse nicht konvertieren */
+ Init_Conn_Struct( Idx );
+ Log( LOG_ERR, "Can't connect to \"%s\" (connection %d): can't convert ip address %s!", Conf_Server[Server].host, Idx, Conf_Server[Server].ip );
+ return;
+ }
+
+ memset( &new_addr, 0, sizeof( new_addr ));
+ new_addr.sin_family = AF_INET;
+ new_addr.sin_addr = inaddr;
+ new_addr.sin_port = htons( Conf_Server[Server].port );
+
+ new_sock = socket( PF_INET, SOCK_STREAM, 0 );
+ if ( new_sock < 0 )
+ {
+ Init_Conn_Struct( Idx );
+ Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
+ return;
+ }
+
+ if( ! Init_Socket( new_sock )) return;
+
+ res = connect( new_sock, (struct sockaddr *)&new_addr, sizeof( new_addr ));
+ if(( res != 0 ) && ( errno != EINPROGRESS ))
+ {
+ Log( LOG_CRIT, "Can't connect socket: %s!", strerror( errno ));
+ close( new_sock );
+ Init_Conn_Struct( Idx );
+ return;
+ }
+
+ /* Client-Struktur initialisieren */
+ c = Client_NewLocal( Idx, inet_ntoa( new_addr.sin_addr ), CLIENT_UNKNOWNSERVER, FALSE );
+ if( ! c )
+ {
+ close( new_sock );
+ Init_Conn_Struct( Idx );
+ Log( LOG_ALERT, "Can't establish connection: can't create client structure!" );
+ return;