refactor(network): codestyle and error handling
This commit is contained in:
parent
50e782e028
commit
75cc1bc318
|
@ -269,11 +269,11 @@ void waybar::modules::Network::getInterfaceAddress() {
|
||||||
int success = getifaddrs(&ifaddr);
|
int success = getifaddrs(&ifaddr);
|
||||||
if (success == 0) {
|
if (success == 0) {
|
||||||
ifa = ifaddr;
|
ifa = ifaddr;
|
||||||
while(ifa != NULL && ipaddr_.empty() && netmask_.empty()) {
|
while (ifa != NULL && ipaddr_.empty() && netmask_.empty()) {
|
||||||
if(ifa->ifa_addr->sa_family == family_) {
|
if (ifa->ifa_addr->sa_family == family_) {
|
||||||
if(strcmp(ifa->ifa_name, ifname_.c_str()) == 0){
|
if (strcmp(ifa->ifa_name, ifname_.c_str()) == 0) {
|
||||||
ipaddr_=inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr);
|
ipaddr_ = inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr);
|
||||||
netmask_=inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr);
|
netmask_ = inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr);
|
||||||
cidrRaw = ((struct sockaddr_in *)(ifa->ifa_netmask))->sin_addr.s_addr;
|
cidrRaw = ((struct sockaddr_in *)(ifa->ifa_netmask))->sin_addr.s_addr;
|
||||||
unsigned int cidr = 0;
|
unsigned int cidr = 0;
|
||||||
while (cidrRaw) {
|
while (cidrRaw) {
|
||||||
|
@ -285,8 +285,12 @@ void waybar::modules::Network::getInterfaceAddress() {
|
||||||
}
|
}
|
||||||
ifa = ifa->ifa_next;
|
ifa = ifa->ifa_next;
|
||||||
}
|
}
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
} else {
|
||||||
|
ipaddr_.clear();
|
||||||
|
netmask_.clear();
|
||||||
|
cidr_ = 0;
|
||||||
}
|
}
|
||||||
freeifaddrs(ifaddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int waybar::modules::Network::netlinkRequest(int fd, void *req,
|
int waybar::modules::Network::netlinkRequest(int fd, void *req,
|
||||||
|
|
Loading…
Reference in New Issue