refactor(network): don't clear ipaddr

This commit is contained in:
Alex 2019-05-25 18:02:36 +02:00
parent 2a9fa1a4b9
commit c0a39f34cd

View File

@ -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;
} }