+#endif
+
+ /* Socket initialisieren */
+ Init_Socket( new_sock );
+
+ /* Check IP-based connection limit */
+ cnt = Count_Connections( new_addr );
+ if(( Conf_MaxConnectionsIP > 0 ) && ( cnt >= Conf_MaxConnectionsIP ))
+ {
+ /* Access denied, too many connections from this IP address! */
+ Log( LOG_ERR, "Refused connection from %s: too may connections (%ld) from this IP address!", inet_ntoa( new_addr.sin_addr ), cnt);
+ Simple_Message( new_sock, "ERROR :Connection refused, too many connections from your IP address!" );
+ close( new_sock );
+ return;
+ }
+
+ /* Freie Connection-Struktur suchen */
+ for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == NONE ) break;
+ if( idx >= Pool_Size )
+ {
+ new_size = Pool_Size + CONNECTION_POOL;
+
+ /* Im bisherigen Pool wurde keine freie Connection-Struktur mehr gefunden.
+ * Wenn erlaubt und moeglich muss nun der Pool vergroessert werden: */
+
+ if( Conf_MaxConnections > 0 )
+ {
+ /* Es ist ein Limit konfiguriert */
+ if( Pool_Size >= Conf_MaxConnections )
+ {
+ /* Mehr Verbindungen duerfen wir leider nicht mehr annehmen ... */
+ Log( LOG_ALERT, "Can't accept connection: limit (%d) reached!", Pool_Size );
+ Simple_Message( new_sock, "ERROR :Connection limit reached" );
+ close( new_sock );
+ return;
+ }
+ if( new_size > Conf_MaxConnections ) new_size = Conf_MaxConnections;
+ }
+ if( new_size < Pool_Size )
+ {
+ Log( LOG_ALERT, "Can't accespt connection: limit (%d) reached -- overflow!", Pool_Size );
+ Simple_Message( new_sock, "ERROR :Connection limit reached" );
+ close( new_sock );
+ return;
+ }
+
+ ptr = (POINTER *)realloc( My_Connections, sizeof( CONNECTION ) * new_size );
+ if( ! ptr )
+ {
+ Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
+ Simple_Message( new_sock, "ERROR: Internal error" );
+ close( new_sock );
+ return;
+ }
+
+#ifdef DEBUG
+ Log( LOG_DEBUG, "Allocated new connection pool for %ld items (%ld bytes). [realloc()]", new_size, sizeof( CONNECTION ) * new_size );
+#endif
+
+ /* Adjust pointer to new block */
+ My_Connections = (CONNECTION *)ptr;
+
+ /* Initialize new items */
+ for( idx = Pool_Size; idx < new_size; idx++ ) Init_Conn_Struct( idx );
+ idx = Pool_Size;
+
+ /* Adjust new pool size */
+ Pool_Size = new_size;
+ }