inspircd

A modular C++ IRC daemon (ircd). https://www.inspircd.org/
Log | Files | Refs | README

commit 33932b95e4b886aec8ac1bf3e3e1665826bcd0ea
parent de7011e54ad88656e01c92a88dd053a94b5acc6b
Author: Peter Powell <petpow@saberuk.com>
Date:   Wed, 29 May 2019 12:48:05 +0100

Add irc::sockets::isunix for checking if a file is a UNIX socket.

Diffstat:
Minclude/socket.h | 6++++++
Msrc/modules/m_spanningtree/main.cpp | 5+----
Msrc/socket.cpp | 11+++++++++++
3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/socket.h b/include/socket.h @@ -127,6 +127,12 @@ namespace irc * @return True if the conversion was successful; otherwise, false. */ CoreExport bool untosa(const std::string& path, irc::sockets::sockaddrs& sa); + + /** Determines whether the specified file is a UNIX socket. + * @param file The path to the file to check. + * @return True if the file is a UNIX socket; otherwise, false. + */ + CoreExport bool isunix(const std::string& file); } } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp @@ -191,11 +191,9 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) } irc::sockets::sockaddrs sa; -#ifndef _WIN32 if (x->IPAddr.find('/') != std::string::npos) { - struct stat sb; - if (stat(x->IPAddr.c_str(), &sb) == -1 || !S_ISSOCK(sb.st_mode) || !irc::sockets::untosa(x->IPAddr, sa)) + if (!irc::sockets::isunix(x->IPAddr) || !irc::sockets::untosa(x->IPAddr, sa)) { // We don't use the family() != AF_UNSPEC check below for UNIX sockets as // that results in a DNS lookup. @@ -205,7 +203,6 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) } } else -#endif { // If this fails then the IP sa will be AF_UNSPEC. irc::sockets::aptosa(x->IPAddr, x->Port, sa); diff --git a/src/socket.cpp b/src/socket.cpp @@ -189,6 +189,17 @@ bool irc::sockets::untosa(const std::string& path, irc::sockets::sockaddrs& sa) return true; } +bool irc::sockets::isunix(const std::string& file) +{ +#ifndef _WIN32 + struct stat sb; + if (stat(file.c_str(), &sb) == 0 && S_ISSOCK(sb.st_mode)) + return true; +#endif + return false; +} + + int irc::sockets::sockaddrs::family() const { return sa.sa_family;