summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2019-05-29 12:48:05 +0100
committerPeter Powell <petpow@saberuk.com>2019-05-29 17:50:49 +0100
commit33932b95e4b886aec8ac1bf3e3e1665826bcd0ea (patch)
tree99f7a15ae6c73753c2a330aa1e54128de3cf99a1
parentde7011e54ad88656e01c92a88dd053a94b5acc6b (diff)
Add irc::sockets::isunix for checking if a file is a UNIX socket.
-rw-r--r--include/socket.h6
-rw-r--r--src/modules/m_spanningtree/main.cpp5
-rw-r--r--src/socket.cpp11
3 files changed, 18 insertions, 4 deletions
diff --git a/include/socket.h b/include/socket.h
index e527bc7f5..6ecb23020 100644
--- 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
index 44271473c..55fe992b6 100644
--- 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
index abccd0408..2daa6a821 100644
--- 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;