2018-08-09 14:38:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-13 20:31:26 +00:00
|
|
|
#include <arpa/inet.h>
|
2019-04-18 15:52:00 +00:00
|
|
|
#include <fmt/format.h>
|
2018-11-13 20:31:26 +00:00
|
|
|
#include <ifaddrs.h>
|
2018-08-09 14:38:24 +00:00
|
|
|
#include <linux/nl80211.h>
|
2019-04-18 15:52:00 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netlink/genl/ctrl.h>
|
|
|
|
#include <netlink/genl/genl.h>
|
|
|
|
#include <netlink/netlink.h>
|
2018-12-26 10:13:36 +00:00
|
|
|
#include <sys/epoll.h>
|
2018-08-18 09:43:48 +00:00
|
|
|
#include "ALabel.hpp"
|
2019-04-18 15:52:00 +00:00
|
|
|
#include "util/sleeper_thread.hpp"
|
2018-08-09 14:38:24 +00:00
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2018-08-18 09:43:48 +00:00
|
|
|
class Network : public ALabel {
|
2019-04-18 15:52:00 +00:00
|
|
|
public:
|
|
|
|
Network(const std::string&, const Json::Value&);
|
|
|
|
~Network();
|
|
|
|
auto update() -> void;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const uint8_t MAX_RETRY = 5;
|
|
|
|
static const uint8_t EPOLL_MAX = 200;
|
|
|
|
|
|
|
|
static int handleEvents(struct nl_msg*, void*);
|
|
|
|
static int handleScan(struct nl_msg*, void*);
|
|
|
|
|
|
|
|
void worker();
|
|
|
|
void disconnected();
|
|
|
|
void createInfoSocket();
|
|
|
|
void createEventSocket();
|
|
|
|
int getExternalInterface();
|
|
|
|
void getInterfaceAddress();
|
|
|
|
int netlinkRequest(void*, uint32_t, uint32_t groups = 0);
|
|
|
|
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
|
|
|
|
void parseEssid(struct nlattr**);
|
|
|
|
void parseSignal(struct nlattr**);
|
|
|
|
bool associatedOrJoined(struct nlattr**);
|
|
|
|
auto getInfo() -> void;
|
|
|
|
|
|
|
|
waybar::util::SleeperThread thread_;
|
|
|
|
waybar::util::SleeperThread thread_timer_;
|
|
|
|
int ifid_;
|
|
|
|
sa_family_t family_;
|
|
|
|
struct sockaddr_nl nladdr_ = {0};
|
|
|
|
struct nl_sock* sk_ = nullptr;
|
|
|
|
struct nl_sock* info_sock_ = nullptr;
|
|
|
|
int efd_;
|
|
|
|
int ev_fd_;
|
|
|
|
int nl80211_id_;
|
|
|
|
|
|
|
|
std::string essid_;
|
|
|
|
std::string ifname_;
|
|
|
|
std::string ipaddr_;
|
|
|
|
std::string netmask_;
|
|
|
|
int cidr_;
|
|
|
|
int32_t signal_strength_dbm_;
|
|
|
|
uint8_t signal_strength_;
|
2018-08-16 12:29:41 +00:00
|
|
|
};
|
2018-08-09 14:38:24 +00:00
|
|
|
|
2019-04-18 15:52:00 +00:00
|
|
|
} // namespace waybar::modules
|