waybar/include/modules/network.hpp

55 lines
1.3 KiB
C++
Raw Normal View History

2018-08-09 16:38:24 +02:00
#pragma once
#include <net/if.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
2018-08-09 16:38:24 +02:00
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <linux/nl80211.h>
#include <fmt/format.h>
#include "util/chrono.hpp"
#include "ALabel.hpp"
2018-08-09 16:38:24 +02:00
namespace waybar::modules {
class Network : public ALabel {
2018-08-16 14:29:41 +02:00
public:
2018-08-20 14:50:45 +02:00
Network(const Json::Value&);
2018-08-19 13:39:57 +02:00
~Network();
2018-08-16 14:29:41 +02:00
auto update() -> void;
private:
2018-09-10 11:16:57 +02:00
static int netlinkRequest(int, void*, uint32_t, uint32_t groups = 0);
static int netlinkResponse(int, void*, uint32_t, uint32_t groups = 0);
2018-08-16 14:29:41 +02:00
static int scanCb(struct nl_msg*, void*);
2018-11-16 10:02:12 +01:00
void worker();
2018-08-17 14:24:00 +02:00
void disconnected();
2018-08-24 15:32:06 +02:00
void initNL80211();
2018-08-17 14:24:00 +02:00
int getExternalInterface();
void getInterfaceAddress();
2018-08-16 14:29:41 +02:00
void parseEssid(struct nlattr**);
void parseSignal(struct nlattr**);
bool associatedOrJoined(struct nlattr**);
auto getInfo() -> void;
waybar::util::SleeperThread thread_;
2018-11-16 10:02:12 +01:00
waybar::util::SleeperThread thread_timer_;
2018-08-17 14:24:00 +02:00
int ifid_;
sa_family_t family_;
int sock_fd_;
2018-11-16 10:02:12 +01:00
struct sockaddr_nl nladdr_ = {0};
2018-08-24 15:32:06 +02:00
struct nl_sock* sk_ = nullptr;
int nl80211_id_;
2018-08-17 14:24:00 +02:00
2018-08-16 14:29:41 +02:00
std::string essid_;
2018-08-17 14:24:00 +02:00
std::string ifname_;
std::string ipaddr_;
std::string netmask_;
int cidr_;
2018-08-16 14:29:41 +02:00
int signal_strength_dbm_;
uint16_t signal_strength_;
};
2018-08-09 16:38:24 +02:00
}