2 5fefe1a3 2001-12-12 alex * ngIRCd -- The Next Generation IRC Daemon
3 03d971d9 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 5fefe1a3 2001-12-12 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 5fefe1a3 2001-12-12 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 5fefe1a3 2001-12-12 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 5fefe1a3 2001-12-12 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 5fefe1a3 2001-12-12 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 804b1ec4 2001-12-31 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
12 e39925af 2002-03-26 alex * $Id: conn.c,v 1.57 2002/03/26 23:47:45 alex Exp $
14 5fefe1a3 2001-12-12 alex * connect.h: Verwaltung aller Netz-Verbindungen ("connections")
18 ca33cbda 2002-03-12 alex #include "portab.h"
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 5fefe1a3 2001-12-12 alex #include <assert.h>
22 d5c97f81 2001-12-23 alex #include <stdarg.h>
23 5fefe1a3 2001-12-12 alex #include <stdio.h>
24 b20fa7c6 2002-01-01 alex #include <stdlib.h>
25 5fefe1a3 2001-12-12 alex #include <unistd.h>
26 5fefe1a3 2001-12-12 alex #include <errno.h>
27 5fefe1a3 2001-12-12 alex #include <fcntl.h>
28 5fefe1a3 2001-12-12 alex #include <string.h>
29 9ab186c4 2001-12-25 alex #include <sys/socket.h>
30 5fefe1a3 2001-12-12 alex #include <sys/time.h>
31 9ab186c4 2001-12-25 alex #include <sys/types.h>
32 ba331a2f 2001-12-26 alex #include <time.h>
33 5fefe1a3 2001-12-12 alex #include <netinet/in.h>
34 4a111033 2001-12-29 alex #include <netdb.h>
36 bcc0cdc3 2002-01-05 alex #ifdef HAVE_ARPA_INET_H
37 bcc0cdc3 2002-01-05 alex #include <arpa/inet.h>
39 bcc0cdc3 2002-01-05 alex #define PF_INET AF_INET
42 5fefe1a3 2001-12-12 alex #ifdef HAVE_STDINT_H
43 5fefe1a3 2001-12-12 alex #include <stdint.h> /* u.a. fuer Mac OS X */
46 1c8eb478 2001-12-12 alex #include "ngircd.h"
47 d5c97f81 2001-12-23 alex #include "client.h"
48 65bdfdf2 2001-12-26 alex #include "conf.h"
49 5fefe1a3 2001-12-12 alex #include "log.h"
50 c4199b04 2001-12-21 alex #include "parse.h"
51 1c8eb478 2001-12-12 alex #include "tool.h"
53 ca33cbda 2002-03-12 alex #include "exp.h"
54 5fefe1a3 2001-12-12 alex #include "conn.h"
57 34d54344 2002-03-12 alex #define SERVER_WAIT (NONE - 1)
60 1c8eb478 2001-12-12 alex typedef struct _Connection
62 1c8eb478 2001-12-12 alex INT sock; /* Socket Handle */
63 1c8eb478 2001-12-12 alex struct sockaddr_in addr; /* Adresse des Client */
64 4a111033 2001-12-29 alex RES_STAT *res_stat; /* "Resolver-Status", s.o. */
65 4a111033 2001-12-29 alex CHAR host[HOST_LEN]; /* Hostname */
66 804b1ec4 2001-12-31 alex CHAR rbuf[READBUFFER_LEN]; /* Lesepuffer */
67 63758dd7 2001-12-15 alex INT rdatalen; /* Laenge der Daten im Lesepuffer */
68 804b1ec4 2001-12-31 alex CHAR wbuf[WRITEBUFFER_LEN]; /* Schreibpuffer */
69 63758dd7 2001-12-15 alex INT wdatalen; /* Laenge der Daten im Schreibpuffer */
70 03d971d9 2002-01-02 alex INT our_server; /* wenn von uns zu connectender Server: ID */
71 65bdfdf2 2001-12-26 alex time_t lastdata; /* Letzte Aktivitaet */
72 65bdfdf2 2001-12-26 alex time_t lastping; /* Letzter PING */
73 804b1ec4 2001-12-31 alex time_t lastprivmsg; /* Letzte PRIVMSG */
74 1c8eb478 2001-12-12 alex } CONNECTION;
77 63758dd7 2001-12-15 alex LOCAL VOID Handle_Read( INT sock );
78 63758dd7 2001-12-15 alex LOCAL BOOLEAN Handle_Write( CONN_ID Idx );
79 1c8eb478 2001-12-12 alex LOCAL VOID New_Connection( INT Sock );
80 cf050519 2001-12-14 alex LOCAL CONN_ID Socket2Index( INT Sock );
81 cf050519 2001-12-14 alex LOCAL VOID Read_Request( CONN_ID Idx );
82 63758dd7 2001-12-15 alex LOCAL BOOLEAN Try_Write( CONN_ID Idx );
83 9ab186c4 2001-12-25 alex LOCAL VOID Handle_Buffer( CONN_ID Idx );
84 65bdfdf2 2001-12-26 alex LOCAL VOID Check_Connections( VOID );
85 03d971d9 2002-01-02 alex LOCAL VOID Check_Servers( VOID );
86 4a111033 2001-12-29 alex LOCAL VOID Init_Conn_Struct( INT Idx );
87 6da91c34 2002-03-02 alex LOCAL BOOLEAN Init_Socket( INT Sock );
88 03d971d9 2002-01-02 alex LOCAL VOID New_Server( INT Server, CONN_ID Idx );
90 03d971d9 2002-01-02 alex LOCAL RES_STAT *ResolveAddr( struct sockaddr_in *Addr );
91 03d971d9 2002-01-02 alex LOCAL RES_STAT *ResolveName( CHAR *Host );
92 03d971d9 2002-01-02 alex LOCAL VOID Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd );
93 03d971d9 2002-01-02 alex LOCAL VOID Do_ResolveName( CHAR *Host, INT w_fd );
94 4a111033 2001-12-29 alex LOCAL VOID Read_Resolver_Result( INT r_fd );
95 03d971d9 2002-01-02 alex LOCAL CHAR *Resolv_Error( INT H_Error );
98 4a111033 2001-12-29 alex LOCAL fd_set My_Listeners;
99 1c8eb478 2001-12-12 alex LOCAL fd_set My_Sockets;
100 4a111033 2001-12-29 alex LOCAL fd_set My_Resolvers;
101 6da91c34 2002-03-02 alex LOCAL fd_set My_Connects;
103 1c8eb478 2001-12-12 alex LOCAL INT My_Max_Fd;
105 1c8eb478 2001-12-12 alex LOCAL CONNECTION My_Connections[MAX_CONNECTIONS];
108 5fefe1a3 2001-12-12 alex GLOBAL VOID Conn_Init( VOID )
110 bc140df8 2001-12-29 alex /* Modul initialisieren: statische Strukturen "ausnullen". */
114 1c8eb478 2001-12-12 alex /* zu Beginn haben wir keine Verbindungen */
115 4a111033 2001-12-29 alex FD_ZERO( &My_Listeners );
116 1c8eb478 2001-12-12 alex FD_ZERO( &My_Sockets );
117 4a111033 2001-12-29 alex FD_ZERO( &My_Resolvers );
118 6da91c34 2002-03-02 alex FD_ZERO( &My_Connects );
120 1c8eb478 2001-12-12 alex My_Max_Fd = 0;
122 1c8eb478 2001-12-12 alex /* Connection-Struktur initialisieren */
123 4a111033 2001-12-29 alex for( i = 0; i < MAX_CONNECTIONS; i++ ) Init_Conn_Struct( i );
124 5fefe1a3 2001-12-12 alex } /* Conn_Init */
127 5fefe1a3 2001-12-12 alex GLOBAL VOID Conn_Exit( VOID )
129 bc140df8 2001-12-29 alex /* Modul abmelden: alle noch offenen Connections
130 bc140df8 2001-12-29 alex * schliessen und freigeben. */
132 cf050519 2001-12-14 alex CONN_ID idx;
135 1c8eb478 2001-12-12 alex /* Sockets schliessen */
136 79809118 2002-01-06 alex Log( LOG_DEBUG, "Shutting down all connections ..." );
137 1c8eb478 2001-12-12 alex for( i = 0; i < My_Max_Fd + 1; i++ )
139 1c8eb478 2001-12-12 alex if( FD_ISSET( i, &My_Sockets ))
141 1c8eb478 2001-12-12 alex for( idx = 0; idx < MAX_CONNECTIONS; idx++ )
143 1c8eb478 2001-12-12 alex if( My_Connections[idx].sock == i ) break;
145 6da91c34 2002-03-02 alex if( FD_ISSET( i, &My_Listeners ))
147 1c8eb478 2001-12-12 alex close( i );
148 79809118 2002-01-06 alex Log( LOG_DEBUG, "Listening socket %d closed.", i );
150 6da91c34 2002-03-02 alex else if( FD_ISSET( i, &My_Connects ))
152 6da91c34 2002-03-02 alex close( i );
153 6da91c34 2002-03-02 alex Log( LOG_DEBUG, "Connection %d closed during creation (socket %d).", idx, i );
155 6da91c34 2002-03-02 alex else if( idx < MAX_CONNECTIONS ) Conn_Close( idx, NULL, "Server going down", TRUE );
158 6da91c34 2002-03-02 alex Log( LOG_WARNING, "Closing unknown connection %d ...", i );
159 1c8eb478 2001-12-12 alex close( i );
163 5fefe1a3 2001-12-12 alex } /* Conn_Exit */
166 08cf5607 2001-12-26 alex GLOBAL BOOLEAN Conn_NewListener( CONST INT Port )
168 bc140df8 2001-12-29 alex /* Neuen Listen-Socket erzeugen: der Server wartet dann auf
169 bc140df8 2001-12-29 alex * dem angegebenen Port auf Verbindungen. Kann der Listen-
170 bc140df8 2001-12-29 alex * Socket nicht erteugt werden, so wird NULL geliefert.*/
172 1c8eb478 2001-12-12 alex struct sockaddr_in addr;
175 5fefe1a3 2001-12-12 alex /* Server-"Listen"-Socket initialisieren */
176 1c8eb478 2001-12-12 alex memset( &addr, 0, sizeof( addr ));
177 1c8eb478 2001-12-12 alex addr.sin_family = AF_INET;
178 1c8eb478 2001-12-12 alex addr.sin_port = htons( Port );
179 1c8eb478 2001-12-12 alex addr.sin_addr.s_addr = htonl( INADDR_ANY );
181 5fefe1a3 2001-12-12 alex /* Socket erzeugen */
182 1c8eb478 2001-12-12 alex sock = socket( PF_INET, SOCK_STREAM, 0);
183 fb55c443 2001-12-13 alex if( sock < 0 )
185 79809118 2002-01-06 alex Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
186 5fefe1a3 2001-12-12 alex return FALSE;
189 6da91c34 2002-03-02 alex if( ! Init_Socket( sock )) return FALSE;
191 5fefe1a3 2001-12-12 alex /* an Port binden */
192 1c8eb478 2001-12-12 alex if( bind( sock, (struct sockaddr *)&addr, (socklen_t)sizeof( addr )) != 0 )
194 79809118 2002-01-06 alex Log( LOG_CRIT, "Can't bind socket: %s!", strerror( errno ));
195 1c8eb478 2001-12-12 alex close( sock );
196 5fefe1a3 2001-12-12 alex return FALSE;
199 5fefe1a3 2001-12-12 alex /* in "listen mode" gehen :-) */
200 1c8eb478 2001-12-12 alex if( listen( sock, 10 ) != 0 )
202 79809118 2002-01-06 alex Log( LOG_CRIT, "Can't listen on soecket: %s!", strerror( errno ));
203 1c8eb478 2001-12-12 alex close( sock );
204 5fefe1a3 2001-12-12 alex return FALSE;
207 1c8eb478 2001-12-12 alex /* Neuen Listener in Strukturen einfuegen */
208 4a111033 2001-12-29 alex FD_SET( sock, &My_Listeners );
209 1c8eb478 2001-12-12 alex FD_SET( sock, &My_Sockets );
211 1c8eb478 2001-12-12 alex if( sock > My_Max_Fd ) My_Max_Fd = sock;
213 9856253d 2001-12-30 alex Log( LOG_INFO, "Now listening on port %d (socket %d).", Port, sock );
215 5fefe1a3 2001-12-12 alex return TRUE;
216 08cf5607 2001-12-26 alex } /* Conn_NewListener */
219 747fd2f0 2001-12-13 alex GLOBAL VOID Conn_Handler( INT Timeout )
221 bc140df8 2001-12-29 alex /* Aktive Verbindungen ueberwachen. Mindestens alle "Timeout"
222 bc140df8 2001-12-29 alex * Sekunden wird die Funktion verlassen. Folgende Aktionen
223 bc140df8 2001-12-29 alex * werden durchgefuehrt:
224 bc140df8 2001-12-29 alex * - neue Verbindungen annehmen,
225 03d971d9 2002-01-02 alex * - Server-Verbindungen aufbauen,
226 bc140df8 2001-12-29 alex * - geschlossene Verbindungen loeschen,
227 bc140df8 2001-12-29 alex * - volle Schreibpuffer versuchen zu schreiben,
228 bc140df8 2001-12-29 alex * - volle Lesepuffer versuchen zu verarbeiten,
229 bc140df8 2001-12-29 alex * - Antworten von Resolver Sub-Prozessen annehmen.
232 63758dd7 2001-12-15 alex fd_set read_sockets, write_sockets;
233 747fd2f0 2001-12-13 alex struct timeval tv;
234 9ab186c4 2001-12-25 alex time_t start;
237 9ab186c4 2001-12-25 alex start = time( NULL );
238 65bdfdf2 2001-12-26 alex while(( time( NULL ) - start < Timeout ) && ( ! NGIRCd_Quit ))
240 03d971d9 2002-01-02 alex Check_Servers( );
242 65bdfdf2 2001-12-26 alex Check_Connections( );
244 65bdfdf2 2001-12-26 alex /* Timeout initialisieren */
245 7b8b5423 2002-03-02 alex tv.tv_sec = 0;
246 7b8b5423 2002-03-02 alex tv.tv_usec = 50000;
248 65bdfdf2 2001-12-26 alex /* noch volle Lese-Buffer suchen */
249 9ab186c4 2001-12-25 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
251 03d971d9 2002-01-02 alex if(( My_Connections[i].sock > NONE ) && ( My_Connections[i].rdatalen > 0 ))
253 65bdfdf2 2001-12-26 alex /* Kann aus dem Buffer noch ein Befehl extrahiert werden? */
254 65bdfdf2 2001-12-26 alex Handle_Buffer( i );
258 65bdfdf2 2001-12-26 alex /* noch volle Schreib-Puffer suchen */
259 65bdfdf2 2001-12-26 alex FD_ZERO( &write_sockets );
260 9ab186c4 2001-12-25 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
262 03d971d9 2002-01-02 alex if(( My_Connections[i].sock > NONE ) && ( My_Connections[i].wdatalen > 0 ))
264 65bdfdf2 2001-12-26 alex /* Socket der Verbindung in Set aufnehmen */
265 65bdfdf2 2001-12-26 alex FD_SET( My_Connections[i].sock, &write_sockets );
268 6da91c34 2002-03-02 alex /* Sockets mit im Aufbau befindlichen ausgehenden Verbindungen suchen */
269 6da91c34 2002-03-02 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
271 6da91c34 2002-03-02 alex if(( My_Connections[i].sock > NONE ) && ( FD_ISSET( My_Connections[i].sock, &My_Connects ))) FD_SET( My_Connections[i].sock, &write_sockets );
274 4a111033 2001-12-29 alex /* von welchen Sockets koennte gelesen werden? */
275 9ab186c4 2001-12-25 alex read_sockets = My_Sockets;
276 4a111033 2001-12-29 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
278 03d971d9 2002-01-02 alex if(( My_Connections[i].sock > NONE ) && ( My_Connections[i].host[0] == '\0' ))
280 4a111033 2001-12-29 alex /* Hier muss noch auf den Resolver Sub-Prozess gewartet werden */
281 6da91c34 2002-03-02 alex FD_CLR( My_Connections[i].sock, &read_sockets );
283 6da91c34 2002-03-02 alex if(( My_Connections[i].sock > NONE ) && ( FD_ISSET( My_Connections[i].sock, &My_Connects )))
285 6da91c34 2002-03-02 alex /* Hier laeuft noch ein asyncrones connect() */
286 4a111033 2001-12-29 alex FD_CLR( My_Connections[i].sock, &read_sockets );
289 4a111033 2001-12-29 alex for( i = 0; i < My_Max_Fd + 1; i++ )
291 4a111033 2001-12-29 alex /* Pipes von Resolver Sub-Prozessen aufnehmen */
292 4a111033 2001-12-29 alex if( FD_ISSET( i, &My_Resolvers ))
294 4a111033 2001-12-29 alex FD_SET( i, &read_sockets );
298 4a111033 2001-12-29 alex /* Auf Aktivitaet warten */
299 9ab186c4 2001-12-25 alex if( select( My_Max_Fd + 1, &read_sockets, &write_sockets, NULL, &tv ) == -1 )
301 db58d347 2002-01-05 alex if( errno != EINTR )
303 79809118 2002-01-06 alex Log( LOG_EMERG, "select(): %s!", strerror( errno ));
304 db58d347 2002-01-05 alex Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
310 9ab186c4 2001-12-25 alex /* Koennen Daten geschrieben werden? */
311 9ab186c4 2001-12-25 alex for( i = 0; i < My_Max_Fd + 1; i++ )
313 9ab186c4 2001-12-25 alex if( FD_ISSET( i, &write_sockets )) Handle_Write( Socket2Index( i ));
316 9ab186c4 2001-12-25 alex /* Daten zum Lesen vorhanden? */
317 9ab186c4 2001-12-25 alex for( i = 0; i < My_Max_Fd + 1; i++ )
319 9ab186c4 2001-12-25 alex if( FD_ISSET( i, &read_sockets )) Handle_Read( i );
322 1c8eb478 2001-12-12 alex } /* Conn_Handler */
325 d5c97f81 2001-12-23 alex GLOBAL BOOLEAN Conn_WriteStr( CONN_ID Idx, CHAR *Format, ... )
327 63758dd7 2001-12-15 alex /* String in Socket schreiben. CR+LF wird von dieser Funktion
328 d5c97f81 2001-12-23 alex * automatisch angehaengt. Im Fehlerfall wird dir Verbindung
329 d5c97f81 2001-12-23 alex * getrennt und FALSE geliefert. */
331 804b1ec4 2001-12-31 alex CHAR buffer[COMMAND_LEN];
332 d5c97f81 2001-12-23 alex BOOLEAN ok;
333 d5c97f81 2001-12-23 alex va_list ap;
335 28c5a21f 2002-03-14 alex assert( Idx >= 0 );
336 28c5a21f 2002-03-14 alex assert( My_Connections[Idx].sock > NONE );
337 28c5a21f 2002-03-14 alex assert( Format != NULL );
339 d5c97f81 2001-12-23 alex va_start( ap, Format );
340 804b1ec4 2001-12-31 alex if( vsnprintf( buffer, COMMAND_LEN - 2, Format, ap ) == COMMAND_LEN - 2 )
342 79809118 2002-01-06 alex Log( LOG_CRIT, "Text too long to send (connection %d)!", Idx );
343 79809118 2002-01-06 alex Conn_Close( Idx, "Text too long to send!", NULL, FALSE );
344 63758dd7 2001-12-15 alex return FALSE;
347 7c91951d 2001-12-25 alex #ifdef SNIFFER
348 d79a7d28 2002-01-18 alex if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " -> connection %d: '%s'.", Idx, buffer );
351 446df061 2001-12-24 alex strcat( buffer, "\r\n" );
352 446df061 2001-12-24 alex ok = Conn_Write( Idx, buffer, strlen( buffer ));
354 d5c97f81 2001-12-23 alex va_end( ap );
356 63758dd7 2001-12-15 alex } /* Conn_WriteStr */
359 63758dd7 2001-12-15 alex GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
361 63758dd7 2001-12-15 alex /* Daten in Socket schreiben. Bei "fatalen" Fehlern wird
362 63758dd7 2001-12-15 alex * der Client disconnectiert und FALSE geliefert. */
364 63758dd7 2001-12-15 alex assert( Idx >= 0 );
365 03d971d9 2002-01-02 alex assert( My_Connections[Idx].sock > NONE );
366 63758dd7 2001-12-15 alex assert( Data != NULL );
367 63758dd7 2001-12-15 alex assert( Len > 0 );
369 63758dd7 2001-12-15 alex /* pruefen, ob Daten im Schreibpuffer sind. Wenn ja, zunaechst
370 63758dd7 2001-12-15 alex * pruefen, ob diese gesendet werden koennen */
371 63758dd7 2001-12-15 alex if( My_Connections[Idx].wdatalen > 0 )
373 63758dd7 2001-12-15 alex if( ! Try_Write( Idx )) return FALSE;
376 63758dd7 2001-12-15 alex /* pruefen, ob im Schreibpuffer genuegend Platz ist */
377 63758dd7 2001-12-15 alex if( WRITEBUFFER_LEN - My_Connections[Idx].wdatalen - Len <= 0 )
379 63758dd7 2001-12-15 alex /* der Puffer ist dummerweise voll ... */
380 63758dd7 2001-12-15 alex Log( LOG_NOTICE, "Write buffer overflow (connection %d)!", Idx );
381 79809118 2002-01-06 alex Conn_Close( Idx, "Write buffer overflow!", NULL, FALSE );
382 63758dd7 2001-12-15 alex return FALSE;
385 63758dd7 2001-12-15 alex /* Daten in Puffer kopieren */
386 63758dd7 2001-12-15 alex memcpy( My_Connections[Idx].wbuf + My_Connections[Idx].wdatalen, Data, Len );
387 63758dd7 2001-12-15 alex My_Connections[Idx].wdatalen += Len;
389 63758dd7 2001-12-15 alex /* pruefen, on Daten vorhanden sind und geschrieben werden koennen */
390 63758dd7 2001-12-15 alex if( My_Connections[Idx].wdatalen > 0 )
392 63758dd7 2001-12-15 alex if( ! Try_Write( Idx )) return FALSE;
395 63758dd7 2001-12-15 alex return TRUE;
396 63758dd7 2001-12-15 alex } /* Conn_Write */
399 79809118 2002-01-06 alex GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
401 bc140df8 2001-12-29 alex /* Verbindung schliessen. Evtl. noch von Resolver
402 bc140df8 2001-12-29 alex * Sub-Prozessen offene Pipes werden geschlossen. */
406 7c91951d 2001-12-25 alex assert( Idx >= 0 );
407 03d971d9 2002-01-02 alex assert( My_Connections[Idx].sock > NONE );
409 79809118 2002-01-06 alex if( InformClient )
411 79809118 2002-01-06 alex if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg );
412 79809118 2002-01-06 alex else Conn_WriteStr( Idx, "ERROR :Closing connection." );
413 03d971d9 2002-01-02 alex if( My_Connections[Idx].sock == NONE ) return;
416 7c91951d 2001-12-25 alex if( close( My_Connections[Idx].sock ) != 0 )
418 7c91951d 2001-12-25 alex 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 ));
422 4d4f2d4f 2002-01-04 alex Log( LOG_INFO, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port ));
425 03d971d9 2002-01-02 alex c = Client_GetFromConn( Idx );
426 50ec7a56 2002-03-11 alex if( c ) Client_Destroy( c, LogMsg, FwdMsg, TRUE );
428 4a111033 2001-12-29 alex if( My_Connections[Idx].res_stat )
430 4a111033 2001-12-29 alex /* Resolver-Strukturen freigeben, wenn noch nicht geschehen */
431 b9728ba2 2001-12-29 alex FD_CLR( My_Connections[Idx].res_stat->pipe[0], &My_Resolvers );
432 b9728ba2 2001-12-29 alex close( My_Connections[Idx].res_stat->pipe[0] );
433 b9728ba2 2001-12-29 alex close( My_Connections[Idx].res_stat->pipe[1] );
434 4a111033 2001-12-29 alex free( My_Connections[Idx].res_stat );
437 a3ee1a9a 2002-03-02 alex /* Bei Server-Verbindungen lasttry-Zeitpunkt so setzen, dass
438 a3ee1a9a 2002-03-02 alex * der naechste Verbindungsversuch in RECONNECT_DELAY Sekunden
439 590f2a3f 2002-03-11 alex * gestartet wird. */
440 590f2a3f 2002-03-11 alex if(( My_Connections[Idx].our_server >= 0 ) && ( Conf_Server[My_Connections[Idx].our_server].lasttry < time( NULL )))
442 590f2a3f 2002-03-11 alex /* Okay, die Verbindung stand schon "genuegend lange" */
443 590f2a3f 2002-03-11 alex Conf_Server[My_Connections[Idx].our_server].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
446 7c91951d 2001-12-25 alex FD_CLR( My_Connections[Idx].sock, &My_Sockets );
447 5457e078 2002-03-02 alex FD_CLR( My_Connections[Idx].sock, &My_Connects );
448 7c91951d 2001-12-25 alex My_Connections[Idx].sock = NONE;
449 7c91951d 2001-12-25 alex } /* Conn_Close */
452 804b1ec4 2001-12-31 alex GLOBAL VOID Conn_UpdateIdle( CONN_ID Idx )
454 804b1ec4 2001-12-31 alex /* Idle-Timer zuruecksetzen */
456 804b1ec4 2001-12-31 alex assert( Idx >= 0 );
457 804b1ec4 2001-12-31 alex My_Connections[Idx].lastprivmsg = time( NULL );
461 8465653c 2002-02-23 alex GLOBAL time_t Conn_GetIdle( CONN_ID Idx )
463 804b1ec4 2001-12-31 alex /* Idle-Time einer Verbindung liefern (in Sekunden) */
465 804b1ec4 2001-12-31 alex assert( Idx >= 0 );
466 804b1ec4 2001-12-31 alex return time( NULL ) - My_Connections[Idx].lastprivmsg;
467 804b1ec4 2001-12-31 alex } /* Conn_GetIdle */
470 8465653c 2002-02-23 alex GLOBAL time_t Conn_LastPing( CONN_ID Idx )
472 b9f005af 2002-02-11 alex /* Zeitpunkt des letzten PING liefern */
474 b9f005af 2002-02-11 alex assert( Idx >= 0 );
475 b9f005af 2002-02-11 alex return My_Connections[Idx].lastping;
476 b9f005af 2002-02-11 alex } /* Conn_LastPing */
479 63758dd7 2001-12-15 alex LOCAL BOOLEAN Try_Write( CONN_ID Idx )
481 63758dd7 2001-12-15 alex /* Versuchen, Daten aus dem Schreib-Puffer in den
482 63758dd7 2001-12-15 alex * Socket zu schreiben. */
484 63758dd7 2001-12-15 alex fd_set write_socket;
486 63758dd7 2001-12-15 alex assert( Idx >= 0 );
487 03d971d9 2002-01-02 alex assert( My_Connections[Idx].sock > NONE );
488 63758dd7 2001-12-15 alex assert( My_Connections[Idx].wdatalen > 0 );
490 63758dd7 2001-12-15 alex FD_ZERO( &write_socket );
491 63758dd7 2001-12-15 alex FD_SET( My_Connections[Idx].sock, &write_socket );
492 63758dd7 2001-12-15 alex if( select( My_Connections[Idx].sock + 1, NULL, &write_socket, NULL, 0 ) == -1 )
494 63758dd7 2001-12-15 alex /* Fehler! */
495 63758dd7 2001-12-15 alex if( errno != EINTR )
497 79809118 2002-01-06 alex Log( LOG_ALERT, "select() failed: %s!", strerror( errno ));
498 79809118 2002-01-06 alex Conn_Close( Idx, "Server error!", NULL, FALSE );
499 63758dd7 2001-12-15 alex return FALSE;
503 63758dd7 2001-12-15 alex if( FD_ISSET( My_Connections[Idx].sock, &write_socket )) return Handle_Write( Idx );
504 63758dd7 2001-12-15 alex else return TRUE;
505 63758dd7 2001-12-15 alex } /* Try_Write */
508 63758dd7 2001-12-15 alex LOCAL VOID Handle_Read( INT Sock )
510 bc140df8 2001-12-29 alex /* Aktivitaet auf einem Socket verarbeiten:
511 bc140df8 2001-12-29 alex * - neue Clients annehmen,
512 bc140df8 2001-12-29 alex * - Daten von Clients verarbeiten,
513 bc140df8 2001-12-29 alex * - Resolver-Rueckmeldungen annehmen. */
515 cf050519 2001-12-14 alex CONN_ID idx;
517 63758dd7 2001-12-15 alex assert( Sock >= 0 );
519 4a111033 2001-12-29 alex if( FD_ISSET( Sock, &My_Listeners ))
521 1c8eb478 2001-12-12 alex /* es ist einer unserer Listener-Sockets: es soll
522 1c8eb478 2001-12-12 alex * also eine neue Verbindung aufgebaut werden. */
524 1c8eb478 2001-12-12 alex New_Connection( Sock );
526 4a111033 2001-12-29 alex else if( FD_ISSET( Sock, &My_Resolvers ))
528 4a111033 2001-12-29 alex /* Rueckmeldung von einem Resolver Sub-Prozess */
530 4a111033 2001-12-29 alex Read_Resolver_Result( Sock );
534 1c8eb478 2001-12-12 alex /* Ein Client Socket: entweder ein User oder Server */
536 1c8eb478 2001-12-12 alex idx = Socket2Index( Sock );
537 747fd2f0 2001-12-13 alex Read_Request( idx );
539 63758dd7 2001-12-15 alex } /* Handle_Read */
542 63758dd7 2001-12-15 alex LOCAL BOOLEAN Handle_Write( CONN_ID Idx )
544 6da91c34 2002-03-02 alex /* Daten aus Schreibpuffer versenden bzw. Connection aufbauen */
546 6da91c34 2002-03-02 alex INT len, res, err;
548 63758dd7 2001-12-15 alex assert( Idx >= 0 );
549 03d971d9 2002-01-02 alex assert( My_Connections[Idx].sock > NONE );
551 6da91c34 2002-03-02 alex if( FD_ISSET( My_Connections[Idx].sock, &My_Connects ))
553 6da91c34 2002-03-02 alex /* es soll nichts geschrieben werden, sondern ein
554 6da91c34 2002-03-02 alex * connect() hat ein Ergebnis geliefert */
556 6da91c34 2002-03-02 alex FD_CLR( My_Connections[Idx].sock, &My_Connects );
558 6da91c34 2002-03-02 alex /* Ergebnis des connect() ermitteln */
559 6da91c34 2002-03-02 alex len = sizeof( err );
560 6da91c34 2002-03-02 alex res = getsockopt( My_Connections[Idx].sock, SOL_SOCKET, SO_ERROR, &err, &len );
561 6da91c34 2002-03-02 alex assert( len == sizeof( err ));
563 6da91c34 2002-03-02 alex /* Fehler aufgetreten? */
564 6da91c34 2002-03-02 alex if(( res != 0 ) || ( err != 0 ))
566 6da91c34 2002-03-02 alex /* Fehler! */
567 6da91c34 2002-03-02 alex if( res != 0 ) Log( LOG_CRIT, "getsockopt (connection %d): %s!", Idx, strerror( errno ));
568 6da91c34 2002-03-02 alex else Log( LOG_CRIT, "Can't connect socket to \"%s:%d\" (connection %d): %s!", My_Connections[Idx].host, Conf_Server[My_Connections[Idx].our_server].port, Idx, strerror( err ));
570 6da91c34 2002-03-02 alex /* Socket etc. pp. aufraeumen */
571 6da91c34 2002-03-02 alex FD_CLR( My_Connections[Idx].sock, &My_Sockets );
572 6da91c34 2002-03-02 alex close( My_Connections[Idx].sock );
573 6da91c34 2002-03-02 alex Init_Conn_Struct( Idx );
575 cbce54e0 2002-03-02 alex /* Bei Server-Verbindungen lasttry-Zeitpunkt auf "jetzt" setzen */
576 cbce54e0 2002-03-02 alex Conf_Server[My_Connections[Idx].our_server].lasttry = time( NULL );
578 6da91c34 2002-03-02 alex return FALSE;
580 6da91c34 2002-03-02 alex Log( LOG_DEBUG, "Connection %d with \"%s:%d\" established, now sendig PASS and SERVER ...", Idx, My_Connections[Idx].host, Conf_Server[My_Connections[Idx].our_server].port );
582 6da91c34 2002-03-02 alex /* PASS und SERVER verschicken */
583 6da91c34 2002-03-02 alex Conn_WriteStr( Idx, "PASS %s "PASSSERVERADD, Conf_Server[My_Connections[Idx].our_server].pwd );
584 6da91c34 2002-03-02 alex Conn_WriteStr( Idx, "SERVER %s :%s", Conf_ServerName, Conf_ServerInfo );
586 6da91c34 2002-03-02 alex return TRUE;
589 63758dd7 2001-12-15 alex assert( My_Connections[Idx].wdatalen > 0 );
591 63758dd7 2001-12-15 alex /* Daten schreiben */
592 63758dd7 2001-12-15 alex len = send( My_Connections[Idx].sock, My_Connections[Idx].wbuf, My_Connections[Idx].wdatalen, 0 );
593 63758dd7 2001-12-15 alex if( len < 0 )
595 63758dd7 2001-12-15 alex /* Oops, ein Fehler! */
596 79809118 2002-01-06 alex Log( LOG_ERR, "Write error (buffer) on connection %d: %s!", Idx, strerror( errno ));
597 79809118 2002-01-06 alex Conn_Close( Idx, "Write error (buffer)!", NULL, FALSE );
598 63758dd7 2001-12-15 alex return FALSE;
601 63758dd7 2001-12-15 alex /* Puffer anpassen */
602 63758dd7 2001-12-15 alex My_Connections[Idx].wdatalen -= len;
603 63758dd7 2001-12-15 alex memmove( My_Connections[Idx].wbuf, My_Connections[Idx].wbuf + len, My_Connections[Idx].wdatalen );
605 63758dd7 2001-12-15 alex return TRUE;
606 63758dd7 2001-12-15 alex } /* Handle_Write */
609 1c8eb478 2001-12-12 alex LOCAL VOID New_Connection( INT Sock )
611 d5c97f81 2001-12-23 alex /* Neue Client-Verbindung von Listen-Socket annehmen und
612 d5c97f81 2001-12-23 alex * CLIENT-Struktur anlegen. */
614 1c8eb478 2001-12-12 alex struct sockaddr_in new_addr;
615 cf050519 2001-12-14 alex INT new_sock, new_sock_len;
616 4a111033 2001-12-29 alex RES_STAT *s;
617 cf050519 2001-12-14 alex CONN_ID idx;
619 63758dd7 2001-12-15 alex assert( Sock >= 0 );
621 1c8eb478 2001-12-12 alex new_sock_len = sizeof( new_addr );
622 fb55c443 2001-12-13 alex new_sock = accept( Sock, (struct sockaddr *)&new_addr, (socklen_t *)&new_sock_len );
623 1c8eb478 2001-12-12 alex if( new_sock < 0 )
625 446df061 2001-12-24 alex Log( LOG_CRIT, "Can't accept connection: %s!", strerror( errno ));
629 1c8eb478 2001-12-12 alex /* Freie Connection-Struktur suschen */
630 03d971d9 2002-01-02 alex for( idx = 0; idx < MAX_CONNECTIONS; idx++ ) if( My_Connections[idx].sock == NONE ) break;
631 1c8eb478 2001-12-12 alex if( idx >= MAX_CONNECTIONS )
633 63758dd7 2001-12-15 alex Log( LOG_ALERT, "Can't accept connection: limit reached (%d)!", MAX_CONNECTIONS );
634 1c8eb478 2001-12-12 alex close( new_sock );
638 d5c97f81 2001-12-23 alex /* Client-Struktur initialisieren */
639 2e4d085d 2002-01-05 alex if( ! Client_NewLocal( idx, inet_ntoa( new_addr.sin_addr ), CLIENT_UNKNOWN, FALSE ))
641 d5c97f81 2001-12-23 alex Log( LOG_ALERT, "Can't accept connection: can't create client structure!" );
642 d5c97f81 2001-12-23 alex close( new_sock );
646 1c8eb478 2001-12-12 alex /* Verbindung registrieren */
647 4a111033 2001-12-29 alex Init_Conn_Struct( idx );
648 1c8eb478 2001-12-12 alex My_Connections[idx].sock = new_sock;
649 1c8eb478 2001-12-12 alex My_Connections[idx].addr = new_addr;
651 1c8eb478 2001-12-12 alex /* Neuen Socket registrieren */
652 1c8eb478 2001-12-12 alex FD_SET( new_sock, &My_Sockets );
653 1c8eb478 2001-12-12 alex if( new_sock > My_Max_Fd ) My_Max_Fd = new_sock;
655 4d4f2d4f 2002-01-04 alex Log( LOG_INFO, "Accepted connection %d from %s:%d on socket %d.", idx, inet_ntoa( new_addr.sin_addr ), ntohs( new_addr.sin_port), Sock );
657 4a111033 2001-12-29 alex /* Hostnamen ermitteln */
658 03d971d9 2002-01-02 alex s = ResolveAddr( &new_addr );
661 4a111033 2001-12-29 alex /* Sub-Prozess wurde asyncron gestartet */
662 4a111033 2001-12-29 alex My_Connections[idx].res_stat = s;
666 4a111033 2001-12-29 alex /* kann Namen nicht aufloesen */
667 4a111033 2001-12-29 alex strcpy( My_Connections[idx].host, inet_ntoa( new_addr.sin_addr ));
669 1c8eb478 2001-12-12 alex } /* New_Connection */
672 cf050519 2001-12-14 alex LOCAL CONN_ID Socket2Index( INT Sock )
674 63758dd7 2001-12-15 alex /* zum Socket passende Connection suchen */
676 cf050519 2001-12-14 alex CONN_ID idx;
678 63758dd7 2001-12-15 alex assert( Sock >= 0 );
680 1c8eb478 2001-12-12 alex for( idx = 0; idx < MAX_CONNECTIONS; idx++ ) if( My_Connections[idx].sock == Sock ) break;
682 63758dd7 2001-12-15 alex assert( idx < MAX_CONNECTIONS );
683 1c8eb478 2001-12-12 alex return idx;
684 1c8eb478 2001-12-12 alex } /* Socket2Index */
687 cf050519 2001-12-14 alex LOCAL VOID Read_Request( CONN_ID Idx )
689 747fd2f0 2001-12-13 alex /* Daten von Socket einlesen und entsprechend behandeln.
690 747fd2f0 2001-12-13 alex * Tritt ein Fehler auf, so wird der Socket geschlossen. */
694 63758dd7 2001-12-15 alex assert( Idx >= 0 );
695 03d971d9 2002-01-02 alex assert( My_Connections[Idx].sock > NONE );
697 54e487d4 2002-01-03 alex if( READBUFFER_LEN - My_Connections[Idx].rdatalen - 2 < 0 )
699 54e487d4 2002-01-03 alex /* Der Lesepuffer ist voll */
700 79809118 2002-01-06 alex Log( LOG_ERR, "Read buffer overflow (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
701 79809118 2002-01-06 alex Conn_Close( Idx, "Read buffer overflow!", NULL, FALSE );
705 54e487d4 2002-01-03 alex len = recv( My_Connections[Idx].sock, My_Connections[Idx].rbuf + My_Connections[Idx].rdatalen, READBUFFER_LEN - My_Connections[Idx].rdatalen - 2, 0 );
707 747fd2f0 2001-12-13 alex if( len == 0 )
709 747fd2f0 2001-12-13 alex /* Socket wurde geschlossen */
710 c4199b04 2001-12-21 alex Log( LOG_INFO, "%s:%d is closing the connection ...", inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port));
711 ae6ab2c3 2002-03-04 alex Conn_Close( Idx, "Socket closed!", "Client closed connection", FALSE );
715 747fd2f0 2001-12-13 alex if( len < 0 )
717 747fd2f0 2001-12-13 alex /* Fehler beim Lesen */
718 79809118 2002-01-06 alex Log( LOG_ERR, "Read error on connection %d: %s!", Idx, strerror( errno ));
719 ae6ab2c3 2002-03-04 alex Conn_Close( Idx, "Read error!", "Client closed connection", FALSE );
723 65bdfdf2 2001-12-26 alex /* Lesebuffer updaten */
724 63758dd7 2001-12-15 alex My_Connections[Idx].rdatalen += len;
725 54e487d4 2002-01-03 alex assert( My_Connections[Idx].rdatalen < READBUFFER_LEN );
726 63758dd7 2001-12-15 alex My_Connections[Idx].rbuf[My_Connections[Idx].rdatalen] = '\0';
728 65bdfdf2 2001-12-26 alex /* Timestamp aktualisieren */
729 65bdfdf2 2001-12-26 alex My_Connections[Idx].lastdata = time( NULL );
731 9ab186c4 2001-12-25 alex Handle_Buffer( Idx );
732 9ab186c4 2001-12-25 alex } /* Read_Request */
735 9ab186c4 2001-12-25 alex LOCAL VOID Handle_Buffer( CONN_ID Idx )
737 bc140df8 2001-12-29 alex /* Daten im Lese-Puffer einer Verbindung verarbeiten. */
739 9ab186c4 2001-12-25 alex CHAR *ptr, *ptr1, *ptr2;
740 9ab186c4 2001-12-25 alex INT len, delta;
742 63758dd7 2001-12-15 alex /* Eine komplette Anfrage muss mit CR+LF enden, vgl.
743 63758dd7 2001-12-15 alex * RFC 2812. Haben wir eine? */
744 63758dd7 2001-12-15 alex ptr = strstr( My_Connections[Idx].rbuf, "\r\n" );
746 9ab186c4 2001-12-25 alex if( ptr ) delta = 2;
747 54e487d4 2002-01-03 alex #ifndef STRICT_RFC
750 9ab186c4 2001-12-25 alex /* Nicht RFC-konforme Anfrage mit nur CR oder LF? Leider
751 9ab186c4 2001-12-25 alex * machen soetwas viele Clients, u.a. "mIRC" :-( */
752 9ab186c4 2001-12-25 alex ptr1 = strchr( My_Connections[Idx].rbuf, '\r' );
753 9ab186c4 2001-12-25 alex ptr2 = strchr( My_Connections[Idx].rbuf, '\n' );
755 9ab186c4 2001-12-25 alex if( ptr1 && ptr2 ) ptr = ptr1 > ptr2 ? ptr2 : ptr1;
756 9ab186c4 2001-12-25 alex else if( ptr1 ) ptr = ptr1;
757 9ab186c4 2001-12-25 alex else if( ptr2 ) ptr = ptr2;
763 9ab186c4 2001-12-25 alex /* Ende der Anfrage wurde gefunden */
764 63758dd7 2001-12-15 alex *ptr = '\0';
765 9ab186c4 2001-12-25 alex len = ( ptr - My_Connections[Idx].rbuf ) + delta;
766 54e487d4 2002-01-03 alex if( len > COMMAND_LEN )
768 54e487d4 2002-01-03 alex /* Eine Anfrage darf(!) nicht laenger als 512 Zeichen
769 54e487d4 2002-01-03 alex * (incl. CR+LF!) werden; vgl. RFC 2812. Wenn soetwas
770 54e487d4 2002-01-03 alex * empfangen wird, wird der Client disconnectiert. */
771 79809118 2002-01-06 alex Log( LOG_ERR, "Request too long (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
772 79809118 2002-01-06 alex Conn_Close( Idx, NULL, "Request too long", TRUE );
776 9ab186c4 2001-12-25 alex if( len > delta )
778 c4199b04 2001-12-21 alex /* Es wurde ein Request gelesen */
779 c4199b04 2001-12-21 alex if( ! Parse_Request( Idx, My_Connections[Idx].rbuf )) return;
782 63758dd7 2001-12-15 alex /* Puffer anpassen */
783 63758dd7 2001-12-15 alex My_Connections[Idx].rdatalen -= len;
784 63758dd7 2001-12-15 alex memmove( My_Connections[Idx].rbuf, My_Connections[Idx].rbuf + len, My_Connections[Idx].rdatalen );
786 9ab186c4 2001-12-25 alex } /* Handle_Buffer */
789 65bdfdf2 2001-12-26 alex LOCAL VOID Check_Connections( VOID )
791 bc140df8 2001-12-29 alex /* Pruefen, ob Verbindungen noch "alive" sind. Ist dies
792 bc140df8 2001-12-29 alex * nicht der Fall, zunaechst PING-PONG spielen und, wenn
793 bc140df8 2001-12-29 alex * auch das nicht "hilft", Client disconnectieren. */
798 65bdfdf2 2001-12-26 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
800 03d971d9 2002-01-02 alex if( My_Connections[i].sock == NONE ) continue;
802 03d971d9 2002-01-02 alex c = Client_GetFromConn( i );
803 356683ff 2002-01-04 alex if( c && (( Client_Type( c ) == CLIENT_USER ) || ( Client_Type( c ) == CLIENT_SERVER ) || ( Client_Type( c ) == CLIENT_SERVICE )))
805 03d971d9 2002-01-02 alex /* verbundener User, Server oder Service */
806 65bdfdf2 2001-12-26 alex if( My_Connections[i].lastping > My_Connections[i].lastdata )
808 65bdfdf2 2001-12-26 alex /* es wurde bereits ein PING gesendet */
809 08cf5607 2001-12-26 alex if( My_Connections[i].lastping < time( NULL ) - Conf_PongTimeout )
811 65bdfdf2 2001-12-26 alex /* Timeout */
812 e39925af 2002-03-26 alex Log( LOG_DEBUG, "Connection %d: Ping timeout: %d seconds.", i, Conf_PongTimeout );
813 79809118 2002-01-06 alex Conn_Close( i, NULL, "Ping timeout", TRUE );
816 08cf5607 2001-12-26 alex else if( My_Connections[i].lastdata < time( NULL ) - Conf_PingTimeout )
818 65bdfdf2 2001-12-26 alex /* es muss ein PING gesendet werden */
819 65bdfdf2 2001-12-26 alex Log( LOG_DEBUG, "Connection %d: sending PING ...", i );
820 65bdfdf2 2001-12-26 alex My_Connections[i].lastping = time( NULL );
821 356683ff 2002-01-04 alex Conn_WriteStr( i, "PING :%s", Client_ID( Client_ThisServer( )));
826 03d971d9 2002-01-02 alex /* noch nicht vollstaendig aufgebaute Verbindung */
827 03d971d9 2002-01-02 alex if( My_Connections[i].lastdata < time( NULL ) - Conf_PingTimeout )
829 03d971d9 2002-01-02 alex /* Timeout */
830 140d1aa5 2002-02-27 alex Log( LOG_DEBUG, "Connection %d timed out ...", i );
831 5457e078 2002-03-02 alex Conn_Close( i, NULL, "Timeout", FALSE );
835 03d971d9 2002-01-02 alex } /* Check_Connections */
838 03d971d9 2002-01-02 alex LOCAL VOID Check_Servers( VOID )
840 03d971d9 2002-01-02 alex /* Pruefen, ob Server-Verbindungen aufgebaut werden
841 03d971d9 2002-01-02 alex * muessen bzw. koennen */
843 03d971d9 2002-01-02 alex INT idx, i, n;
844 03d971d9 2002-01-02 alex RES_STAT *s;
846 26ffbc78 2002-02-19 alex /* Wenn "Passive-Mode" aktiv: nicht verbinden */
847 26ffbc78 2002-02-19 alex if( NGIRCd_Passive ) return;
849 03d971d9 2002-01-02 alex for( i = 0; i < Conf_Server_Count; i++ )
851 03d971d9 2002-01-02 alex /* Ist ein Hostname und Port definiert? */
852 03d971d9 2002-01-02 alex if(( ! Conf_Server[i].host[0] ) || ( ! Conf_Server[i].port > 0 )) continue;
854 03d971d9 2002-01-02 alex /* Haben wir schon eine Verbindung? */
855 03d971d9 2002-01-02 alex for( n = 0; n < MAX_CONNECTIONS; n++ )
857 9146fa25 2002-03-12 alex if( My_Connections[n].sock == NONE ) continue;
859 d67d94ea 2002-03-10 alex /* Verbindung zu diesem Server? */
860 9146fa25 2002-03-12 alex if( My_Connections[n].our_server == i )
862 03d971d9 2002-01-02 alex /* Komplett aufgebaute Verbindung? */
863 03d971d9 2002-01-02 alex if( My_Connections[n].sock > NONE ) break;
865 03d971d9 2002-01-02 alex /* IP schon aufgeloest? */
866 03d971d9 2002-01-02 alex if( My_Connections[n].res_stat == NULL ) New_Server( i, n );
869 d67d94ea 2002-03-10 alex /* Verbindung in dieser Server-Gruppe? */
870 9146fa25 2002-03-12 alex if(( My_Connections[n].our_server != NONE ) && ( Conf_Server[i].group != NONE ))
872 9146fa25 2002-03-12 alex if( Conf_Server[My_Connections[n].our_server].group == Conf_Server[i].group ) break;
875 03d971d9 2002-01-02 alex if( n < MAX_CONNECTIONS ) continue;
877 03d971d9 2002-01-02 alex /* Wann war der letzte Connect-Versuch? */
878 03d971d9 2002-01-02 alex if( Conf_Server[i].lasttry > time( NULL ) - Conf_ConnectRetry ) continue;
880 03d971d9 2002-01-02 alex /* Okay, Verbindungsaufbau versuchen */
881 03d971d9 2002-01-02 alex Conf_Server[i].lasttry = time( NULL );
883 03d971d9 2002-01-02 alex /* Freie Connection-Struktur suschen */
884 03d971d9 2002-01-02 alex for( idx = 0; idx < MAX_CONNECTIONS; idx++ ) if( My_Connections[idx].sock == NONE ) break;
885 03d971d9 2002-01-02 alex if( idx >= MAX_CONNECTIONS )
887 03d971d9 2002-01-02 alex Log( LOG_ALERT, "Can't establist server connection: connection limit reached (%d)!", MAX_CONNECTIONS );
890 03d971d9 2002-01-02 alex Log( LOG_DEBUG, "Preparing connection %d for \"%s\" ...", idx, Conf_Server[i].host );
892 03d971d9 2002-01-02 alex /* Verbindungs-Struktur initialisieren */
893 03d971d9 2002-01-02 alex Init_Conn_Struct( idx );
894 03d971d9 2002-01-02 alex My_Connections[idx].sock = SERVER_WAIT;
895 03d971d9 2002-01-02 alex My_Connections[idx].our_server = i;
897 03d971d9 2002-01-02 alex /* Hostnamen in IP aufloesen */
898 03d971d9 2002-01-02 alex s = ResolveName( Conf_Server[i].host );
901 03d971d9 2002-01-02 alex /* Sub-Prozess wurde asyncron gestartet */
902 03d971d9 2002-01-02 alex My_Connections[idx].res_stat = s;
906 03d971d9 2002-01-02 alex /* kann Namen nicht aufloesen: Connection-Struktur freigeben */
907 03d971d9 2002-01-02 alex Init_Conn_Struct( idx );
910 03d971d9 2002-01-02 alex } /* Check_Servers */
913 03d971d9 2002-01-02 alex LOCAL VOID New_Server( INT Server, CONN_ID Idx )
915 03d971d9 2002-01-02 alex /* Neue Server-Verbindung aufbauen */
917 03d971d9 2002-01-02 alex struct sockaddr_in new_addr;
918 03d971d9 2002-01-02 alex struct in_addr inaddr;
919 03d971d9 2002-01-02 alex INT new_sock;
922 03d971d9 2002-01-02 alex assert( Server >= 0 );
923 03d971d9 2002-01-02 alex assert( Idx >= 0 );
925 03d971d9 2002-01-02 alex /* Wurde eine gueltige IP-Adresse gefunden? */
926 03d971d9 2002-01-02 alex if( ! Conf_Server[Server].ip[0] )
928 03d971d9 2002-01-02 alex /* Nein. Verbindung wieder freigeben: */
929 03d971d9 2002-01-02 alex Init_Conn_Struct( Idx );
930 03d971d9 2002-01-02 alex Log( LOG_ERR, "Can't connect to \"%s\" (connection %d): ip address unknown!", Conf_Server[Server].host, Idx );
934 94435271 2002-02-19 alex 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 );
936 03d971d9 2002-01-02 alex if( inet_aton( Conf_Server[Server].ip, &inaddr ) == 0 )
938 03d971d9 2002-01-02 alex /* Konnte Adresse nicht konvertieren */
939 03d971d9 2002-01-02 alex Init_Conn_Struct( Idx );
940 03d971d9 2002-01-02 alex 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 );
944 03d971d9 2002-01-02 alex memset( &new_addr, 0, sizeof( new_addr ));
945 03d971d9 2002-01-02 alex new_addr.sin_family = AF_INET;
946 03d971d9 2002-01-02 alex new_addr.sin_addr = inaddr;
947 03d971d9 2002-01-02 alex new_addr.sin_port = htons( Conf_Server[Server].port );
949 03d971d9 2002-01-02 alex new_sock = socket( PF_INET, SOCK_STREAM, 0 );
950 03d971d9 2002-01-02 alex if ( new_sock < 0 )
952 03d971d9 2002-01-02 alex Init_Conn_Struct( Idx );
953 79809118 2002-01-06 alex Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
957 6da91c34 2002-03-02 alex if( ! Init_Socket( new_sock )) return;
959 6da91c34 2002-03-02 alex connect( new_sock, (struct sockaddr *)&new_addr, sizeof( new_addr ));
960 6da91c34 2002-03-02 alex if( errno != EINPROGRESS )
963 03d971d9 2002-01-02 alex close( new_sock );
964 03d971d9 2002-01-02 alex Init_Conn_Struct( Idx );
965 79809118 2002-01-06 alex Log( LOG_CRIT, "Can't connect socket: %s!", strerror( errno ));
969 03d971d9 2002-01-02 alex /* Client-Struktur initialisieren */
970 2e4d085d 2002-01-05 alex c = Client_NewLocal( Idx, inet_ntoa( new_addr.sin_addr ), CLIENT_UNKNOWNSERVER, FALSE );
973 03d971d9 2002-01-02 alex close( new_sock );
974 03d971d9 2002-01-02 alex Init_Conn_Struct( Idx );
975 03d971d9 2002-01-02 alex Log( LOG_ALERT, "Can't establish connection: can't create client structure!" );
978 356683ff 2002-01-04 alex Client_SetIntroducer( c, c );
980 03d971d9 2002-01-02 alex /* Verbindung registrieren */
981 03d971d9 2002-01-02 alex My_Connections[Idx].sock = new_sock;
982 03d971d9 2002-01-02 alex My_Connections[Idx].addr = new_addr;
983 03d971d9 2002-01-02 alex strcpy( My_Connections[Idx].host, Conf_Server[Server].host );
985 03d971d9 2002-01-02 alex /* Neuen Socket registrieren */
986 03d971d9 2002-01-02 alex FD_SET( new_sock, &My_Sockets );
987 6da91c34 2002-03-02 alex FD_SET( new_sock, &My_Connects );
988 03d971d9 2002-01-02 alex if( new_sock > My_Max_Fd ) My_Max_Fd = new_sock;
989 03d971d9 2002-01-02 alex } /* New_Server */
992 4a111033 2001-12-29 alex LOCAL VOID Init_Conn_Struct( INT Idx )
994 4a111033 2001-12-29 alex /* Connection-Struktur initialisieren */
996 4a111033 2001-12-29 alex My_Connections[Idx].sock = NONE;
997 4a111033 2001-12-29 alex My_Connections[Idx].res_stat = NULL;
998 4a111033 2001-12-29 alex My_Connections[Idx].host[0] = '\0';
999 4a111033 2001-12-29 alex My_Connections[Idx].rbuf[0] = '\0';
1000 4a111033 2001-12-29 alex My_Connections[Idx].rdatalen = 0;
1001 4a111033 2001-12-29 alex My_Connections[Idx].wbuf[0] = '\0';
1002 4a111033 2001-12-29 alex My_Connections[Idx].wdatalen = 0;
1003 d67d94ea 2002-03-10 alex My_Connections[Idx].our_server = NONE;
1004 4a111033 2001-12-29 alex My_Connections[Idx].lastdata = time( NULL );
1005 4a111033 2001-12-29 alex My_Connections[Idx].lastping = 0;
1006 804b1ec4 2001-12-31 alex My_Connections[Idx].lastprivmsg = time( NULL );
1007 4a111033 2001-12-29 alex } /* Init_Conn_Struct */
1010 6da91c34 2002-03-02 alex LOCAL BOOLEAN Init_Socket( INT Sock )
1012 6da91c34 2002-03-02 alex /* Socket-Optionen setzen */
1014 6da91c34 2002-03-02 alex INT on = 1;
1016 239727b4 2002-03-13 alex #ifdef O_NONBLOCK /* A/UX kennt das nicht? */
1017 6da91c34 2002-03-02 alex if( fcntl( Sock, F_SETFL, O_NONBLOCK ) != 0 )
1019 6da91c34 2002-03-02 alex Log( LOG_CRIT, "Can't enable non-blocking mode: %s!", strerror( errno ));
1020 6da91c34 2002-03-02 alex close( Sock );
1021 6da91c34 2002-03-02 alex return FALSE;
1024 6da91c34 2002-03-02 alex if( setsockopt( Sock, SOL_SOCKET, SO_REUSEADDR, &on, (socklen_t)sizeof( on )) != 0)
1026 6da91c34 2002-03-02 alex Log( LOG_ERR, "Can't set socket options: %s!", strerror( errno ));
1027 6da91c34 2002-03-02 alex /* dieser Fehler kann ignoriert werden. */
1030 6da91c34 2002-03-02 alex return TRUE;
1031 6da91c34 2002-03-02 alex } /* Init_Socket */
1034 03d971d9 2002-01-02 alex LOCAL RES_STAT *ResolveAddr( struct sockaddr_in *Addr )
1036 03d971d9 2002-01-02 alex /* IP (asyncron!) aufloesen. Bei Fehler, z.B. wenn der
1037 4a111033 2001-12-29 alex * Child-Prozess nicht erzeugt werden kann, wird NULL geliefert.
1038 4a111033 2001-12-29 alex * Der Host kann dann nicht aufgeloest werden. */
1040 4a111033 2001-12-29 alex RES_STAT *s;
1043 bc140df8 2001-12-29 alex /* Speicher anfordern */
1044 4a111033 2001-12-29 alex s = malloc( sizeof( RES_STAT ));
1047 79809118 2002-01-06 alex Log( LOG_EMERG, "Resolver: Can't allocate memory!" );
1048 4a111033 2001-12-29 alex return NULL;
1051 bc140df8 2001-12-29 alex /* Pipe fuer Antwort initialisieren */
1052 b9728ba2 2001-12-29 alex if( pipe( s->pipe ) != 0 )
1054 4a111033 2001-12-29 alex free( s );
1055 4a111033 2001-12-29 alex Log( LOG_ALERT, "Resolver: Can't create output pipe: %s!", strerror( errno ));
1056 4a111033 2001-12-29 alex return NULL;
1059 bc140df8 2001-12-29 alex /* Sub-Prozess erzeugen */
1060 4a111033 2001-12-29 alex pid = fork( );
1061 4a111033 2001-12-29 alex if( pid > 0 )
1063 4a111033 2001-12-29 alex /* Haupt-Prozess */
1064 bc140df8 2001-12-29 alex Log( LOG_DEBUG, "Resolver for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid );
1065 b9728ba2 2001-12-29 alex FD_SET( s->pipe[0], &My_Resolvers );
1066 b9728ba2 2001-12-29 alex if( s->pipe[0] > My_Max_Fd ) My_Max_Fd = s->pipe[0];
1067 4a111033 2001-12-29 alex s->pid = pid;
1070 4a111033 2001-12-29 alex else if( pid == 0 )
1072 4a111033 2001-12-29 alex /* Sub-Prozess */
1073 4a111033 2001-12-29 alex Log_Init_Resolver( );
1074 03d971d9 2002-01-02 alex Do_ResolveAddr( Addr, s->pipe[1] );
1075 4a111033 2001-12-29 alex Log_Exit_Resolver( );
1076 4a111033 2001-12-29 alex exit( 0 );
1080 4a111033 2001-12-29 alex /* Fehler */
1081 4a111033 2001-12-29 alex free( s );
1082 79809118 2002-01-06 alex Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
1083 4a111033 2001-12-29 alex return NULL;
1085 03d971d9 2002-01-02 alex } /* ResolveAddr */
1088 03d971d9 2002-01-02 alex LOCAL RES_STAT *ResolveName( CHAR *Host )
1090 03d971d9 2002-01-02 alex /* Hostnamen (asyncron!) aufloesen. Bei Fehler, z.B. wenn der
1091 03d971d9 2002-01-02 alex * Child-Prozess nicht erzeugt werden kann, wird NULL geliefert.
1092 03d971d9 2002-01-02 alex * Der Host kann dann nicht aufgeloest werden. */
1094 03d971d9 2002-01-02 alex RES_STAT *s;
1097 03d971d9 2002-01-02 alex /* Speicher anfordern */
1098 03d971d9 2002-01-02 alex s = malloc( sizeof( RES_STAT ));
1101 79809118 2002-01-06 alex Log( LOG_EMERG, "Resolver: Can't allocate memory!" );
1102 03d971d9 2002-01-02 alex return NULL;
1105 03d971d9 2002-01-02 alex /* Pipe fuer Antwort initialisieren */
1106 03d971d9 2002-01-02 alex if( pipe( s->pipe ) != 0 )
1108 03d971d9 2002-01-02 alex free( s );
1109 03d971d9 2002-01-02 alex Log( LOG_ALERT, "Resolver: Can't create output pipe: %s!", strerror( errno ));
1110 03d971d9 2002-01-02 alex return NULL;
1113 03d971d9 2002-01-02 alex /* Sub-Prozess erzeugen */
1114 03d971d9 2002-01-02 alex pid = fork( );
1115 03d971d9 2002-01-02 alex if( pid > 0 )
1117 03d971d9 2002-01-02 alex /* Haupt-Prozess */
1118 03d971d9 2002-01-02 alex Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid );
1119 03d971d9 2002-01-02 alex FD_SET( s->pipe[0], &My_Resolvers );
1120 03d971d9 2002-01-02 alex if( s->pipe[0] > My_Max_Fd ) My_Max_Fd = s->pipe[0];
1121 03d971d9 2002-01-02 alex s->pid = pid;
1124 03d971d9 2002-01-02 alex else if( pid == 0 )
1126 03d971d9 2002-01-02 alex /* Sub-Prozess */
1127 03d971d9 2002-01-02 alex Log_Init_Resolver( );
1128 03d971d9 2002-01-02 alex Do_ResolveName( Host, s->pipe[1] );
1129 03d971d9 2002-01-02 alex Log_Exit_Resolver( );
1130 03d971d9 2002-01-02 alex exit( 0 );
1134 03d971d9 2002-01-02 alex /* Fehler */
1135 03d971d9 2002-01-02 alex free( s );
1136 79809118 2002-01-06 alex Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
1137 03d971d9 2002-01-02 alex return NULL;
1139 03d971d9 2002-01-02 alex } /* ResolveName */
1142 03d971d9 2002-01-02 alex LOCAL VOID Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd )
1144 03d971d9 2002-01-02 alex /* Resolver Sub-Prozess: IP aufloesen und Ergebnis in Pipe schreiben. */
1146 03d971d9 2002-01-02 alex CHAR hostname[HOST_LEN];
1147 03d971d9 2002-01-02 alex struct hostent *h;
1149 03d971d9 2002-01-02 alex Log_Resolver( LOG_DEBUG, "Now resolving %s ...", inet_ntoa( Addr->sin_addr ));
1151 03d971d9 2002-01-02 alex /* Namen aufloesen */
1152 03d971d9 2002-01-02 alex h = gethostbyaddr( (CHAR *)&Addr->sin_addr, sizeof( Addr->sin_addr ), AF_INET );
1153 03d971d9 2002-01-02 alex if( h ) strcpy( hostname, h->h_name );
1156 03d971d9 2002-01-02 alex Log_Resolver( LOG_WARNING, "Can't resolve address %s: code %s!", inet_ntoa( Addr->sin_addr ), Resolv_Error( h_errno ));
1157 03d971d9 2002-01-02 alex strcpy( hostname, inet_ntoa( Addr->sin_addr ));
1160 03d971d9 2002-01-02 alex /* Antwort an Parent schreiben */
1161 03d971d9 2002-01-02 alex if( write( w_fd, hostname, strlen( hostname ) + 1 ) != ( strlen( hostname ) + 1 ))
1163 79809118 2002-01-06 alex Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
1164 03d971d9 2002-01-02 alex close( w_fd );
1168 03d971d9 2002-01-02 alex Log_Resolver( LOG_DEBUG, "Ok, translated %s to \"%s\".", inet_ntoa( Addr->sin_addr ), hostname );
1169 03d971d9 2002-01-02 alex } /* Do_ResolveAddr */
1172 03d971d9 2002-01-02 alex LOCAL VOID Do_ResolveName( CHAR *Host, INT w_fd )
1174 03d971d9 2002-01-02 alex /* Resolver Sub-Prozess: Name aufloesen und Ergebnis in Pipe schreiben. */
1176 03d971d9 2002-01-02 alex CHAR ip[16];
1177 03d971d9 2002-01-02 alex struct hostent *h;
1178 03d971d9 2002-01-02 alex struct in_addr *addr;
1180 03d971d9 2002-01-02 alex Log_Resolver( LOG_DEBUG, "Now resolving \"%s\" ...", Host );
1182 03d971d9 2002-01-02 alex /* Namen aufloesen */
1183 03d971d9 2002-01-02 alex h = gethostbyname( Host );
1186 03d971d9 2002-01-02 alex addr = (struct in_addr *)h->h_addr;
1187 03d971d9 2002-01-02 alex strcpy( ip, inet_ntoa( *addr ));
1191 03d971d9 2002-01-02 alex Log_Resolver( LOG_WARNING, "Can't resolve \"%s\": %s!", Host, Resolv_Error( h_errno ));
1192 03d971d9 2002-01-02 alex strcpy( ip, "" );
1195 03d971d9 2002-01-02 alex /* Antwort an Parent schreiben */
1196 03d971d9 2002-01-02 alex if( write( w_fd, ip, strlen( ip ) + 1 ) != ( strlen( ip ) + 1 ))
1198 79809118 2002-01-06 alex Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
1199 03d971d9 2002-01-02 alex close( w_fd );
1203 03d971d9 2002-01-02 alex if( ip[0] ) Log_Resolver( LOG_DEBUG, "Ok, translated \"%s\" to %s.", Host, ip );
1204 03d971d9 2002-01-02 alex } /* Do_ResolveName */
1207 4a111033 2001-12-29 alex LOCAL VOID Read_Resolver_Result( INT r_fd )
1209 4a111033 2001-12-29 alex /* Ergebnis von Resolver Sub-Prozess aus Pipe lesen
1210 03d971d9 2002-01-02 alex * und entsprechende Connection aktualisieren */
1212 03d971d9 2002-01-02 alex CHAR result[HOST_LEN];
1213 4a111033 2001-12-29 alex CLIENT *c;
1214 03d971d9 2002-01-02 alex INT len, i;
1216 4a111033 2001-12-29 alex FD_CLR( r_fd, &My_Resolvers );
1218 4a111033 2001-12-29 alex /* Anfrage vom Parent lesen */
1219 03d971d9 2002-01-02 alex len = read( r_fd, result, HOST_LEN);
1220 03d971d9 2002-01-02 alex if( len < 0 )
1222 4a111033 2001-12-29 alex /* Fehler beim Lesen aus der Pipe */
1223 4a111033 2001-12-29 alex close( r_fd );
1224 79809118 2002-01-06 alex Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
1227 03d971d9 2002-01-02 alex result[len] = '\0';
1229 bc140df8 2001-12-29 alex /* zugehoerige Connection suchen */
1230 4a111033 2001-12-29 alex for( i = 0; i < MAX_CONNECTIONS; i++ )
1232 03d971d9 2002-01-02 alex if(( My_Connections[i].sock != NONE ) && ( My_Connections[i].res_stat ) && ( My_Connections[i].res_stat->pipe[0] == r_fd )) break;
1234 4a111033 2001-12-29 alex if( i >= MAX_CONNECTIONS )
1236 03d971d9 2002-01-02 alex /* Opsa! Keine passende Connection gefunden!? Vermutlich
1237 03d971d9 2002-01-02 alex * wurde sie schon wieder geschlossen. */
1238 4a111033 2001-12-29 alex close( r_fd );
1239 03d971d9 2002-01-02 alex Log( LOG_DEBUG, "Resolver: Got result for unknown connection!?" );
1243 4a111033 2001-12-29 alex /* Aufraeumen */
1244 b9728ba2 2001-12-29 alex close( My_Connections[i].res_stat->pipe[0] );
1245 b9728ba2 2001-12-29 alex close( My_Connections[i].res_stat->pipe[1] );
1246 4a111033 2001-12-29 alex free( My_Connections[i].res_stat );
1247 4a111033 2001-12-29 alex My_Connections[i].res_stat = NULL;
1249 03d971d9 2002-01-02 alex if( My_Connections[i].sock > NONE )
1251 03d971d9 2002-01-02 alex /* Eingehende Verbindung: Hostnamen setzen */
1252 03d971d9 2002-01-02 alex c = Client_GetFromConn( i );
1253 54e487d4 2002-01-03 alex assert( c != NULL );
1254 54e487d4 2002-01-03 alex strcpy( My_Connections[i].host, result );
1255 54e487d4 2002-01-03 alex Client_SetHostname( c, result );
1259 03d971d9 2002-01-02 alex /* Ausgehende Verbindung (=Server): IP setzen */
1260 03d971d9 2002-01-02 alex assert( My_Connections[i].our_server >= 0 );
1261 03d971d9 2002-01-02 alex strcpy( Conf_Server[My_Connections[i].our_server].ip, result );
1263 4a111033 2001-12-29 alex } /* Read_Resolver_Result */
1266 03d971d9 2002-01-02 alex LOCAL CHAR *Resolv_Error( INT H_Error )
1268 03d971d9 2002-01-02 alex /* Fehlerbeschreibung fuer H_Error liefern */
1270 03d971d9 2002-01-02 alex switch( H_Error )
1272 03d971d9 2002-01-02 alex case HOST_NOT_FOUND:
1273 03d971d9 2002-01-02 alex return "host not found";
1274 bcc0cdc3 2002-01-05 alex case NO_DATA:
1275 03d971d9 2002-01-02 alex return "name valid but no IP address defined";
1276 03d971d9 2002-01-02 alex case NO_RECOVERY:
1277 03d971d9 2002-01-02 alex return "name server error";
1278 03d971d9 2002-01-02 alex case TRY_AGAIN:
1279 03d971d9 2002-01-02 alex return "name server temporary not available";
1281 03d971d9 2002-01-02 alex return "unknown error";
1283 03d971d9 2002-01-02 alex } /* Resolv_Error */
1286 5fefe1a3 2001-12-12 alex /* -eof- */