+} /* Handle_Buffer */
+
+
+LOCAL VOID Check_Connections( VOID )
+{
+ /* Pruefen, ob Verbindungen noch "alive" sind */
+
+ INT i;
+
+ for( i = 0; i < MAX_CONNECTIONS; i++ )
+ {
+ if( My_Connections[i].sock != NONE )
+ {
+ if( My_Connections[i].lastping > My_Connections[i].lastdata )
+ {
+ /* es wurde bereits ein PING gesendet */
+ if( My_Connections[i].lastping < time( NULL ) - Conf_PongTimeout )
+ {
+ /* Timeout */
+ Log( LOG_INFO, "Connection %d: Ping timeout.", i );
+ Conn_Close( i, "Ping timeout" );
+ }
+ }
+ else if( My_Connections[i].lastdata < time( NULL ) - Conf_PingTimeout )
+ {
+ /* es muss ein PING gesendet werden */
+ Log( LOG_DEBUG, "Connection %d: sending PING ...", i );
+ My_Connections[i].lastping = time( NULL );
+ Conn_WriteStr( i, "PING :%s", This_Server->nick );
+ }
+ }
+ }
+} /* Conn_Check */
+
+
+LOCAL VOID Init_Conn_Struct( INT Idx )
+{
+ /* Connection-Struktur initialisieren */
+
+ My_Connections[Idx].sock = NONE;
+ My_Connections[Idx].res_stat = NULL;
+ My_Connections[Idx].host[0] = '\0';
+ My_Connections[Idx].rbuf[0] = '\0';
+ My_Connections[Idx].rdatalen = 0;
+ My_Connections[Idx].wbuf[0] = '\0';
+ My_Connections[Idx].wdatalen = 0;
+ My_Connections[Idx].lastdata = time( NULL );
+ My_Connections[Idx].lastping = 0;
+} /* Init_Conn_Struct */
+
+
+LOCAL RES_STAT *Resolve( struct sockaddr_in *Addr )
+{
+ /* Hostnamen (asyncron!) aufloesen. Bei Fehler, z.B. wenn der
+ * Child-Prozess nicht erzeugt werden kann, wird NULL geliefert.
+ * Der Host kann dann nicht aufgeloest werden. */
+
+ RES_STAT *s;
+ INT pid;
+
+ s = malloc( sizeof( RES_STAT ));
+ if( ! s )
+ {
+ Log( LOG_ALERT, "Resolver: Can't alloc memory!" );
+ return NULL;
+ }
+
+ if( pipe( s->pipe ) != 0 )
+ {
+ free( s );
+ Log( LOG_ALERT, "Resolver: Can't create output pipe: %s!", strerror( errno ));
+ return NULL;
+ }
+
+ pid = fork( );
+ if( pid > 0 )
+ {
+ /* Haupt-Prozess */
+ Log( LOG_DEBUG, "Resolver process for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid );
+ FD_SET( s->pipe[0], &My_Resolvers );
+ if( s->pipe[0] > My_Max_Fd ) My_Max_Fd = s->pipe[0];
+ s->pid = pid;
+ return s;
+ }
+ else if( pid == 0 )
+ {
+ /* Sub-Prozess */
+ Log_Init_Resolver( );
+ Do_Resolve( Addr, s->pipe[1] );
+ Log_Exit_Resolver( );
+ exit( 0 );
+ }
+ else
+ {
+ /* Fehler */
+ free( s );
+ Log( LOG_ALERT, "Resolver: Can't fork: %s!", strerror( errno ));
+ return NULL;
+ }
+} /* Resolve */
+
+
+LOCAL VOID Read_Resolver_Result( INT r_fd )
+{
+ /* Ergebnis von Resolver Sub-Prozess aus Pipe lesen
+ * und entsprechende Connection aktualisieren */
+
+ CHAR hostname[HOST_LEN];
+ CLIENT *c;
+ INT i;
+
+ FD_CLR( r_fd, &My_Resolvers );
+
+ /* Anfrage vom Parent lesen */
+ if( read( r_fd, hostname, HOST_LEN) < 0 )
+ {
+ /* Fehler beim Lesen aus der Pipe */
+ close( r_fd );
+ Log( LOG_ALERT, "Resolver: Can't read result: %s!", strerror( errno ));
+ return;
+ }
+
+ for( i = 0; i < MAX_CONNECTIONS; i++ )
+ {
+ /* zugehoerige Connection suchen */
+ if(( My_Connections[i].sock >= 0 ) && ( My_Connections[i].res_stat ) && ( My_Connections[i].res_stat->pipe[0] == r_fd )) break;
+ }
+
+ if( i >= MAX_CONNECTIONS )
+ {
+ /* Opsa! Keine passende Connection gefunden!? */
+ close( r_fd );
+ Log( LOG_ALERT, "Resolver: Got result for unknown connection!?" );
+ return;
+ }
+
+ /* Aufraeumen */
+ close( My_Connections[i].res_stat->pipe[0] );
+ close( My_Connections[i].res_stat->pipe[1] );
+ free( My_Connections[i].res_stat );
+ My_Connections[i].res_stat = NULL;
+
+ /* Hostnamen setzen */
+ strcpy( My_Connections[i].host, hostname );
+ c = Client_GetFromConn( i );
+ if( c ) Client_SetHostname( c, hostname );
+} /* Read_Resolver_Result */
+
+
+LOCAL VOID Do_Resolve( struct sockaddr_in *Addr, INT w_fd )
+{
+ /* Resolver Sub-Prozess: aufzuloesenden Namen aus
+ * der Pipe lesen, Ergebnis in Pipe schreiben. */
+
+ CHAR hostname[HOST_LEN];
+ struct hostent *h;
+
+ Log_Resolver( LOG_DEBUG, "Now resolving %s ...", inet_ntoa( Addr->sin_addr ));
+
+ /* Namen aufloesen */
+ h = gethostbyaddr( (CHAR *)&Addr->sin_addr, sizeof( Addr->sin_addr ), AF_INET );
+ if( h ) strcpy( hostname, h->h_name );
+ else
+ {
+ Log_Resolver( LOG_WARNING, "Resolver: Can't resolve host name (code %d)!", h_errno );
+ strcpy( hostname, inet_ntoa( Addr->sin_addr ));
+ }
+
+ /* Antwort an Parent schreiben */
+ if( write( w_fd, hostname, strlen( hostname ) + 1 ) != ( strlen( hostname ) + 1 ))
+ {
+ Log_Resolver( LOG_ALERT, "Resolver: Can't write to parent: %s!", strerror( errno ));
+ close( w_fd );
+ return;
+ }
+
+ Log_Resolver( LOG_DEBUG, "Ok, translated %s to \"%s\".", inet_ntoa( Addr->sin_addr ), hostname );
+} /* Do_Resolve */