--- src/inet.c.inet-v6only 2006-12-18 11:33:49.000000000 -0700 +++ src/inet.c 2007-09-06 15:30:03.000000000 -0600 @@ -49,6 +49,8 @@ static int inet_errno = 0; /* Holds err */ static int inet_family = 0; +static const char *trace_channel = "inet"; + /* Called by others after running a number of pr_inet_* functions in order * to free up memory. */ @@ -298,13 +300,9 @@ static conn_t *inet_initialize_connectio #if defined(PR_USE_IPV6) && defined(IPV6_V6ONLY) if (pr_netaddr_use_ipv6() && addr_family == AF_INET6) { - int on = 0; - -# ifdef SOL_IP - int level = SOL_IP; -# else int level = ipv6_proto; -# endif /* SOL_IP */ + int off; + socklen_t len = sizeof(off); /* If creating a wildcard socket IPv6 socket, make sure that it * will accept IPv4 connections as well. This is the default on @@ -315,9 +313,20 @@ static conn_t *inet_initialize_connectio * SocketOptions directive. */ - if (setsockopt(fd, level, IPV6_V6ONLY, (void *) &on, sizeof(on)) < 0) - pr_log_pri(PR_LOG_NOTICE, "error setting IPV6_V6ONLY: %s", - strerror(errno)); + if (getsockopt(fd, level, IPV6_V6ONLY, (void *) &off, &len) >= 0) { + if (off != 0) { + off = 0; + + pr_trace_msg(trace_channel, 5, + "disabling IPV6_V6ONLY on server socket %d", fd); + + if (setsockopt(fd, level, IPV6_V6ONLY, (void *) &off, + len) < 0) { + pr_log_pri(PR_LOG_NOTICE, "error setting IPV6_V6ONLY: %s", + strerror(errno)); + } + } + } } #endif /* PR_USE_IPV6 and IPV6_V6ONLY */