]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add irc::sockets::isunix for checking if a file is a UNIX socket.
authorPeter Powell <petpow@saberuk.com>
Wed, 29 May 2019 11:48:05 +0000 (12:48 +0100)
committerPeter Powell <petpow@saberuk.com>
Wed, 29 May 2019 16:50:49 +0000 (17:50 +0100)
include/socket.h
src/modules/m_spanningtree/main.cpp
src/socket.cpp

index e527bc7f54aa89c86b53253e6a38f4056f80882a..6ecb230206d07ef4df369ff72777e84a2431613f 100644 (file)
@@ -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);
        }
 }
 
index 44271473c827621210f38535b10a616b5ab3c954..55fe992b67d1b3b3a5ef66f0de9800af0717dde6 100644 (file)
@@ -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);
index abccd04084c3d58a0908898c27805bef9f337296..2daa6a8212dd72f108ff192b3deae36159d06348 100644 (file)
@@ -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;