set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
endif()
check_function_exists(inet_aton HAVE_INET_ATON)
+check_function_exists(inet_pton HAVE_INET_PTON)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
set(CMAKE_EXTRA_INCLUDE_FILES)
set(CMAKE_REQUIRED_LIBRARIES)
return;
}
- // - localhostOnly will mean "127.0.0.1 only", no IPv6
- bool use_ipv6 = !localhostOnly;
+ bool use_ipv6;
int af;
#ifdef AF_INET6
- if (use_ipv6)
- af = AF_INET6;
- else
- af = AF_INET;
+ use_ipv6 = true;
+ af = AF_INET6;
#else
use_ipv6 = false;
af = AF_INET;
memset(&addr6, 0, (sa_len = sizeof(addr6)));
addr6.sin6_family = af;
addr6.sin6_port = htons(port);
- sa = (struct sockaddr *)&addr6;
- } else {
+
+ if (localhostOnly)
+ addr6.sin6_addr = in6addr_loopback;
+ else if (listenaddr != NULL) {
+#ifdef HAVE_INET_PTON
+ if (inet_pton(AF_INET6, listenaddr, &addr6.sin6_addr) != 1)
+ use_ipv6 = false;
+#else
+ // Unable to parse without inet_pton
+ use_ipv6 = false;
+#endif
+ }
+
+ if (use_ipv6)
+ sa = (struct sockaddr *)&addr6;
+ }
+
+ if (!use_ipv6) {
memset(&addr, 0, (sa_len = sizeof(addr)));
addr.sin_family = af;
addr.sin_port = htons(port);
#define PACKAGE_VERSION "@VERSION@"
#cmakedefine HAVE_INET_ATON
+#cmakedefine HAVE_INET_PTON
#cmakedefine HAVE_GETADDRINFO
#cmakedefine HAVE_GNUTLS_SET_GLOBAL_ERRNO
#cmakedefine HAVE_GNUTLS_SET_ERRNO