* @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);
}
}
}
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.
}
}
else
-#endif
{
// If this fails then the IP sa will be AF_UNSPEC.
irc::sockets::aptosa(x->IPAddr, x->Port, 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;