ConnectionStatus platform method for Linux.

This commit is contained in:
Lev Dragunov 2015-10-21 12:56:37 +03:00
parent f274104956
commit 6a962df079

View file

@ -6,9 +6,18 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
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)
@ -121,6 +130,22 @@ 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);
struct sockaddr_in addr;
if(socketFd < 0)
return EConnectionType::CONNECTION_NONE;
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, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
close(socketFd);
return EConnectionType::CONNECTION_NONE;
}
close(socketFd);
return EConnectionType::CONNECTION_WIFI;
}