+#else
+ l.sl_is_tls = lud->lud_ldaps;
+
+ if(! lud->lud_port ) {
+ lud->lud_port = lud->lud_ldaps ? tls_port : port;
+ }
+#endif
+
+ port = lud->lud_port;
+
+ (void) memset( (void*) &l.sl_addr, '\0', sizeof(l.sl_addr) );
+
+ l.sl_addr.sin_family = AF_INET;
+ l.sl_addr.sin_port = htons( (unsigned short) lud->lud_port );
+
+ if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
+ || strcmp(lud->lud_host, "*") == 0 )
+ {
+ l.sl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ } else {
+ /* host or address was specified */
+ if( !inet_aton( lud->lud_host, &l.sl_addr.sin_addr ) ) {
+ struct hostent *he = gethostbyname( lud->lud_host );
+ if( he == NULL ) {
+ Debug( LDAP_DEBUG_ANY, "invalid host (%s) in URL: %s",
+ lud->lud_host, url, 0);
+ ldap_free_urldesc( lud );
+ return NULL;
+ }
+
+ memcpy( &l.sl_addr.sin_addr, he->h_addr,
+ sizeof( l.sl_addr.sin_addr ) );
+ }
+ }
+
+ ldap_free_urldesc( lud );
+
+
+ if ( (l.sl_sd = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID ) {
+#ifndef HAVE_WINSOCK
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: socket() failed errno %d (%s)\n", err,
+ err > -1 && err < sys_nerr ? sys_errlist[err] :
+ "unknown", 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: socket() failed errno %d (%s)\n",
+ WSAGetLastError(),
+ WSAGetLastErrorString(), 0 );
+#endif
+ return NULL;
+ }
+
+#ifndef HAVE_WINSOCK
+ if ( l.sl_sd >= dtblsize ) {
+ Debug( LDAP_DEBUG_ANY,
+ "daemon: listener descriptor %ld is too great %ld\n",
+ (long) l.sl_sd, (long) dtblsize, 0 );
+ tcp_close( l.sl_sd );
+ return NULL;
+ }
+#endif
+
+#ifdef SO_REUSEADDR
+ tmp = 1;
+ if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &tmp, sizeof(tmp) ) == -1 )
+ {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ }
+#endif
+#ifdef SO_KEEPALIVE
+ tmp = 1;
+ if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE,
+ (char *) &tmp, sizeof(tmp) ) == -1 )
+ {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "slapd(%ld): setsockopt(SO_KEEPALIVE) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ }
+#endif
+#ifdef TCP_NODELAY
+ tmp = 1;
+ if ( setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&tmp, sizeof(tmp) ) )
+ {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY,
+ "slapd(%ld): setsockopt(TCP_NODELAY) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ }
+#endif
+
+ if ( bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ) == -1 ) {
+ int err = errno;
+ Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno %d (%s)\n",
+ (long) l.sl_sd, err,
+ err > -1 && err < sys_nerr
+ ? sys_errlist[err] : "unknown" );
+ tcp_close( l.sl_sd );
+ return NULL;
+ }
+
+ l.sl_url = ch_strdup( url );
+
+ 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 )