From 27fdd04153e886a882fe773c7f1bc1503ae0c132 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 15 Jun 2002 22:01:39 +0000 Subject: [PATCH] Add -4/-6 flags to slapd to force use of IPv4 or IPv6 --- doc/man/man8/slapd.8 | 7 +++++++ servers/slapd/daemon.c | 4 +++- servers/slapd/main.c | 14 ++++++++++++++ servers/slapd/slap.h | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/man/man8/slapd.8 b/doc/man/man8/slapd.8 index afb12e712f..f30dcc0a9f 100644 --- a/doc/man/man8/slapd.8 +++ b/doc/man/man8/slapd.8 @@ -6,6 +6,7 @@ slapd \- Stand-alone LDAP Daemon .SH SYNOPSIS .B LIBEXECDIR/slapd +.B [\-[4|6]] .B [\-d debug\-level] .B [\-f slapd\-config\-file] .B [\-h URLs] @@ -57,6 +58,12 @@ See the "OpenLDAP Administrator's Guide" for more details on .BR slapd . .SH OPTIONS .TP +.B \-4 +Listen on IPv4 addresses only. +.TP +.B \-6 +Listen on IPv6 addresses only. +.TP .BI \-d " debug\-level" Turn on debugging as defined by .I debug\-level. diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 80de649bea..c34077e224 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -33,6 +33,8 @@ int deny_severity = LOG_NOTICE; #define LDAPI_MOD_URLEXT "x-mod" #endif /* LDAP_PF_LOCAL */ +int slap_inet4or6 = AF_UNSPEC; + /* globals */ time_t starttime; ber_socket_t dtblsize; @@ -414,7 +416,7 @@ static int slap_get_listener_addresses( memset( &hints, '\0', sizeof(hints) ); hints.ai_flags = AI_PASSIVE; hints.ai_socktype = SOCK_STREAM; - hints.ai_family = AF_UNSPEC; + hints.ai_family = slap_inet4or6; snprintf(serv, sizeof serv, "%d", port); if ( (err = getaddrinfo(host, serv, &hints, &res)) ) { diff --git a/servers/slapd/main.c b/servers/slapd/main.c index b48f222450..cea889cf7a 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -96,6 +96,8 @@ usage( char *name ) fprintf( stderr, "usage: %s options\n", name ); fprintf( stderr, + "\t-4\t\tIPv4 only\n" + "\t-6\t\tIPv6 only\n" "\t-d level\tDebug level" "\n" "\t-f filename\tConfiguration file\n" #if defined(HAVE_SETUID) && defined(HAVE_SETGID) @@ -216,6 +218,9 @@ int main( int argc, char **argv ) while ( (i = getopt( argc, argv, "d:f:h:s:n:t" +#if LDAP_PF_INET6 + "46" +#endif #ifdef HAVE_CHROOT "r:" #endif @@ -227,6 +232,15 @@ int main( int argc, char **argv ) #endif )) != EOF ) { switch ( i ) { +#ifdef LDAP_PF_INET6 + case '4': + slap_inet4or6 = AF_INET; + break; + case '6': + slap_inet4or6 = AF_INET6; + break; +#endif + case 'h': /* listen URLs */ if ( urls != NULL ) free( urls ); urls = ch_strdup( optarg ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index b4c0d795dd..b3b129ba10 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -250,6 +250,10 @@ typedef union slap_sockaddr { #endif } Sockaddr; +#ifdef LDAP_PF_INET6 +extern int slap_inet4or6; +#endif + typedef struct slap_oid_macro { struct berval som_oid; char **som_names; -- 2.39.5