2016-05-31 03:58:58 +00:00
|
|
|
#pragma once
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <iwlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
|
|
|
|
#include "exception.hpp"
|
|
|
|
#include "services/command.hpp"
|
|
|
|
|
|
|
|
namespace net
|
|
|
|
{
|
|
|
|
bool is_wireless_interface(const std::string& ifname);
|
|
|
|
|
|
|
|
// Network
|
2016-05-31 03:58:58 +00:00
|
|
|
|
2016-05-19 14:41:06 +00:00
|
|
|
class NetworkException : public Exception
|
|
|
|
{
|
|
|
|
public:
|
2016-05-31 03:58:58 +00:00
|
|
|
explicit NetworkException(const std::string& msg)
|
2016-05-19 14:41:06 +00:00
|
|
|
: Exception("[Network] "+ msg){}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Network
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::unique_ptr<Command> ping;
|
|
|
|
std::string interface;
|
|
|
|
struct ifreq data;
|
|
|
|
int fd;
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
bool test_interface();
|
|
|
|
bool test_connection();
|
2016-05-19 14:41:06 +00:00
|
|
|
|
|
|
|
public:
|
2016-05-31 03:58:58 +00:00
|
|
|
explicit Network(const std::string& interface);
|
2016-05-19 14:41:06 +00:00
|
|
|
~Network();
|
|
|
|
|
|
|
|
virtual bool connected();
|
|
|
|
virtual bool test();
|
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
std::string get_ip();
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// WiredNetwork
|
2016-05-31 03:58:58 +00:00
|
|
|
|
2016-05-19 14:41:06 +00:00
|
|
|
class WiredNetworkException : public NetworkException {
|
|
|
|
using NetworkException::NetworkException;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WiredNetwork : public Network
|
|
|
|
{
|
|
|
|
int linkspeed = 0;
|
|
|
|
|
|
|
|
public:
|
2016-05-31 03:58:58 +00:00
|
|
|
explicit WiredNetwork(const std::string& interface);
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-05-31 09:49:33 +00:00
|
|
|
std::string get_link_speed();
|
2016-05-19 14:41:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// WirelessNetwork
|
2016-05-31 03:58:58 +00:00
|
|
|
|
2016-05-19 14:41:06 +00:00
|
|
|
class WirelessNetworkException : public NetworkException {
|
|
|
|
using NetworkException::NetworkException;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WirelessNetwork : public Network
|
|
|
|
{
|
|
|
|
struct iwreq iw;
|
|
|
|
|
|
|
|
public:
|
2016-05-31 03:58:58 +00:00
|
|
|
explicit WirelessNetwork(const std::string& interface);
|
2016-05-19 14:41:06 +00:00
|
|
|
|
2016-05-31 03:58:58 +00:00
|
|
|
std::string get_essid();
|
|
|
|
float get_signal_dbm();
|
2016-05-19 14:41:06 +00:00
|
|
|
float get_signal_quality();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|