memset(part, 0, sizeof(part));
struct ifaddrs *ifaddr, *addrp;
+ bool found = false;
getifaddrs(&ifaddr);
addrp = addrp->ifa_next) {
/* Check if the interface is down */
- if (strcmp(addrp->ifa_name, interface) == 0 &&
- (addrp->ifa_flags & IFF_RUNNING) == 0) {
+ if (strcmp(addrp->ifa_name, interface) != 0)
+ continue;
+ found = true;
+ if ((addrp->ifa_flags & IFF_RUNNING) == 0) {
freeifaddrs(ifaddr);
return NULL;
}
if (addrp == NULL) {
freeifaddrs(ifaddr);
- return "no IP";
+ return (found ? "no IP" : NULL);
}
int ret;