+ l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65336") );
+ s = inet_ntoa( l.sl_addr.sin_addr );
+ sprintf( l.sl_name, "IP=%s:%d",
+ s != NULL ? s : "unknown" , port );
+
+ li = ch_malloc( sizeof( Listener ) );
+ *li = l;
+
+ Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
+ l.sl_url, 0, 0 );
+
+ return li;
+}
+
+static int sockinit(void);
+static int sockdestroy(void);
+
+int slapd_daemon_init(char *urls, int port, int tls_port )
+{
+ int i, rc;
+ char **u;
+
+#ifndef HAVE_TLS
+ assert( tls_port == 0 );
+#endif
+
+ Debug( LDAP_DEBUG_ARGS, "daemon_init: %s (%d/%d)\n",
+ urls ? urls : "<null>", port, tls_port );
+
+ if( rc = sockinit() ) {
+ return rc;
+ }
+
+#ifdef HAVE_SYSCONF
+ dtblsize = sysconf( _SC_OPEN_MAX );
+#elif HAVE_GETDTABLESIZE
+ dtblsize = getdtablesize();
+#else
+ dtblsize = FD_SETSIZE;
+#endif
+
+#ifdef FD_SETSIZE
+ if(dtblsize > FD_SETSIZE) {
+ dtblsize = FD_SETSIZE;
+ }
+#endif /* !FD_SETSIZE */
+
+ FD_ZERO( &slap_daemon.sd_readers );
+ FD_ZERO( &slap_daemon.sd_writers );
+
+ if( urls == NULL ) {
+ urls = "ldap:///";
+ }
+
+ u = str2charray( urls, " " );
+
+ if( u == NULL || u[0] == NULL ) {
+ Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
+ urls, 0, 0 );
+
+ return -1;
+ }
+
+ for( i=0; u[i] != NULL; i++ ) {
+ Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
+ u[i], 0, 0 );
+ }
+
+ if( i == 0 ) {
+ Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
+ urls, 0, 0 );
+ return -1;
+ }
+
+ Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n",
+ i, 0, 0 );
+
+ slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
+
+ for(i = 0; u[i] != NULL; i++ ) {
+ slap_listeners[i] = open_listener( u[i], port, tls_port );
+
+ if( slap_listeners[i] == NULL ) {
+ return -1;