]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conn.c
- Verbindungen mit Lesefehlern werden nun korrekt terminiert.
[ngircd-alex.git] / src / ngircd / conn.c
index 2e896a28187d33f6d2dcadc876f49284078a3350..70b4cf7df4c2b3fe8e27f49f1659e48d37b6b0fd 100644 (file)
@@ -9,11 +9,27 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: conn.c,v 1.8 2001/12/23 22:02:54 alex Exp $
+ * $Id: conn.c,v 1.13 2001/12/26 03:36:57 alex Exp $
  *
  * connect.h: Verwaltung aller Netz-Verbindungen ("connections")
  *
  * $Log: conn.c,v $
+ * Revision 1.13  2001/12/26 03:36:57  alex
+ * - Verbindungen mit Lesefehlern werden nun korrekt terminiert.
+ *
+ * Revision 1.12  2001/12/26 03:20:53  alex
+ * - PING/PONG-Timeout implementiert.
+ *
+ * Revision 1.11  2001/12/25 23:15:16  alex
+ * - buffer werden nun periodisch geprueft, keine haengenden Clients mehr.
+ *
+ * Revision 1.10  2001/12/25 22:03:47  alex
+ * - Conn_Close() eingefuehrt: war die lokale Funktion Close_Connection().
+ *
+ * Revision 1.9  2001/12/24 01:32:33  alex
+ * - in Conn_WriteStr() wurde das CR+LF nicht angehaengt!
+ * - Fehler-Ausgaben vereinheitlicht.
+ *
  * Revision 1.8  2001/12/23 22:02:54  alex
  * - Conn_WriteStr() nimmt nun variable Parameter,
  * - diverse kleinere Aenderungen.
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
-#include <sys/socket.h> 
+#include <sys/socket.h>
 #include <sys/time.h>
-#include <sys/types.h> 
+#include <sys/types.h>
+#include <time.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
@@ -71,6 +88,7 @@
 
 #include "ngircd.h"
 #include "client.h"
+#include "conf.h"
 #include "log.h"
 #include "parse.h"
 #include "tool.h"
@@ -95,6 +113,8 @@ typedef struct _Connection
        INT rdatalen;                   /* Laenge der Daten im Lesepuffer */
        CHAR wbuf[WRITEBUFFER_LEN + 1]; /* Schreibpuffer */
        INT wdatalen;                   /* Laenge der Daten im Schreibpuffer */
+       time_t lastdata;                /* Letzte Aktivitaet */
+       time_t lastping;                /* Letzter PING */
 } CONNECTION;
 
 
@@ -102,9 +122,10 @@ LOCAL VOID Handle_Read( INT sock );
 LOCAL BOOLEAN Handle_Write( CONN_ID Idx );
 LOCAL VOID New_Connection( INT Sock );
 LOCAL CONN_ID Socket2Index( INT Sock );
-LOCAL VOID Close_Connection( CONN_ID Idx, CHAR *Msg );
 LOCAL VOID Read_Request( CONN_ID Idx );
 LOCAL BOOLEAN Try_Write( CONN_ID Idx );
+LOCAL VOID Handle_Buffer( CONN_ID Idx );
+LOCAL VOID Check_Connections( VOID );
 
 
 LOCAL fd_set My_Listener;
@@ -122,9 +143,9 @@ GLOBAL VOID Conn_Init( VOID )
        /* zu Beginn haben wir keine Verbindungen */
        FD_ZERO( &My_Listener );
        FD_ZERO( &My_Sockets );
-       
+
        My_Max_Fd = 0;
-       
+
        /* Connection-Struktur initialisieren */
        for( i = 0; i < MAX_CONNECTIONS; i++ ) My_Connections[i].sock = NONE;
 } /* Conn_Init */
@@ -134,7 +155,7 @@ GLOBAL VOID Conn_Exit( VOID )
 {
        CONN_ID idx;
        INT i;
-       
+
        /* Sockets schliessen */
        for( i = 0; i < My_Max_Fd + 1; i++ )
        {
@@ -144,7 +165,7 @@ GLOBAL VOID Conn_Exit( VOID )
                        {
                                if( My_Connections[idx].sock == i ) break;
                        }
-                       if( idx < MAX_CONNECTIONS ) Close_Connection( idx, "Server going down ..." );
+                       if( idx < MAX_CONNECTIONS ) Conn_Close( idx, "Server going down ..." );
                        else if( FD_ISSET( i, &My_Listener ))
                        {
                                close( i );
@@ -178,27 +199,27 @@ GLOBAL BOOLEAN Conn_New_Listener( CONST INT Port )
        sock = socket( PF_INET, SOCK_STREAM, 0);
        if( sock < 0 )
        {
-               Log( LOG_ALERT, "Can't create socket: %s", strerror( errno ));
+               Log( LOG_ALERT, "Can't create socket: %s!", strerror( errno ));
                return FALSE;
        }
 
        /* Socket-Optionen setzen */
        if( fcntl( sock, F_SETFL, O_NONBLOCK ) != 0 )
        {
-               Log( LOG_ALERT, "Can't enable non-blocking mode: %s", strerror( errno ));
+               Log( LOG_ALERT, "Can't enable non-blocking mode: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
        if( setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &on, (socklen_t)sizeof( on )) != 0)
        {
-               Log( LOG_CRIT, "Can't set socket options: %s", strerror( errno ));
+               Log( LOG_CRIT, "Can't set socket options: %s!", strerror( errno ));
                /* dieser Fehler kann ignoriert werden. */
        }
 
        /* an Port binden */
        if( bind( sock, (struct sockaddr *)&addr, (socklen_t)sizeof( addr )) != 0 )
        {
-               Log( LOG_ALERT, "Can't bind socket: %s", strerror( errno ));
+               Log( LOG_ALERT, "Can't bind socket: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
@@ -206,7 +227,7 @@ GLOBAL BOOLEAN Conn_New_Listener( CONST INT Port )
        /* in "listen mode" gehen :-) */
        if( listen( sock, 10 ) != 0 )
        {
-               Log( LOG_ALERT, "Can't listen on soecket: %s", strerror( errno ));
+               Log( LOG_ALERT, "Can't listen on soecket: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
@@ -214,7 +235,7 @@ GLOBAL BOOLEAN Conn_New_Listener( CONST INT Port )
        /* Neuen Listener in Strukturen einfuegen */
        FD_SET( sock, &My_Listener );
        FD_SET( sock, &My_Sockets );
-       
+
        if( sock > My_Max_Fd ) My_Max_Fd = sock;
 
        Log( LOG_INFO, "Now listening on port %d, socket %d.", Port, sock );
@@ -227,40 +248,57 @@ GLOBAL VOID Conn_Handler( INT Timeout )
 {
        fd_set read_sockets, write_sockets;
        struct timeval tv;
+       time_t start;
        INT i;
 
-       /* Timeout initialisieren */
-       tv.tv_sec = Timeout;
-       tv.tv_usec = 0;
-       
-       /* noch volle Schreib-Puffer suchen */
-       FD_ZERO( &write_sockets );
-       for( i = 0; i < MAX_CONNECTIONS; i++ )
+       start = time( NULL );
+       while(( time( NULL ) - start < Timeout ) && ( ! NGIRCd_Quit ))
        {
-               if(( My_Connections[i].sock >= 0 ) && ( My_Connections[i].wdatalen > 0 ))
+               Check_Connections( );
+
+               /* Timeout initialisieren */
+               tv.tv_sec = 0;
+               tv.tv_usec = 50000;
+
+               /* noch volle Lese-Buffer suchen */
+               for( i = 0; i < MAX_CONNECTIONS; i++ )
                {
-                       /* Socket der Verbindung in Set aufnehmen */
-                       FD_SET( My_Connections[i].sock, &write_sockets );
+                       if(( My_Connections[i].sock >= 0 ) && ( My_Connections[i].rdatalen > 0 ))
+                       {
+                               /* Kann aus dem Buffer noch ein Befehl extrahiert werden? */
+                               Handle_Buffer( i );
+                       }
+               }
+               
+               /* noch volle Schreib-Puffer suchen */
+               FD_ZERO( &write_sockets );
+               for( i = 0; i < MAX_CONNECTIONS; i++ )
+               {
+                       if(( My_Connections[i].sock >= 0 ) && ( My_Connections[i].wdatalen > 0 ))
+                       {
+                               /* Socket der Verbindung in Set aufnehmen */
+                               FD_SET( My_Connections[i].sock, &write_sockets );
+                       }
+               }
+               
+               read_sockets = My_Sockets;
+               if( select( My_Max_Fd + 1, &read_sockets, &write_sockets, NULL, &tv ) == -1 )
+               {
+                       if( errno != EINTR ) Log( LOG_ALERT, "select(): %s!", strerror( errno ));
+                       return;
+               }
+
+               /* Koennen Daten geschrieben werden? */
+               for( i = 0; i < My_Max_Fd + 1; i++ )
+               {
+                       if( FD_ISSET( i, &write_sockets )) Handle_Write( Socket2Index( i ));
+               }
+
+               /* Daten zum Lesen vorhanden? */
+               for( i = 0; i < My_Max_Fd + 1; i++ )
+               {
+                       if( FD_ISSET( i, &read_sockets )) Handle_Read( i );
                }
-       }
-       
-       read_sockets = My_Sockets;
-       if( select( My_Max_Fd + 1, &read_sockets, &write_sockets, NULL, &tv ) == -1 )
-       {
-               if( errno != EINTR ) Log( LOG_ALERT, "select(): %s", strerror( errno ));
-               return;
-       }
-       
-       /* Koennen Daten geschrieben werden? */
-       for( i = 0; i < My_Max_Fd + 1; i++ )
-       {
-               if( FD_ISSET( i, &write_sockets )) Handle_Write( Socket2Index( i ));
-       }
-       
-       /* Daten zum Lesen vorhanden? */
-       for( i = 0; i < My_Max_Fd + 1; i++ )
-       {
-               if( FD_ISSET( i, &read_sockets )) Handle_Read( i );
        }
 } /* Conn_Handler */
 
@@ -270,24 +308,26 @@ GLOBAL BOOLEAN Conn_WriteStr( CONN_ID Idx, CHAR *Format, ... )
        /* String in Socket schreiben. CR+LF wird von dieser Funktion
         * automatisch angehaengt. Im Fehlerfall wird dir Verbindung
         * getrennt und FALSE geliefert. */
-       
+
        CHAR buffer[MAX_CMDLEN];
        BOOLEAN ok;
        va_list ap;
 
        va_start( ap, Format );
-       if( vsnprintf( buffer, MAX_CMDLEN, Format, ap ) == MAX_CMDLEN )
+       if( vsnprintf( buffer, MAX_CMDLEN - 2, Format, ap ) == MAX_CMDLEN - 2 )
        {
                Log( LOG_ALERT, "String too long to send (connection %d)!", Idx );
-               Close_Connection( Idx, "Server error: String too long to send!" );
+               Conn_Close( Idx, "Server error: String too long to send!" );
                return FALSE;
        }
-       ok = Conn_Write( Idx, buffer, strlen( buffer ));
 
-#ifdef DEBUG
+#ifdef SNIFFER
        Log( LOG_DEBUG, " -> connection %d: '%s'.", Idx, buffer );
 #endif
 
+       strcat( buffer, "\r\n" );
+       ok = Conn_Write( Idx, buffer, strlen( buffer ));
+
        va_end( ap );
        return ok;
 } /* Conn_WriteStr */
@@ -297,7 +337,7 @@ GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
 {
        /* Daten in Socket schreiben. Bei "fatalen" Fehlern wird
         * der Client disconnectiert und FALSE geliefert. */
-       
+
        assert( Idx >= 0 );
        assert( My_Connections[Idx].sock >= 0 );
        assert( Data != NULL );
@@ -309,13 +349,13 @@ GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
        {
                if( ! Try_Write( Idx )) return FALSE;
        }
-       
+
        /* pruefen, ob im Schreibpuffer genuegend Platz ist */
        if( WRITEBUFFER_LEN - My_Connections[Idx].wdatalen - Len <= 0 )
        {
                /* der Puffer ist dummerweise voll ... */
                Log( LOG_NOTICE, "Write buffer overflow (connection %d)!", Idx );
-               Close_Connection( Idx, NULL );
+               Conn_Close( Idx, NULL );
                return FALSE;
        }
 
@@ -328,18 +368,44 @@ GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
        {
                if( ! Try_Write( Idx )) return FALSE;
        }
-       
+
        return TRUE;
 } /* Conn_Write */
 
 
+GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *Msg )
+{
+       /* Verbindung schliessen */
+
+       assert( Idx >= 0 );
+       assert( My_Connections[Idx].sock >= 0 );
+
+       if( Msg ) Conn_WriteStr( Idx, "ERROR :%s", Msg );
+
+       if( close( My_Connections[Idx].sock ) != 0 )
+       {
+               Log( LOG_ERR, "Error closing connection %d with %s:%d - %s!", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port), strerror( errno ));
+               return;
+       }
+       else
+       {
+               Log( LOG_NOTICE, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port ));
+       }
+
+       Client_Destroy( Client_GetFromConn( Idx ));
+
+       FD_CLR( My_Connections[Idx].sock, &My_Sockets );
+       My_Connections[Idx].sock = NONE;
+} /* Conn_Close */
+
+
 LOCAL BOOLEAN Try_Write( CONN_ID Idx )
 {
        /* Versuchen, Daten aus dem Schreib-Puffer in den
         * Socket zu schreiben. */
 
        fd_set write_socket;
-       
+
        assert( Idx >= 0 );
        assert( My_Connections[Idx].sock >= 0 );
        assert( My_Connections[Idx].wdatalen > 0 );
@@ -351,8 +417,8 @@ LOCAL BOOLEAN Try_Write( CONN_ID Idx )
                /* Fehler! */
                if( errno != EINTR )
                {
-                       Log( LOG_ALERT, "select(): %s", strerror( errno ));
-                       Close_Connection( Idx, NULL );
+                       Log( LOG_ALERT, "select(): %s!", strerror( errno ));
+                       Conn_Close( Idx, NULL );
                        return FALSE;
                }
        }
@@ -367,7 +433,7 @@ LOCAL VOID Handle_Read( INT Sock )
        /* Aktivitaet auf einem Socket verarbeiten */
 
        CONN_ID idx;
-       
+
        assert( Sock >= 0 );
 
        if( FD_ISSET( Sock, &My_Listener ))
@@ -380,7 +446,7 @@ LOCAL VOID Handle_Read( INT Sock )
        else
        {
                /* Ein Client Socket: entweder ein User oder Server */
-               
+
                idx = Socket2Index( Sock );
                Read_Request( idx );
        }
@@ -390,27 +456,27 @@ LOCAL VOID Handle_Read( INT Sock )
 LOCAL BOOLEAN Handle_Write( CONN_ID Idx )
 {
        /* Daten aus Schreibpuffer versenden */
-       
+
        INT len;
 
        assert( Idx >= 0 );
        assert( My_Connections[Idx].sock >= 0 );
        assert( My_Connections[Idx].wdatalen > 0 );
-               
+
        /* Daten schreiben */
        len = send( My_Connections[Idx].sock, My_Connections[Idx].wbuf, My_Connections[Idx].wdatalen, 0 );
        if( len < 0 )
        {
                /* Oops, ein Fehler! */
-               Log( LOG_ALERT, "Write error (buffer) on connection %d: %s", Idx, strerror( errno ));
-               Close_Connection( Idx, NULL );
+               Log( LOG_ALERT, "Write error (buffer) on connection %d: %s!", Idx, strerror( errno ));
+               Conn_Close( Idx, NULL );
                return FALSE;
        }
-       
+
        /* Puffer anpassen */
        My_Connections[Idx].wdatalen -= len;
        memmove( My_Connections[Idx].wbuf, My_Connections[Idx].wbuf + len, My_Connections[Idx].wdatalen );
-       
+
        return TRUE;
 } /* Handle_Write */
 
@@ -423,17 +489,17 @@ LOCAL VOID New_Connection( INT Sock )
        struct sockaddr_in new_addr;
        INT new_sock, new_sock_len;
        CONN_ID idx;
-       
+
        assert( Sock >= 0 );
 
        new_sock_len = sizeof( new_addr );
        new_sock = accept( Sock, (struct sockaddr *)&new_addr, (socklen_t *)&new_sock_len );
        if( new_sock < 0 )
        {
-               Log( LOG_CRIT, "Can't accept connection: %s", strerror( errno ));
+               Log( LOG_CRIT, "Can't accept connection: %s!", strerror( errno ));
                return;
        }
-               
+
        /* Freie Connection-Struktur suschen */
        for( idx = 0; idx < MAX_CONNECTIONS; idx++ ) if( My_Connections[idx].sock < 0 ) break;
        if( idx >= MAX_CONNECTIONS )
@@ -442,7 +508,7 @@ LOCAL VOID New_Connection( INT Sock )
                close( new_sock );
                return;
        }
-       
+
        /* Client-Struktur initialisieren */
        if( ! Client_New_Local( idx, inet_ntoa( new_addr.sin_addr )))
        {
@@ -450,12 +516,14 @@ LOCAL VOID New_Connection( INT Sock )
                close( new_sock );
                return;
        }
-       
+
        /* Verbindung registrieren */
        My_Connections[idx].sock = new_sock;
        My_Connections[idx].addr = new_addr;
        My_Connections[idx].rdatalen = 0;
        My_Connections[idx].wdatalen = 0;
+       My_Connections[idx].lastdata = time( NULL );
+       My_Connections[idx].lastping = 0;
 
        /* Neuen Socket registrieren */
        FD_SET( new_sock, &My_Sockets );
@@ -471,52 +539,26 @@ LOCAL CONN_ID Socket2Index( INT Sock )
        /* zum Socket passende Connection suchen */
 
        CONN_ID idx;
-       
+
        assert( Sock >= 0 );
-       
+
        for( idx = 0; idx < MAX_CONNECTIONS; idx++ ) if( My_Connections[idx].sock == Sock ) break;
-       
+
        assert( idx < MAX_CONNECTIONS );
        return idx;
 } /* Socket2Index */
 
 
-LOCAL VOID Close_Connection( CONN_ID Idx, CHAR *Msg )
-{
-       /* Verbindung schlie§en */
-
-       assert( Idx >= 0 );
-       assert( My_Connections[Idx].sock >= 0 );
-       
-       if( Msg ) Conn_WriteStr( Idx, "ERROR :%s", Msg );
-
-       if( close( My_Connections[Idx].sock ) != 0 )
-       {
-               Log( LOG_ERR, "Error closing connection %d with %s:%d - %s", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port), strerror( errno ));
-       }
-       else
-       {
-               Log( LOG_NOTICE, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port ));
-       }
-
-       Client_Destroy( Client_GetFromConn( Idx ));
-       
-       FD_CLR( My_Connections[Idx].sock, &My_Sockets );
-       My_Connections[Idx].sock = NONE;
-} /* Close_Connection */
-
-
 LOCAL VOID Read_Request( CONN_ID Idx )
 {
        /* Daten von Socket einlesen und entsprechend behandeln.
         * Tritt ein Fehler auf, so wird der Socket geschlossen. */
 
        INT len;
-       CHAR *ptr;
 
        assert( Idx >= 0 );
        assert( My_Connections[Idx].sock >= 0 );
-       
+
        len = recv( My_Connections[Idx].sock, My_Connections[Idx].rbuf + My_Connections[Idx].rdatalen, READBUFFER_LEN - My_Connections[Idx].rdatalen, 0 );
        My_Connections[Idx].rbuf[READBUFFER_LEN] = '\0';
 
@@ -524,18 +566,19 @@ LOCAL VOID Read_Request( CONN_ID Idx )
        {
                /* Socket wurde geschlossen */
                Log( LOG_INFO, "%s:%d is closing the connection ...", inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port));
-               Close_Connection( Idx, NULL );
+               Conn_Close( Idx, NULL );
                return;
        }
 
        if( len < 0 )
        {
                /* Fehler beim Lesen */
-               Log( LOG_ALERT, "Read error on connection %d!", Idx );
-               Close_Connection( Idx, "Read error!" );
+               Log( LOG_ALERT, "Read error on connection %d: %s!", Idx, strerror( errno ));
+               Conn_Close( Idx, NULL );
                return;
        }
 
+       /* Lesebuffer updaten */
        My_Connections[Idx].rdatalen += len;
        assert( My_Connections[Idx].rdatalen <= READBUFFER_LEN );
        My_Connections[Idx].rbuf[My_Connections[Idx].rdatalen] = '\0';
@@ -546,19 +589,45 @@ LOCAL VOID Read_Request( CONN_ID Idx )
                 * (incl. CR+LF!) werden; vgl. RFC 2812. Wenn soetwas
                 * empfangen wird, wird der Client disconnectiert. */
                Log( LOG_ALERT, "Request too long (connection %d)!", Idx );
-               Close_Connection( Idx, "Request too long!" );
+               Conn_Close( Idx, "Request too long!" );
                return;
        }
+
+       /* Timestamp aktualisieren */
+       My_Connections[Idx].lastdata = time( NULL );
+
+       Handle_Buffer( Idx );
+} /* Read_Request */
+
+
+LOCAL VOID Handle_Buffer( CONN_ID Idx )
+{
+       CHAR *ptr, *ptr1, *ptr2;
+       INT len, delta;
        
        /* Eine komplette Anfrage muss mit CR+LF enden, vgl.
         * RFC 2812. Haben wir eine? */
        ptr = strstr( My_Connections[Idx].rbuf, "\r\n" );
+
+       if( ptr ) delta = 2;
+       else
+       {
+               /* Nicht RFC-konforme Anfrage mit nur CR oder LF? Leider
+                * machen soetwas viele Clients, u.a. "mIRC" :-( */
+               ptr1 = strchr( My_Connections[Idx].rbuf, '\r' );
+               ptr2 = strchr( My_Connections[Idx].rbuf, '\n' );
+               delta = 1;
+               if( ptr1 && ptr2 ) ptr = ptr1 > ptr2 ? ptr2 : ptr1;
+               else if( ptr1 ) ptr = ptr1;
+               else if( ptr2 ) ptr = ptr2;
+       }
+
        if( ptr )
        {
-               /* Ende der Anfrage (CR+LF) wurde gefunden */
+               /* Ende der Anfrage wurde gefunden */
                *ptr = '\0';
-               len = ( ptr - My_Connections[Idx].rbuf ) + 2;
-               if( len > 2 )
+               len = ( ptr - My_Connections[Idx].rbuf ) + delta;
+               if( len > delta )
                {
                        /* Es wurde ein Request gelesen */
                        if( ! Parse_Request( Idx, My_Connections[Idx].rbuf )) return;
@@ -569,7 +638,39 @@ LOCAL VOID Read_Request( CONN_ID Idx )
                My_Connections[Idx].rdatalen -= len;
                memmove( My_Connections[Idx].rbuf, My_Connections[Idx].rbuf + len, My_Connections[Idx].rdatalen );
        }
-} /* Read_Request */
+} /* 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_PONG_Timeout )
+                               {
+                                       /* Timeout */
+                                       Log( LOG_NOTICE, "Connection %d: Ping timeout." );
+                                       Conn_Close( i, "Ping timeout" );
+                               }
+                       }
+                       else if( My_Connections[i].lastdata < time( NULL ) - Conf_PING_Timeout )
+                       {
+                               /* 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 */
 
 
 /* -eof- */