diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp index f8b5b5622d..b9f497616a 100644 --- a/platform/platform_linux.cpp +++ b/platform/platform_linux.cpp @@ -1,14 +1,27 @@ #include "platform/platform.hpp" #include "base/logging.hpp" +#include "base/scope_guard.hpp" + #include "coding/file_reader.hpp" +#include "std/bind.hpp" + #include #include +#include #include #include +#include +#include + +namespace +{ +// Web service ip to check internet connection. Now it's a mail.ru ip. +char constexpr kSomeWorkingWebServer[] = "217.69.139.202"; +} // namespace /// @return directory where binary resides, including slash at the end static bool GetBinaryFolder(string & outPath) @@ -91,7 +104,7 @@ Platform::Platform() } string Platform::UniqueClientId() const -{ +{ string machineFile = "/var/lib/dbus/machine-id"; if (IsFileExistsByFullPath("/etc/machine-id")) machineFile = "/etc/machine-id"; @@ -104,7 +117,6 @@ string Platform::UniqueClientId() const } else return "n0dbus0n0lsb00000000000000000000"; - } void Platform::RunOnGuiThread(TFunctor const & fn) @@ -121,6 +133,19 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) Platform::EConnectionType Platform::ConnectionStatus() { - // @TODO Add implementation - return EConnectionType::CONNECTION_NONE; + int socketFd = socket(AF_INET, SOCK_STREAM, 0); + MY_SCOPE_GUARD(closeSocket, bind(&close, socketFd)); + if (socketFd < 0) + return EConnectionType::CONNECTION_NONE; + + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(80); + inet_pton(AF_INET, kSomeWorkingWebServer, &addr.sin_addr); + + if (connect(socketFd, reinterpret_cast(&addr), sizeof(addr)) < 0) + return EConnectionType::CONNECTION_NONE; + + return EConnectionType::CONNECTION_WIFI; }