+#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! */
+ Log( LOG_ERR, "Refused connection from %s: too may connections (%ld) from this IP!", inet_ntoa( new_addr.sin_addr ), cnt);
+ Simple_Message( new_sock, "ERROR :Connection refused, too many connections from your IP!" );
+ 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;
+ }
+
+ /* zunaechst realloc() versuchen; wenn das scheitert, malloc() versuchen
+ * und Daten ggf. "haendisch" umkopieren. (Haesslich! Eine wirklich
+ * dynamische Verwaltung waere wohl _deutlich_ besser ...) */
+ ptr = realloc( My_Connections, sizeof( CONNECTION ) * new_size );
+ if( ! ptr )
+ {
+ /* realloc() ist fehlgeschlagen. Nun malloc() probieren: */
+ ptr = malloc( sizeof( CONNECTION ) * new_size );
+ if( ! ptr )
+ {
+ /* Offenbar steht kein weiterer Sepeicher zur Verfuegung :-( */
+ Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
+ Simple_Message( new_sock, "ERROR: Internal error" );
+ close( new_sock );
+ return;
+ }
+
+ /* Struktur umkopieren ... */
+ memcpy( ptr, My_Connections, sizeof( CONNECTION ) * Pool_Size );
+
+#ifdef DEBUG
+ Log( LOG_DEBUG, "Allocated new connection pool for %ld items (%ld bytes). [malloc()/memcpy()]", new_size, sizeof( CONNECTION ) * new_size );
+#endif
+ }
+#ifdef DEBUG
+ else 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 = 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;
+ }