refactor(network): don't clear ipaddr
parent
2a9fa1a4b9
commit
c0a39f34cd
|
@ -448,15 +448,13 @@ out:
|
||||||
void waybar::modules::Network::getInterfaceAddress() {
|
void waybar::modules::Network::getInterfaceAddress() {
|
||||||
unsigned int cidrRaw;
|
unsigned int cidrRaw;
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
ipaddr_.clear();
|
|
||||||
netmask_.clear();
|
|
||||||
cidr_ = 0;
|
cidr_ = 0;
|
||||||
int success = getifaddrs(&ifaddr);
|
int success = getifaddrs(&ifaddr);
|
||||||
if (success != 0) {
|
if (success != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ifa = ifaddr;
|
ifa = ifaddr;
|
||||||
while (ifa != nullptr && ipaddr_.empty() && netmask_.empty()) {
|
while (ifa != nullptr) {
|
||||||
if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == family_ &&
|
if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == family_ &&
|
||||||
ifa->ifa_name == ifname_) {
|
ifa->ifa_name == ifname_) {
|
||||||
char ipaddr[INET6_ADDRSTRLEN];
|
char ipaddr[INET6_ADDRSTRLEN];
|
||||||
|
@ -475,6 +473,7 @@ void waybar::modules::Network::getInterfaceAddress() {
|
||||||
cidrRaw >>= 1;
|
cidrRaw >>= 1;
|
||||||
}
|
}
|
||||||
cidr_ = cidr;
|
cidr_ = cidr;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ifa = ifa->ifa_next;
|
ifa = ifa->ifa_next;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue