From c330aa6250871c4d5c3ecf2f20e6dfa30be08ab0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 4 May 2023 16:24:08 +0100 Subject: Check whether IPPROTO_SCTP works before trying to implicitly multistack. Fixes bind warnings on platforms which have IPPROTO_SCTP defined but don't actually have support at runtime. --- src/socket.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/socket.cpp') diff --git a/src/socket.cpp b/src/socket.cpp index 2dc94b85f..12f9fabda 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -33,6 +33,23 @@ #include "inspircd.h" +namespace +{ + // Checks whether the system can create SCTP sockets. + bool CanCreateSCTPSocket() + { +#ifdef IPPROTO_SCTP + int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + if (fd >= 0) + { + SocketEngine::Close(fd); + return true; + } +#endif + return false; + } +} + bool InspIRCd::BindPort(const std::shared_ptr& tag, const irc::sockets::sockaddrs& sa, std::vector& old_ports, int protocol) { for (std::vector::iterator n = old_ports.begin(); n != old_ports.end(); ++n) @@ -128,7 +145,8 @@ size_t InspIRCd::BindPorts(FailedPortList& failed_ports) { protocols.push_back(0); // IPPROTO_TCP #ifdef IPPROTO_SCTP - protocols.push_back(IPPROTO_SCTP); + if (CanCreateSCTPSocket()) + protocols.push_back(IPPROTO_SCTP); #endif } else if (stdalgo::string::equalsci(protocol, "sctp")) -- cgit v1.3.1-10-gc9f91