From: Alexander A. Klimov Date: Thu, 21 Feb 2019 09:55:47 +0000 (+0100) Subject: ApiListener: use setsockopt(), not tcp::acceptor#set_option() X-Git-Tag: v2.11.0-rc1~174^2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=326bf6625578180dc5a21ebcceb2043fd538714b;p=icinga2 ApiListener: use setsockopt(), not tcp::acceptor#set_option() --- diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 4928c285c..f3057c289 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -22,7 +22,6 @@ #include "base/exception.hpp" #include #include -#include #include #include #include @@ -370,8 +369,20 @@ bool ApiListener::AddListener(const String& node, const String& service) for (;;) { try { acceptor->open(current->endpoint().protocol()); - acceptor->set_option(ip::v6_only(false)); - acceptor->set_option(tcp::acceptor::reuse_address(true)); + + { + auto fd (acceptor->native_handle()); + + const int optFalse = 0; + setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast(&optFalse), sizeof(optFalse)); + + const int optTrue = 1; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&optTrue), sizeof(optTrue)); +#ifndef _WIN32 + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast(&optTrue), sizeof(optTrue)); +#endif /* _WIN32 */ + } + acceptor->bind(current->endpoint()); break;