slapd \- Stand-alone LDAP Daemon
.SH SYNOPSIS
.B LIBEXECDIR/slapd [\-d debug\-level]
-.B [\-f slapd\-config\-file] [\-p port\-number]
+.B [\-f slapd\-config\-file] [\-a address] [\-p port\-number]
.B [\-s syslog\-level] [\-l syslog\-local\-user] [\-i]
.B
.SH DESCRIPTION
Specifies the slapd configuration file. The default is
.BR ETCDIR/slapd.conf .
.TP
+.BI \-a " address"
+.B slapd
+will listen on all addresses (INADDR_ANY) unless this option
+is given to override the default. The address is expected in
+Internet standard '.' format.
+.TP
.BI \-p " port\-number"
.B slapd
will listen on the default LDAP port (389) unless this option is given
-to override the default.
+to override the default. A numeric port number is expected.
.TP
.B \-i
This option tells
void *
slapd_daemon(
- void *port
+ void *ptr
)
{
+ struct sockaddr_in *addr = ptr;
int i;
int tcps, ns;
- struct sockaddr_in addr;
fd_set readfds;
fd_set writefds;
FILE *fp;
"unknown", 0 );
}
- (void) memset( (void *) &addr, '\0', sizeof(addr) );
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = INADDR_ANY;
- addr.sin_port = htons( (int)port );
- if ( bind( tcps, (struct sockaddr *) &addr, sizeof(addr) ) == -1 ) {
+ if ( bind( tcps, (struct sockaddr *) addr, sizeof(*addr) ) == -1 ) {
Debug( LDAP_DEBUG_ANY, "bind() failed errno %d (%s)\n",
errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
"unknown", 0 );
int i;
int inetd = 0;
int rc = 0;
- int port;
+ struct sockaddr_in bind_addr;
int udp;
#ifdef LOG_LOCAL4
int syslogUser = DEFAULT_SYSLOG_USER;
int serverMode = SLAP_SERVER_MODE;
configfile = SLAPD_DEFAULT_CONFIGFILE;
- port = LDAP_PORT;
+
+ (void) memset( (void*) &bind_addr, '\0', sizeof(bind_addr));
+ bind_addr.sin_family = AF_INET;
+ bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ bind_addr.sin_port = htons(LDAP_PORT);
+
g_argc = argc;
g_argv = argv;
#ifdef SLAPD_BDB2
- while ( (i = getopt( argc, argv, "d:f:ip:s:ut" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "d:f:ia:p:s:ut" )) != EOF ) {
#else
- while ( (i = getopt( argc, argv, "d:f:ip:s:u" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "d:f:ia:p:s:u" )) != EOF ) {
#endif
switch ( i ) {
+ case 'a': /* bind address */
+ if(!inet_aton(optarg, &bind_addr.sin_addr)) {
+ fprintf(stderr, "invalid address (%s) for -a option", optarg);
+ }
+ break;
+
#ifdef LDAP_DEBUG
case 'd': /* turn on debugging */
if ( optarg[0] == '?' ) {
inetd = 1;
break;
- case 'p': /* port on which to listen */
- port = atoi( optarg );
- break;
+ case 'p': { /* port on which to listen */
+ int port = atoi( optarg );
+ if(! port ) {
+ fprintf(stderr, "-p %s must be numeric\n", optarg);
+ } else {
+ bind_addr.sin_port = htons(port);
+ }
+ } break;
case 's': /* set syslog level */
ldap_syslog = atoi( optarg );
break;
#ifdef LOG_LOCAL4
-
case 'l': /* set syslog local user */
syslogUser = cnvt_str2int( optarg, syslog_types,
DEFAULT_SYSLOG_USER );
break;
-
#endif
case 'u': /* do udp */
time( &starttime );
status = ldap_pvt_thread_create( &listener_tid, 0,
- slapd_daemon, (void *) port );
+ slapd_daemon, &bind_addr );
if ( status != 0 )
{
Debug( LDAP_DEBUG_ANY,