+static bool Handle_Write PARAMS(( CONN_ID Idx ));
+static bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, size_t Len ));
+static int New_Connection PARAMS(( int Sock ));
+static CONN_ID Socket2Index PARAMS(( int Sock ));
+static void Read_Request PARAMS(( CONN_ID Idx ));
+static void Handle_Buffer PARAMS(( CONN_ID Idx ));
+static void Check_Connections PARAMS(( void ));
+static void Check_Servers PARAMS(( void ));
+static void Init_Conn_Struct PARAMS(( CONN_ID Idx ));
+static bool Init_Socket PARAMS(( int Sock ));
+static void New_Server PARAMS(( int Server, ng_ipaddr_t *dest ));
+static void Simple_Message PARAMS(( int Sock, const char *Msg ));
+static int NewListener PARAMS(( const char *listen_addr, UINT16 Port ));
+
+static array My_Listeners;
+static array My_ConnArray;
+static size_t NumConnections;
+
+#ifdef TCPWRAP
+int allow_severity = LOG_INFO;
+int deny_severity = LOG_ERR;
+#endif
+
+static void server_login PARAMS((CONN_ID idx));
+
+#ifdef SSL_SUPPORT
+extern struct SSLOptions Conf_SSLOptions;
+static void cb_connserver_login_ssl PARAMS((int sock, short what));
+static void cb_clientserver_ssl PARAMS((int sock, short what));
+#endif
+static void cb_Read_Resolver_Result PARAMS(( int sock, UNUSED short what));
+static void cb_Connect_to_Server PARAMS(( int sock, UNUSED short what));
+static void cb_clientserver PARAMS((int sock, short what));
+
+static void
+cb_listen(int sock, short irrelevant)
+{
+ (void) irrelevant;
+ if (New_Connection( sock ) >= 0)
+ NumConnections++;
+ LogDebug("Total number of connections now %ld.", NumConnections);
+}
+
+
+#ifdef SSL_SUPPORT
+static void
+cb_listen_ssl(int sock, short irrelevant)
+{
+ int fd;
+ (void) irrelevant;
+ fd = New_Connection(sock);
+ if (fd < 0)
+ return;
+
+ NumConnections++;
+ LogDebug("Total number of connections now %ld.", NumConnections);
+ io_event_setcb(My_Connections[fd].sock, cb_clientserver_ssl);
+}
+#endif
+
+
+static void
+cb_connserver(int sock, UNUSED short what)