mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
network: detect if link is p2p and use local addr
without this we endup with peer's addr Signed-off-by: Paymon MARANDI <darwinskernel@gmail.com>
This commit is contained in:
parent
757f20fc04
commit
3da3732cc9
@ -62,6 +62,7 @@ class Network : public ALabel {
|
|||||||
bool want_link_dump_;
|
bool want_link_dump_;
|
||||||
bool want_addr_dump_;
|
bool want_addr_dump_;
|
||||||
bool dump_in_progress_;
|
bool dump_in_progress_;
|
||||||
|
bool is_p2p_;
|
||||||
|
|
||||||
unsigned long long bandwidth_down_total_;
|
unsigned long long bandwidth_down_total_;
|
||||||
unsigned long long bandwidth_up_total_;
|
unsigned long long bandwidth_up_total_;
|
||||||
|
@ -87,6 +87,7 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
|
|||||||
want_link_dump_(false),
|
want_link_dump_(false),
|
||||||
want_addr_dump_(false),
|
want_addr_dump_(false),
|
||||||
dump_in_progress_(false),
|
dump_in_progress_(false),
|
||||||
|
is_p2p_(false),
|
||||||
cidr_(0),
|
cidr_(0),
|
||||||
signal_strength_dbm_(0),
|
signal_strength_dbm_(0),
|
||||||
signal_strength_(0),
|
signal_strength_(0),
|
||||||
@ -456,6 +457,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
case IFLA_IFNAME:
|
case IFLA_IFNAME:
|
||||||
ifname = static_cast<const char *>(RTA_DATA(ifla));
|
ifname = static_cast<const char *>(RTA_DATA(ifla));
|
||||||
ifname_len = RTA_PAYLOAD(ifla) - 1; // minus \0
|
ifname_len = RTA_PAYLOAD(ifla) - 1; // minus \0
|
||||||
|
if (ifi->ifi_flags & IFF_POINTOPOINT && net->checkInterface(ifname))
|
||||||
|
net->is_p2p_ = true;
|
||||||
break;
|
break;
|
||||||
case IFLA_CARRIER: {
|
case IFLA_CARRIER: {
|
||||||
carrier = *(char *)RTA_DATA(ifla) == 1;
|
carrier = *(char *)RTA_DATA(ifla) == 1;
|
||||||
@ -494,6 +497,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
|
|
||||||
net->ifname_ = new_ifname;
|
net->ifname_ = new_ifname;
|
||||||
net->ifid_ = ifi->ifi_index;
|
net->ifid_ = ifi->ifi_index;
|
||||||
|
if (ifi->ifi_flags & IFF_POINTOPOINT)
|
||||||
|
net->is_p2p_ = true;
|
||||||
if (carrier.has_value()) {
|
if (carrier.has_value()) {
|
||||||
net->carrier_ = carrier.value();
|
net->carrier_ = carrier.value();
|
||||||
}
|
}
|
||||||
@ -537,7 +542,10 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
|
|
||||||
for (; RTA_OK(ifa_rta, attrlen); ifa_rta = RTA_NEXT(ifa_rta, attrlen)) {
|
for (; RTA_OK(ifa_rta, attrlen); ifa_rta = RTA_NEXT(ifa_rta, attrlen)) {
|
||||||
switch (ifa_rta->rta_type) {
|
switch (ifa_rta->rta_type) {
|
||||||
case IFA_ADDRESS: {
|
case IFA_ADDRESS:
|
||||||
|
if (net->is_p2p_)
|
||||||
|
continue;
|
||||||
|
case IFA_LOCAL:
|
||||||
char ipaddr[INET6_ADDRSTRLEN];
|
char ipaddr[INET6_ADDRSTRLEN];
|
||||||
if (!is_del_event) {
|
if (!is_del_event) {
|
||||||
net->ipaddr_ = inet_ntop(ifa->ifa_family, RTA_DATA(ifa_rta), ipaddr, sizeof(ipaddr));
|
net->ipaddr_ = inet_ntop(ifa->ifa_family, RTA_DATA(ifa_rta), ipaddr, sizeof(ipaddr));
|
||||||
@ -572,7 +580,6 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user